get() public method

Returns the resource at the given path.
public get ( string $path ) : Puli\Repository\Api\Resource\PuliResource
$path string The path to the resource. Must start with "/". "." and ".." segments in the path are supported.
return Puli\Repository\Api\Resource\PuliResource The resource at this path.
示例#1
0
 /**
  * Handles the "tree" command.
  *
  * @param Args $args The console arguments.
  * @param IO   $io   The I/O.
  *
  * @return int The status code.
  */
 public function handle(Args $args, IO $io)
 {
     $path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
     $resource = $this->repo->get($path);
     $total = 0;
     $io->writeLine('<c1>' . $resource->getPath() . '</c1>');
     $this->printTree($io, $resource, $total);
     $io->writeLine('');
     $io->writeLine($total . ' resources');
     return 0;
 }
 /**
  * Warms up the cache.
  *
  * @param string $cacheDir The cache directory
  *
  * @throws RuntimeException If setEnvironment() wasn't called
  */
 public function warmUp($cacheDir)
 {
     $iterator = new ResourceFilterIterator(new RecursiveResourceIteratorIterator(new ResourceCollectionIterator($this->repo->get('/')->listChildren(), ResourceCollectionIterator::CURRENT_AS_PATH), RecursiveResourceIteratorIterator::SELF_FIRST), $this->suffix, ResourceFilterIterator::FILTER_BY_NAME | ResourceFilterIterator::MATCH_SUFFIX);
     foreach ($iterator as $path) {
         try {
             $this->twig->loadTemplate($path);
         } catch (Twig_Error $e) {
             // Problem during compilation, stop
         }
     }
 }
示例#3
0
 private function loadResourceFromRepo()
 {
     $path = VarUtils::resolve($this->path, $this->getVars(), $this->getValues());
     // Lazily load the resource. If the resource needs to be fetched from
     // the database, we only want to fetch it when really necessary.
     $resource = $this->repo->get($path);
     if (!$resource instanceof BodyResource) {
         throw new RuntimeException(sprintf('The loaded resource is not a BodyResource. Got: %s', is_object($resource) ? get_class($resource) : gettype($resource)));
     }
     $this->resource = $resource;
 }
示例#4
0
 /**
  * Handles the "ls" command.
  *
  * @param Args $args The console arguments.
  * @param IO   $io   The I/O.
  *
  * @return int The status code.
  */
 public function handle(Args $args, IO $io)
 {
     $path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
     $resource = $this->repo->get($path);
     if (!$resource->hasChildren()) {
         throw new RuntimeException(sprintf('The resource "%s" does not have children.', $resource->getPath()));
     }
     if ($args->isOptionSet('long')) {
         $this->listLong($io, $resource->listChildren());
     } else {
         $this->listShort($io, $resource->listChildren());
     }
     return 0;
 }
 /**
  * Loads the complete collection.
  */
 private function load()
 {
     foreach ($this->resources as $key => $resource) {
         if (!$resource instanceof Resource) {
             $this->resources[$key] = $this->repo->get($resource);
         }
     }
     $this->loaded = true;
 }
示例#6
0
 /**
  * @param $templatePath
  * @return null|string
  * @throws \Exception
  */
 private function getRealTemplatePath($templatePath)
 {
     if ($this->repo instanceof ResourceRepository) {
         if ($this->repo->contains($templatePath)) {
             return $this->repo->get($templatePath)->getFilesystemPath();
         }
     }
     if (file_exists($templatePath)) {
         return $templatePath;
     }
     throw new \Exception("Template path not found in repository or on filesystem: {$templatePath}, in PhpTemplate");
 }
 /**
  * Returns a full path for a given Puli path.
  *
  * @param mixed  $path        The Puli path to locate
  * @param string $currentPath The current path
  * @param bool   $first       Whether to return the first occurrence or
  *                            an array of file names
  *
  * @return string|array The full path to the file|An array of file paths
  *
  * @throws InvalidArgumentException When the path is not found
  */
 public function locate($path, $currentPath = null, $first = true)
 {
     // Accept actual file paths
     if (file_exists($path)) {
         return $path;
     }
     if (null !== $currentPath && file_exists($currentPath . '/' . $path)) {
         throw new RuntimeException(sprintf('You tried to load the file "%s" using a relative path. ' . 'This functionality is not supported due to a limitation in ' . 'Symfony, because then this file cannot be overridden anymore. ' . 'Please pass the absolute Puli path instead.', $path));
     }
     try {
         $resource = $this->repo->get($path);
         while ($resource instanceof LinkResource) {
             $resource = $this->repo->get($resource->getTargetPath());
         }
         if (!$resource instanceof FilesystemResource) {
             throw new InvalidArgumentException(sprintf('The file "%s" is not a local file.', $path));
         }
         return $first ? $resource->getFilesystemPath() : array($resource->getFilesystemPath());
     } catch (ResourceNotFoundException $e) {
         throw new InvalidArgumentException(sprintf('The file "%s" could not be found.', $path), 0, $e);
     }
 }
 /**
  * Normalizes an input in order to generate the name for an asset.
  *
  * An "input" in Assetic's terminology is a reference string to an asset,
  * such as "css/*.css", "/webmozart/puli/style.css",
  * "@AcmeDemoBundle/Resources/css/style.css" etc.
  *
  * The normalization logic is described in {@link generateAssetName()}.
  *
  * @param string      $input      The input string.
  * @param string|null $currentDir The Puli directory of the currently loaded
  *                                Twig template. This is `null` if the
  *                                template was not loaded through Puli.
  *
  * @return string The normalized input.
  *
  * @see generateAssetName()
  *
  * @internal This method is public so it can be used as callback. It should
  *           not be used by user code.
  */
 public function normalizeInputForAssetName($input, $currentDir)
 {
     if (!$this->mayBePuliInput($input)) {
         return $input;
     }
     // If $input is a Puli URI, return it unchanged
     if (false !== strpos($input, '://')) {
         return $input;
     }
     // The "root" option is not always set when generateAssetName() is
     // called, so we should depend on the global root only. If not, the
     // normalized paths differ for generateAssetName() and createAsset()
     // If $input is within $this->root, return the relative path from
     // $this->root
     if (Path::isBasePath($this->root, $input)) {
         return Path::makeRelative($input, $this->root);
     }
     // If $input is a glob, keep it as it is
     if (false !== strpos($input, '*')) {
         return $input;
     }
     // If $input is relative, check whether the absolute path based on
     // $this->root is a file and return the relative path in that case
     if (is_file(Path::makeAbsolute($input, $this->root))) {
         // If the path points to a file, return the relative path so that
         // the resulting generated names are independent of the root
         // directory
         return $input;
     }
     // If $input is an absolute or relative Puli path, return the corresponding
     // file system path if possible
     // Don't query the Puli repository for relative paths if the current
     // Puli directory is not set
     if (null !== $currentDir || Path::isAbsolute($input)) {
         try {
             $resource = $this->repo->get(Path::makeAbsolute($input, $currentDir));
             return $resource instanceof FilesystemResource ? Path::makeRelative($resource->getFilesystemPath(), $this->root) : $resource->getPath();
         } catch (ResourceNotFoundException $e) {
             // Continue
         }
     }
     // If we reach this point, then input may be:
     // * an absolute file path with variables: /dir/trans/messages.{locale}.tx
     //   that is not based on $this->root
     // * a relative file path with variables: trans/messages.{locale}.txt
     // * an absolute Puli path with variables: /webmozart/puli/trans/messages.{locale}.txt
     // * a relative Puli path with variables: ../trans/messages.{locale}.txt
     // We can't make any further decisions here, so return $input unchanged
     return $input;
 }
示例#9
0
文件: Engine.php 项目: phn-io/dal
 /**
  * @param string   $path  The path of the DAL to load.
  * @param string[] $stack The stack of paths that have been loaded since the current call.
  *
  * @throws \Exception
  *
  * @return AbstractDal
  */
 private function doLoad($path, array $stack)
 {
     if (!isset($this->layers[$path])) {
         if ($this->isDebug || !file_exists($this->getFilename($path))) {
             $file = $this->repository->get($path);
             if (!$file instanceof FileResource) {
                 throw new \Exception(sprintf('The path "%s" should reference a file.', $path));
             }
             $ast = $this->syntax->read($file->getBody(), ['path' => $path]);
             $compiler = new Compiler();
             $compiler->compile($ast['definition']);
             $this->filesystem->dumpFile($this->getMetaFilename($path), serialize($ast['metadata']));
             $this->filesystem->dumpFile($this->getFilename($path), $compiler->getSource());
         }
         $this->layers[$path] = $this->loadLayerAndCheck($path, $stack);
     }
     return $this->layers[$path];
 }
示例#10
0
文件: Kernel.php 项目: php-di/kernel
 private function loadModule(ContainerBuilder $builder, ResourceRepository $resources, $module)
 {
     // Load all config files in the config/ directory
     foreach ($resources->find('/' . $module . '/config/*.php') as $resource) {
         if ($resource instanceof FilesystemResource) {
             $builder->addDefinitions($resource->getFilesystemPath());
         }
     }
     // Load the environment-specific config if it exists
     $envConfig = '/' . $module . '/config/env/' . $this->environment . '.php';
     if ($resources->contains($envConfig)) {
         $resource = $resources->get($envConfig);
         if ($resource instanceof FilesystemResource) {
             $builder->addDefinitions($resource->getFilesystemPath());
         }
     }
 }