contains() public method

Returns whether any resources match a query.
public contains ( string $query, string $language = 'glob' ) : boolean
$query string A resource query.
$language string The language of the query. All implementations must support the language "glob".
return boolean Returns `true` if any resources exist that match the query.
 /**
  * {@inheritdoc}
  */
 public function findByPath($resourcePath, $typeName = null)
 {
     if (!$this->repo->contains($resourcePath)) {
         throw ResourceNotFoundException::forPath($resourcePath);
     }
     if (null === $typeName) {
         return $this->findAllForPath($resourcePath);
     }
     return $this->findByPathAndType($resourcePath, $typeName);
 }
 /**
  * @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");
 }
 /**
  * {@inheritdoc}
  */
 protected function resolvePath($path, $checkPath = false)
 {
     // Empty path? WTF I don't want to deal with this.
     if ('' === $path) {
         return $path;
     }
     // Absolute paths are fine
     if ('/' === $path[0]) {
         return $path;
     }
     // Resolve relative paths
     $absolutePath = Path::makeAbsolute($path, $this->currentDir);
     // With other loaders enabled, it may happen that a path looks like
     // a relative path, but is none, for example
     // "AcmeBlogBundle::index.html.twig", which doesn't start with a forward
     // slash. For this reason, if $checkPath is true, we should only resolve
     // paths if they actually exist in the repository.
     if (!$checkPath || $this->repo->contains($absolutePath)) {
         return $absolutePath;
     }
     // Return the path unchanged if $checkPath and the path does not exist
     return $path;
 }
 private function parseRelativeInput($input, $currentDir, array $roots, array $vars, array $values)
 {
     // If the Puli resource relative to the current directory exists,
     // prefer to return that
     $inputWithoutVars = VarUtils::resolve($input, $vars, $values);
     if (null !== $currentDir && $this->repo->contains(Path::makeAbsolute($inputWithoutVars, $currentDir))) {
         $asset = $this->createPuliAsset(Path::makeAbsolute($input, $currentDir), $vars);
         $asset->setValues($values);
         return $asset;
     }
     // Otherwise check whether the relative path can be found in the roots
     foreach ($roots as $root) {
         if (is_file(Path::makeAbsolute($inputWithoutVars, $root))) {
             $absolute = Path::makeAbsolute($input, $root);
             $asset = $this->createFileAsset($absolute, $root, $input, $vars);
             $asset->setValues($values);
             return $asset;
         }
     }
     throw new RuntimeException(sprintf('The asset "%s" could not be found. Searched the Puli directory %s ' . 'and the file system directories %s.', $inputWithoutVars, $currentDir, implode(', ', $roots)));
 }
Example #5
0
 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());
         }
     }
 }