/** * Get the URL to a path. * * @param string $path * @param array $parameters * @param mixed $referenceType * @return string */ public function to($path, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { $basePath = strtr($this->request->getBasePath(), '\\', '/'); $realPath = realpath(dirname(__FILE__) . '/../../../../../../../../../../'); if ($query = substr(strstr($path, '?'), 1)) { parse_str($query, $params); $path = strstr($path, '?', true); $parameters = array_replace($parameters, $params); } if ($query = http_build_query($parameters)) { $query = '?' . $query; } if ($path and !$this->isAbsolutePath($path)) { $path = $this->locator->find($path) ?: $path; } $path = strtr($path, '\\', '/'); if ($basePath && strpos($path, $basePath) === 0) { $path = ltrim(substr($path, strlen($basePath)), '/'); } if ($realPath && strpos($path, $realPath) === 0) { $path = ltrim(substr($path, strlen($realPath)), '/'); } if ($path and preg_match('/^(?!\\/|[a-z]+:\\/\\/)/i', $path)) { $path = $this->base($referenceType) . '/' . $path; } return $path . $query; }
/** * Adds a Resource. * * @param mixed $resource * @param string $locale * @return self */ public function addResource($resource, $locale = null) { if ($locale === null) { $locale = $this->getLocale(); } if (is_string($resource)) { if ($path = $this->locator->find($resource)) { $resource = json_decode(file_get_contents($path), true); } else { $resource = array(); } } $this->resources[$locale] = isset($this->resources[$locale]) ? array_replace($this->resources[$locale], $resource) : $resource; return $this; }