Returns the resources matching a query.
public find ( string $query, string $language = 'glob' ) : Puli\Repository\Api\ResourceCollection | ||
$query | string | A resource query. |
$language | string | The language of the query. All implementations must support the language "glob". |
return | Puli\Repository\Api\ResourceCollection | The resources matching the query. |
/** * Handles the "url" 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) { foreach ($args->getArgument('path') as $path) { if (!Glob::isDynamic($path)) { $this->printUrl($path, $io); continue; } foreach ($this->repo->find($path) as $resource) { $this->printUrl($resource->getPath(), $io); } } return 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); $resources = $this->repo->find($path); if (!count($resources)) { $io->errorLine("No resources found for path {$path}"); return 1; } foreach ($resources as $resource) { if ($resource instanceof BodyResource) { $io->writeLine($resource->getBody()); } } return 0; }
/** * Returns the bound resources. * * @return ResourceCollection The bound resources. */ public function getResources() { if (null === $this->repo) { throw new NotInitializedException('The repository of the resource binding must be set before accessing resources.'); } return $this->repo->find($this->query, $this->language); }
/** * Finds the resources for a given path pattern. * * @param string $query The resource query. * @param string $language The language of the query. * * @return string[] An array of short resource class names indexed by * the resource path. */ private function findByPath($query, $language = 'glob') { $matches = array(); $query = '/' . ltrim($query, '/'); foreach ($this->repo->find($query, $language) as $resource) { $matches[$resource->getPath()] = StringUtil::getShortClassName(get_class($resource)); } return $matches; }
/** * {@inheritdoc} */ public function prepareInstallation(AssetMapping $mapping) { $glob = $mapping->getGlob(); $serverName = $mapping->getServerName(); $resources = $this->repo->find($glob); if ($resources->isEmpty()) { throw NotInstallableException::noResourceMatches($glob); } if (!$this->servers->contains($serverName)) { throw NotInstallableException::serverNotFound($serverName); } $server = $this->servers->get($serverName); $installerName = $server->getInstallerName(); if (!$this->installerManager->hasInstallerDescriptor($installerName)) { throw NotInstallableException::installerNotFound($installerName); } $installerDescriptor = $this->installerManager->getInstallerDescriptor($installerName); $installer = $this->loadInstaller($installerDescriptor); $rootDir = $this->context->getRootDirectory(); $params = new InstallationParams($installer, $installerDescriptor, $resources, $mapping, $server, $rootDir); $installer->validateParams($params); return $params; }
private function loadResourcesFromRepo() { $glob = VarUtils::resolve($this->glob, $this->getVars(), $this->getValues()); // Lazily load the resources. If the resources are stored in a database, // we only want to fetch them if really necessary. foreach ($this->repo->find($glob) as $resource) { // Ignore non-file resources if (!$resource instanceof FileResource) { continue; } $this->add(new PuliResourceAsset($resource)); } $this->loaded = true; }
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()); } } }
/** * {@inheritdoc} */ public function getResources() { return $this->repo->find($this->getQuery()); }