/** * Get the URL to a path or locator resource. * * @param string $path * @param mixed $parameters * @param mixed $referenceType * @return string */ public function to($path = '', $parameters = [], $referenceType = UrlGenerator::ABSOLUTE_PATH) { if (0 === strpos($path, '@')) { return $this->route($path, $parameters, $referenceType); } try { if (filter_var($path, FILTER_VALIDATE_URL) !== false) { $path = $this->locator->findResource($path); } } catch (InvalidArgumentException $e) { return $path; } if ($this->isAbsolutePath($path)) { $path = str_replace('\\', '/', $path); $path = strpos($path, $base = $this->context->getScriptPath()) === 0 ? substr($path, strlen($base)) : $path; } if ($query = http_build_query($parameters, '', '&')) { $query = '?' . $query; } if ($referenceType !== UrlGenerator::BASE_PATH) { $path = $this->base($referenceType) . '/' . trim($path, '/'); } return $path . $query; }
/** * Finds and adds theme file resources. * * @param ResourceLocator $locator */ public function registerResources(ResourceLocator $locator) { $root = $this->getPath(); $addResources = function ($config, $prefix = '') use($root, $locator) { foreach ($config as $scheme => $resources) { if (strpos($scheme, '://') > 0 && ($segments = explode('://', $scheme, 2))) { list($scheme, $prefix) = $segments; } $resources = (array) $resources; array_walk($resources, function (&$resource) use($root) { $resource = "{$root}/{$resource}"; }); $locator->addPath($scheme, $prefix, $resources); } }; $addResources($this->getConfig('resources.export', []), $this->getName()); $addResources($this->getConfig('resources.override', []), $this->getName()); }
/** * {@inheritdoc} */ protected function getConfig($filename, $parameters) { return parent::getConfig($this->locator->findResource($filename), $parameters); }
/** * {@inheritdoc} */ protected function getTarget($uri) { return self::$locator->findResource($uri); }