3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace PortlandLabs\DomainMapper\Url; use Concrete\Core\Url\Components\Path; use Concrete\Core\Url\Resolver\PathUrlResolver; use Concrete\Core\Url\Resolver\UrlResolverInterface; use PortlandLabs\DomainMapper\Map\DomainMap; /** * Class Resolver * URL Resolver for handling domain mapped urls, this will intercept mapped paths and alter the outputted links to * remove the prefix and set the proper host. * * @package PortlandLabs\DomainMapper\Url */ class Resolver implements UrlResolverInterface { public function resolve(array $arguments, $resolved = null) { $args = $arguments; $path = array_shift($args); /** @var DomainMap $map */ $map = \Core::make('domain_mapper/config_map'); if ($path instanceof \Page) { $path = $path->getCollectionPath(); $arguments[0] = $path; } if (is_scalar($path) && $path) { $path = (string)$path; $resolved_url = $resolved; if (!$resolved) { /** @var PathUrlResolver $path_resolver */ $path_resolver = \URL::getResolver('concrete.path'); $resolved_url = $path_resolver->resolve($arguments); } $url = $resolved_url; if ($url) { if ($prefix = $map->getPath($url->getHost())) { $prefix_path = new Path($prefix); $real_path = $url->getPath(); if (substr(strtolower($real_path), 0, strlen($prefix_path)) === strtolower($prefix_path)) { $relative_path = $real_path->getRelativePath($prefix_path); $url = $url->setPath($relative_path); } else { $url = $url->setHost(\Config::get('concrete.seo.canonical_host')); } return $url; } if ($domain = $map->getDomain($url->getPath())) { $map_path = new Path(rtrim($map->getPath($domain), '/')); $url_path = new Path(rtrim($url->getPath(), '/')); foreach ($map_path->toArray() as $key => $path_node) { $url_path->offsetUnset($key); } $url = $url->setPath($url_path); $url = $url->setHost($domain); return $url; } } } return $resolved; } }

preferences:
43.04 ms | 402 KiB | 5 Q