/** * Return the path with the basePath prefix * if it has been set. * * @param string $path * * @return string */ protected function resolvePath($path) { Assert::stringNotEmpty($path, 'The path must be a non-empty string. Got: %s'); Assert::startsWith($path, '/', 'The path %s is not absolute.'); if ($this->basePath) { $path = $this->basePath . $path; } $path = Path::canonicalize($path); return $path; }
/** * Splits a path into mount point and path. * * @param string $path The path to split. * * @return array An array with the mount point and the path. If no mount * point was found, both are `null`. */ private function splitPath($path) { Assert::stringNotEmpty($path, 'The path must be a non-empty string. Got: %s'); Assert::startsWith($path, '/', 'The path %s is not absolute.'); $path = Path::canonicalize($path); foreach ($this->repos as $mountPoint => $_) { if (Path::isBasePath($mountPoint, $path)) { // Special case "/": return the complete path if ('/' === $mountPoint) { return array($mountPoint, $path); } return array($mountPoint, substr($path, strlen($mountPoint))); } } return array(null, null); }
/** * Sanitize a given path and check its validity. * * @param string $path * * @return string */ protected function sanitizePath($path) { Assert::stringNotEmpty($path, 'The path must be a non-empty string. Got: %s'); Assert::startsWith($path, '/', 'The path %s is not absolute.'); return Path::canonicalize($path); }
private function getGlobIterator($query, $language) { $this->failUnlessGlob($language); Assert::stringNotEmpty($query, 'The glob must be a non-empty string. Got: %s'); Assert::startsWith($query, '/', 'The glob %s is not absolute.'); $query = Path::canonicalize($query); return new GlobIterator($this->baseDir . $query); }
/** * {@inheritdoc} */ public function add($path, $resource) { Assert::stringNotEmpty($path, 'The path must be a non-empty string. Got: %s'); Assert::startsWith($path, '/', 'The path %s is not absolute.'); $path = Path::canonicalize($path); if ($resource instanceof ResourceCollection) { $this->ensureDirectoryExists($path); foreach ($resource as $child) { $this->addResource($path . '/' . $child->getName(), $child); } // Keep the resources sorted by file name ksort($this->resources); return; } if ($resource instanceof Resource) { $this->ensureDirectoryExists(Path::getDirectory($path)); $this->addResource($path, $resource); ksort($this->resources); return; } throw new UnsupportedResourceException(sprintf('The passed resource must be a Resource or ResourceCollection. Got: %s', is_object($resource) ? get_class($resource) : gettype($resource))); }
private function getGlobIterator($query, $language) { if ('glob' !== $language) { throw UnsupportedLanguageException::forLanguage($language); } Assert::stringNotEmpty($query, 'The glob must be a non-empty string. Got: %s'); Assert::startsWith($query, '/', 'The glob %s is not absolute.'); $query = Path::canonicalize($query); return new GlobIterator($this->baseDir . $query); }