/** * {@inheritdoc} */ public function generateUrl($repositoryPath, $currentUrl = null) { $matchedBinding = null; $bindings = $this->discovery->findBindings(self::BINDING_TYPE); foreach ($bindings as $binding) { /** @var ResourceBinding $binding */ if (Glob::match($repositoryPath, $binding->getQuery())) { $matchedBinding = $binding; break; } } if (null === $matchedBinding) { throw new CannotGenerateUrlException(sprintf('Cannot generate URL for "%s". The path is not public.', $repositoryPath)); } // We can't prevent a resource to be mapped to more than one public path // For now, we'll just take the first one and make the user responsible // for preventing duplicates $url = $this->generateUrlForBinding($matchedBinding, $repositoryPath); if ($currentUrl) { try { $url = Url::makeRelative($url, $currentUrl); } catch (InvalidArgumentException $e) { throw new CannotGenerateUrlException(sprintf('Cannot generate URL for "%s" to current url "%s".', $repositoryPath, $currentUrl), $e->getCode(), $e); } } return $url; }
/** * Creates the container file from the discovered providers. * * @param Discovery $discovery */ public static function compileContainer(Discovery $discovery) { $containerFile = self::getContainerFilePath(); $compiler = new Compiler(); $bindings = $discovery->findBindings('container-interop/DefinitionProviderFactories'); $definitionProviders = []; $priorities = []; foreach ($bindings as $binding) { /* @var $binding ClassBinding */ $definitionProviderFactoryClassName = $binding->getClassName(); // From the factory class name, let's call the buildDefinitionProvider static method to get the definitionProvider. $definitionProviders[] = call_user_func([$definitionProviderFactoryClassName, 'buildDefinitionProvider'], $discovery); $priorities[] = $binding->getParameterValue('priority'); } // Sort definition providers according to their priorities. array_multisort($priorities, $definitionProviders); foreach ($definitionProviders as $provider) { $compiler->register($provider); } $containerFileContent = $compiler->compile('\\TheCodingMachine\\Yaco\\Container'); $filesystem = new Filesystem(); if (!$filesystem->exists(dirname($containerFile))) { $filesystem->mkdir(dirname($containerFile)); } $filesystem->dumpFile($containerFile, $containerFileContent); $filesystem->chmod($containerFile, 0664); }
/** * {@inheritdoc} */ public function registerBundles() { $bundles = [new NanbandoBundle(), new OneupFlysystemBundle(), new CocurSlugifyBundle()]; /** @var ClassBinding $binding */ foreach ($this->discovery->findBindings('nanbando/bundle') as $binding) { $class = $binding->getClassName(); if (class_exists($class)) { $bundles[] = new $class(); } } return $bundles; }
/** * Finds the resources for a given binding type. * * @param string $typeName The type name. * * @return string[] An array of short resource class names indexed by * the resource path. */ private function findByBindingType($typeName) { $matches = array(); $expr = Expr::isInstanceOf('Puli\\Discovery\\Binding\\ResourceBinding'); foreach ($this->discovery->findBindings($typeName, $expr) as $binding) { /** @var ResourceBinding $binding */ foreach ($binding->getResources() as $resource) { $matches[$resource->getPath()] = StringUtil::getShortClassName(get_class($resource)); } } ksort($matches); return $matches; }