Adds a resource for this collection.
public addResource ( Symfony\Component\Config\Resource\ResourceInterface $resource ) | ||
$resource | Symfony\Component\Config\Resource\ResourceInterface | A resource instance |
public function load($resource, $type = null) { $collection = new RouteCollection(); foreach ($this->adminFactory->getAdmins() as $adminId => $admin) { $routePatternPrefix = $admin->getRoutePatternPrefix(); $routeNamePrefix = $admin->getRouteNamePrefix(); foreach ($admin->getActions() as $action) { $defaults = array( '_controller' => 'WhiteOctoberAdminBundle:Admin:execute', '_white_october_admin.admin' => $adminId, '_white_october_admin.action' => $action->getFullName(), ); $defaults = array_merge($action->getRouteDefaults(), $defaults); $route = new Route($routePatternPrefix.$action->getRoutePatternSuffix(), $defaults, $action->getRouteRequirements()); $collection->add($ups = $routeNamePrefix.'_'.$action->getRouteNameSuffix(), $route); $reflection = new \ReflectionObject($action); $collection->addResource(new FileResource($reflection->getFileName())); } $reflection = new \ReflectionObject($admin); $collection->addResource(new FileResource($reflection->getFileName())); } return $collection; }
/** * {@inheritDoc} */ public function load($resource, $type = null) { $collection = new SymfonyRouteCollection(); foreach ($this->adminServiceIds as $id) { $admin = $this->pool->getInstance($id); foreach ($admin->getRoutes()->getElements() as $code => $route) { $collection->add($route->getDefault('_sonata_name'), $route); } $reflection = new \ReflectionObject($admin); $collection->addResource(new FileResource($reflection->getFileName())); } $reflection = new \ReflectionObject($this->container); $collection->addResource(new FileResource($reflection->getFileName())); return $collection; }
public function load(RouteCollection $collection) { $i18nCollection = new RouteCollection(); // add translation resources foreach ($this->locales as $locale) { if (file_exists($metadata = $this->cacheDir . '/translations/catalogue.' . $locale . '.php.meta')) { foreach (unserialize(file_get_contents($metadata)) as $resource) { $i18nCollection->addResource($resource); } } } // add route resources foreach ($collection->getResources() as $resource) { $i18nCollection->addResource($resource); } foreach ($collection->all() as $name => $route) { if ($this->isNotTranslatable($name, $route)) { $i18nCollection->add($name, $route); continue; } $keepOriginal = false; $translations = new RouteCollection(); $patterns = array(); foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) { $i18nRoute = clone $route; // if no translation exists, we use the current pattern if ($name === ($i18nPattern = $this->translator->trans($name, array(), $this->catalogue, $locale))) { $i18nPattern = $route->getPattern(); } // prefix with locale if requested if (I18nRouter::STRATEGY_PREFIX === $this->strategy || I18nRouter::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) { $i18nPattern = '/' . $locale . $i18nPattern; } if (isset($patterns[$i18nPattern])) { $keepOriginal = true; } $patterns[$i18nPattern] = true; $i18nRoute->setPattern($i18nPattern); $i18nRoute->setDefault('_locale', $locale); $translations->add($locale . '_' . $name, $i18nRoute); } if ($keepOriginal || $route->getOption('i18n_keep')) { $i18nCollection->add($name, $route); } $i18nCollection->addCollection($translations); } return $i18nCollection; }
public function testImport() { $resolvedLoader = $this->getMock('Symfony\\Component\\Config\\Loader\\LoaderInterface'); $resolver = $this->getMock('Symfony\\Component\\Config\\Loader\\LoaderResolverInterface'); $resolver->expects($this->once())->method('resolve')->with('admin_routing.yml', 'yaml')->will($this->returnValue($resolvedLoader)); $originalRoute = new Route('/foo/path'); $expectedCollection = new RouteCollection(); $expectedCollection->add('one_test_route', $originalRoute); $expectedCollection->addResource(new FileResource(__DIR__ . '/Fixtures/file_resource.yml')); $resolvedLoader->expects($this->once())->method('load')->with('admin_routing.yml', 'yaml')->will($this->returnValue($expectedCollection)); $loader = $this->getMock('Symfony\\Component\\Config\\Loader\\LoaderInterface'); $loader->expects($this->any())->method('getResolver')->will($this->returnValue($resolver)); // import the file! $routes = new RouteCollectionBuilder($loader); $importedRoutes = $routes->import('admin_routing.yml', '/', 'yaml'); // we should get back a RouteCollectionBuilder $this->assertInstanceOf('Symfony\\Component\\Routing\\RouteCollectionBuilder', $importedRoutes); // get the collection back so we can look at it $addedCollection = $importedRoutes->build(); $route = $addedCollection->get('one_test_route'); $this->assertSame($originalRoute, $route); // should return file_resource.yml, which is in the original collection $this->assertCount(1, $addedCollection->getResources()); // make sure the routes were imported into the top-level builder $this->assertCount(1, $routes->build()); }
public function beatrixLoad($file, $cache, $readCache = true) { $path = $this->locator->locate($file); $config = $cache->file('beatrixRoutes', $path, 'yml', $readCache); $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); // empty file if (null === $config) { return $collection; } // not an array if (!is_array($config)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path)); } foreach ($config as $name => $config) { if (isset($config['pattern'])) { if (isset($config['path'])) { throw new \InvalidArgumentException(sprintf('The file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path)); } $config['path'] = $config['pattern']; unset($config['pattern']); } $this->validate($config, $name, $path); if (isset($config['resource'])) { $this->parseImport($collection, $config, $path, $file); } else { $this->parseRoute($collection, $name, $config, $path); } } return $collection; }
/** * Loads a Yaml file. * * @param string $file A Yaml file path * @param string|null $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When a route can't be parsed because YAML is invalid * * @api */ public function load($file, $type = null) { $path = $this->locator->locate($file); if (!stream_is_local($path)) { throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path)); } if (!file_exists($path)) { throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path)); } if (null === $this->yamlParser) { $this->yamlParser = new YamlParser(); } $config = $this->yamlParser->parse(file_get_contents($path)); $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); // empty file if (null === $config) { return $collection; } // not an array if (!is_array($config)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path)); } foreach ($config as $name => $config) { $this->validate($config, $name, $path); if (isset($config['resource'])) { $this->parseImport($collection, $config, $path, $file); } else { $this->parseRoute($collection, $name, $config, $path); } } return $collection; }
public function testCloneWithoutHiddenWithExistingDestination() { $src = new RouteCollection(); $src->add('route1', new Route('/route1')); $src->add('route2', new Route('/route2', [], [], ['hidden' => true])); $src->add('route3', new Route('/route3', [], [], ['hidden' => false])); $src->addResource(new DirectoryResource('resource1')); $src->addResource(new DirectoryResource('resource2')); $dest = new RouteCollection(); $result = RouteCollectionUtil::cloneWithoutHidden($src, $dest); $this->assertSame($dest, $result); $this->assertCount(2, $result); $this->assertNotNull($result->get('route1')); $this->assertNotNull($result->get('route3')); $this->assertCount(2, $result->getResources()); }
/** * Loads a JSON file * * @param string $file A JSON file path * @param string|null $type The resource type * * @return RouteCollection * * @throws InvalidArgumentException When the JSON is invalid */ public function load($file, $type = null) { $path = $this->locator->locate($file); if (!stream_is_local($path)) { $message = sprintf('This is not a local file "%s"', $path); throw new InvalidArgumentException($message); } if (!file_exists($path)) { $message = sprintf('File "%s" not found', $path); throw new InvalidArgumentException($message); } $parsedConfig = json_decode(file_get_contents($path), true); $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); // empty file if ($parsedConfig === null) { return $collection; } // not an array if (!is_array($parsedConfig)) { $message = sprintf('The file "%s" must contain a JSON object', $path); throw new InvalidArgumentException($message); } foreach ($parsedConfig as $name => $config) { $this->validate($config, $name, $path); if (isset($config['resource'])) { $this->parseImport($collection, $config, $path, $file); } else { $this->parseRoute($collection, $name, $config, $path); } } return $collection; }
/** * {@inheritdoc} */ public function getRouteCollection() { static $i18nCollection; if ($i18nCollection instanceof RouteCollection === false) { if (null === $this->collection) { $this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']); } $i18nCollection = new RouteCollection(); foreach ($this->collection->getResources() as $resource) { $i18nCollection->addResource($resource); } foreach ($this->collection->all() as $name => $route) { //do not add i18n routing prefix if ($this->shouldExcludeRoute($name, $route)) { $i18nCollection->add($name, $route); continue; } //add i18n routing prefix foreach ($this->generateI18nPatterns($name, $route) as $pattern => $locales) { foreach ($locales as $locale) { $localeRoute = clone $route; $localeRoute->setPath($pattern); $localeRoute->setDefault('_locale', $locale); $i18nCollection->add($locale . self::ROUTING_PREFIX . $name, $localeRoute); } } } } return $i18nCollection; }
public function load($resource, $type = null) { $collection = new RouteCollection(); $resource = str_replace('\\', '/', $resource); $namespace = $this->getNamespaceFromResource($resource); $bundle_name = $this->getBundleNameFromResource($resource); foreach ($this->actions as $controller => $datas) { $action = 'index'; if ($controller_folder = $this->getControllerFolder($resource)) { $route_name = str_replace(array('/', '\\'), '_', $namespace) . '_' . $bundle_name . '_' . $controller_folder . '_' . $controller; } else { $route_name = str_replace(array('/', '\\'), '_', $namespace) . '_' . $bundle_name . '_' . $controller; } if (isset($datas['controller'])) { $action = $controller; $controller = $datas['controller']; } if ($controller_folder) { $datas['defaults']['_controller'] = $namespace . '\\' . $bundle_name . '\\Controller\\' . $controller_folder . '\\' . ucfirst($controller) . 'Controller::' . $action . 'Action'; } else { $datas['defaults']['_controller'] = str_replace(array('/', '\\'), '_', $namespace) . $bundle_name . ':' . ucfirst($controller) . ':' . $action; } $route = new Route($datas['pattern'], $datas['defaults'], $datas['requirements']); $collection->add($route_name, $route); $collection->addResource(new FileResource($resource . ucfirst($controller) . 'Controller.php')); } return $collection; }
public function load(RouteCollection $collection) { $i18nCollection = new RouteCollection(); foreach ($collection->getResources() as $resource) { $i18nCollection->addResource($resource); } $this->patternGenerationStrategy->addResources($i18nCollection); foreach ($collection->all() as $name => $route) { if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) { $i18nCollection->add($name, $route); continue; } foreach ($this->patternGenerationStrategy->generateI18nPatterns($name, $route) as $pattern => $locales) { // If this pattern is used for more than one locale, we need to keep the original route. // We still add individual routes for each locale afterwards for faster generation. if (count($locales) > 1) { $catchMultipleRoute = clone $route; $catchMultipleRoute->getPath($pattern); $catchMultipleRoute->setDefault('_locales', $locales); $i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchMultipleRoute); } foreach ($locales as $locale) { $localeRoute = clone $route; $localeRoute->getPath($pattern); $localeRoute->setDefault('_locale', $locale); $i18nCollection->add($locale . I18nLoader::ROUTING_PREFIX . $name, $localeRoute); } } } return $i18nCollection; }
public function load($routingResource, $type = null) { $routes = new RouteCollection(); // resources foreach ($this->am->getResources() as $resources) { if (!$resources instanceof \Traversable) { $resources = array($resources); } foreach ($resources as $resource) { if (file_exists($path = (string) $resource)) { $routes->addResource(new FileResource($path)); } } } // routes foreach ($this->am->getNames() as $name) { $asset = $this->am->get($name); $defaults = array('_controller' => 'assetic.controller:render', 'name' => $name); if ($extension = pathinfo($asset->getTargetUrl(), PATHINFO_EXTENSION)) { $defaults['_format'] = $extension; } $routes->add('assetic_' . $name, new Route($asset->getTargetUrl(), $defaults)); } return $routes; }
public function load($routingResource, $type = null) { $routes = new RouteCollection(); // resources foreach ($this->am->getResources() as $resources) { if (!$resources instanceof \Traversable) { $resources = array($resources); } foreach ($resources as $resource) { $routes->addResource(new AsseticResource($resource)); } } // routes foreach ($this->am->getNames() as $name) { $asset = $this->am->get($name); $formula = $this->am->getFormula($name); $this->loadRouteForAsset($routes, $asset, $name); $debug = isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->am->isDebug(); $combine = isset($formula[2]['combine']) ? $formula[2]['combine'] : !$debug; // add a route for each "leaf" in debug mode if (!$combine) { $i = 0; foreach ($asset as $leaf) { $this->loadRouteForAsset($routes, $leaf, $name, $i++); } } } return $routes; }
/** * Loads an XML file. * * @param string $file An XML file path * @param string $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When a tag can't be parsed */ public function load($file, $type = null) { $path = $this->locator->locate($file); $xml = $this->loadFile($path); $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); // process routes and imports foreach ($xml->documentElement->childNodes as $node) { if (!$node instanceof \DOMElement) { continue; } switch ($node->tagName) { case 'route': $this->parseRoute($collection, $node, $path); break; case 'import': $resource = (string) $node->getAttribute('resource'); $type = (string) $node->getAttribute('type'); $prefix = (string) $node->getAttribute('prefix'); $this->currentDir = dirname($path); $collection->addCollection($this->import($resource, '' !== $type ? $type : null), $prefix); break; default: throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName)); } } return $collection; }
/** * Loads a Yaml file. * * @param string $file A Yaml file path * @param string $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When route can't be parsed * * @api */ public function load($file, $type = null) { $path = $this->locator->locate($file); $config = Yaml::parse($path); $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); // empty file if (null === $config) { $config = array(); } // not an array if (!is_array($config)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $file)); } foreach ($config as $name => $config) { $config = $this->normalizeRouteConfig($config); if (isset($config['resource'])) { $type = isset($config['type']) ? $config['type'] : null; $prefix = isset($config['prefix']) ? $config['prefix'] : null; $defaults = isset($config['defaults']) ? $config['defaults'] : array(); $requirements = isset($config['requirements']) ? $config['requirements'] : array(); $options = isset($config['options']) ? $config['options'] : array(); $this->setCurrentDir(dirname($path)); $collection->addCollection($this->import($config['resource'], $type, false, $file), $prefix, $defaults, $requirements, $options); } else { $this->parseRoute($collection, $name, $config, $path); } } return $collection; }
/** * Loads a Yaml file. * * @param string $file A Yaml file path * @param string $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When route can't be parsed */ public function load($file, $type = null) { $path = $this->findFile($file); $config = $this->loadFile($path); $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); // empty file if (null === $config) { $config = array(); } // not an array if (!is_array($config)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $file)); } foreach ($config as $name => $config) { if (isset($config['resource'])) { $type = isset($config['type']) ? $config['type'] : null; $prefix = isset($config['prefix']) ? $config['prefix'] : null; $this->currentDir = dirname($path); $collection->addCollection($this->import($config['resource'], $type), $prefix); } elseif (isset($config['pattern'])) { $this->parseRoute($collection, $name, $config, $path); } else { throw new \InvalidArgumentException(sprintf('Unable to parse the "%s" route.', $name)); } } return $collection; }
private function addClassResource(\ReflectionClass $class, RouteCollection $collection) { do { if (is_file($class->getFileName())) { $collection->addResource(new FileResource($class->getFileName())); } } while ($class = $class->getParentClass()); }
/** * Loads a Yaml collection file. * * @param string $file A Yaml file path * @param string $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When route can't be parsed */ public function load($file, $type = null) { $path = $this->locator->locate($file); $config = Yaml::parse($path); $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); // process routes and imports foreach ($config as $name => $config) { if (isset($config['resource'])) { $resource = $config['resource']; $prefix = isset($config['prefix']) ? $config['prefix'] : null; $namePrefix = isset($config['name_prefix']) ? $config['name_prefix'] : null; $parent = isset($config['parent']) ? $config['parent'] : null; $type = isset($config['type']) ? $config['type'] : null; $currentDir = dirname($path); $parents = array(); if (!empty($parent)) { if (!isset($this->collectionParents[$parent])) { throw new \InvalidArgumentException(sprintf('Cannot find parent resource with name %s', $parent)); } $parents = $this->collectionParents[$parent]; } $imported = $this->processor->importResource($this, $resource, $parents, $prefix, $namePrefix, $type, $currentDir); if ($imported instanceof RestRouteCollection) { $parents[] = ($prefix ? $prefix . '/' : '') . $imported->getSingularName(); $prefix = null; $this->collectionParents[$name] = $parents; } $imported->addPrefix($prefix); $collection->addCollection($imported); } elseif (isset($config['pattern']) || isset($config['path'])) { // the YamlFileLoader of the Routing component only checks for // the path option if (!isset($config['path'])) { $config['path'] = $config['pattern']; } if ($this->includeFormat) { // append format placeholder if not present if (false === strpos($config['path'], '{_format}')) { $config['path'] .= '.{_format}'; } // set format requirement if configured globally if (!isset($config['requirements']['_format']) && !empty($this->formats)) { $config['requirements']['_format'] = implode('|', array_keys($this->formats)); } } // set the default format if configured if (null !== $this->defaultFormat) { $config['defaults']['_format'] = $this->defaultFormat; } $this->parseRoute($collection, $name, $config, $path); } else { throw new \InvalidArgumentException(sprintf('Unable to parse the "%s" route.', $name)); } } return $collection; }
/** * {@inheritDoc} */ public function addResources(RouteCollection $i18nCollection) { foreach ($this->locales as $locale) { if (file_exists($metadata = $this->cacheDir . '/translations/catalogue.' . $locale . '.php.meta')) { foreach (unserialize(file_get_contents($metadata)) as $resource) { $i18nCollection->addResource($resource); } } } }
/** * Loads from annotations from a file. * * @param string $file A PHP file path * @param string|null $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed */ public function load($file, $type = null) { $path = $this->locator->locate($file); $collection = new RouteCollection(); if ($class = $this->findClass($path)) { $collection->addResource(new FileResource($path)); $collection->addCollection($this->loader->load($class, $type)); } return $collection; }
/** * Loads a all ApplicationBundles routes. * * @param string $file The anything * @param string $type The resource type * * @return RouteCollection A RouteCollection instance */ public function load($file, $type = null) { $collection = new RouteCollection(); foreach ($this->kernel->getBundle('App', false) as $bundle) { if (file_exists($routing = $bundle->getPath() . '/Resources/config/routing.yml')) { $collection->addCollection(parent::load($routing)); $collection->addResource(new FileResource($routing)); } } return $collection; }
/** * Loads from annotations from a file. * * @param string $resource A directory prefixed with annotations: * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When route can't be parsed */ public function load($resource) { $path = $this->getAbsolutePath(substr($resource, 12)); if (!file_exists($path)) { throw new \InvalidArgumentException(sprintf('The file "%s" cannot be found (in: %s).', $resource, implode(', ', $this->paths))); } $collection = new RouteCollection(); if ($class = $this->findClass($path)) { $collection->addResource(new FileResource($path)); $collection->addCollection($this->loader->load($class)); } return $collection; }
public function load(RouteCollection $collection) { $i18nCollection = new RouteCollection(); foreach ($collection->getResources() as $resource) { $i18nCollection->addResource($resource); } $this->patternGenerationStrategy->addResources($i18nCollection); $existedHomepage = []; foreach ($collection->all() as $name => $route) { if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) { $i18nCollection->add($name, $route); continue; } $patters = $this->patternGenerationStrategy->generateI18nPatterns($name, $route); foreach ($patters as $pattern => $hostLocales) { // If this pattern is used for more than one locale, we need to keep the original route. // We still add individual routes for each locale afterwards for faster generation. foreach ($hostLocales as $host => $locales) { if (count($locales) > 1) { $catchMultipleRoute = clone $route; $catchMultipleRoute->setPath($pattern); $catchMultipleRoute->setHost($host); $catchMultipleRoute->setRequirement('_locale', implode('|', $locales)); $catchMultipleRoute->setOption('original_name', $name)->setOption('locales', $locales); $i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchMultipleRoute); } elseif (count($locales) == 1) { $catchRoute = clone $route; $catchRoute->setPath($pattern); $catchRoute->setHost($host); $catchRoute->setDefault('_locale', $locales[0]); $catchRoute->setRequirement('_locale', $locales[0]); $catchRoute->setOption('original_name', $name)->setOption('locales', $locales); $i18nCollection->add(implode('_', $locales) . I18nLoader::ROUTING_PREFIX . $name, $catchRoute); } if ($pattern == '/') { $existedHomepage[] = $host; } } } } $offices = $this->entityManager->getRepository('OctavaMuiBundle:Office')->getRoutingOffices(); foreach ($offices as $locale => $office) { if ($office->getIncludeLangInUrl() && !in_array($office->getHost(), $existedHomepage)) { $redirectRoute = new Route('/', ['_controller' => 'FrameworkBundle:Redirect:urlRedirect', 'path' => '/' . $locale . '/', 'permanent' => true]); $redirectRoute->setHost($office->getHost()); $i18nCollection->add($locale . I18nLoader::ROUTING_PREFIX . 'redirect_to_root', $redirectRoute); } } return $i18nCollection; }
/** * Loads from annotations from a file. * * @param string $file A PHP file path * @param string|null $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed */ public function load($file, $type = null) { $path = $this->locator->locate($file); $collection = new RouteCollection(); if ($class = $this->findClass($path)) { $collection->addResource(new FileResource($path)); $collection->addCollection($this->loader->load($class, $type)); } if (PHP_VERSION_ID >= 70000) { // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098 gc_mem_caches(); } return $collection; }
public function load($routingResource, $type = null) { $routes = new RouteCollection(); // resources foreach ($this->am->getResources() as $resources) { if (!$resources instanceof \Traversable) { $resources = array($resources); } foreach ($resources as $resource) { if (interface_exists('Symfony\\Component\\Config\\Resource\\SelfCheckingResourceInterface')) { $routes->addResource(new SelfCheckingAsseticResource($resource)); } else { // for BC with symfony/config 2.7 and lower $routes->addResource(new AsseticResource($resource)); } } } // routes foreach ($this->am->getNames() as $name) { if (!$this->am->hasFormula($name)) { continue; } $asset = $this->am->get($name); $formula = $this->am->getFormula($name); $this->loadRouteForAsset($routes, $asset, $name); $debug = isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->am->isDebug(); $combine = isset($formula[2]['combine']) ? $formula[2]['combine'] : !$debug; // add a route for each "leaf" in debug mode if (!$combine) { $i = 0; foreach ($asset as $leaf) { $this->loadRouteForAsset($routes, $leaf, $name, $i++); } } } return $routes; }
/** * Loads a resource. * * @param mixed $resource The resource * @param string $type The resource type */ public function load($resource, $type = null) { $entityManager = $this->getEntityManager(); $collection = new RouteCollection(); $collection->addResource(new DoctrineOrmResource('ZymRouterBundle:Route')); try { $routes = $entityManager->getRepository('ZymRouterBundle:Route')->findAll(); } catch (\Doctrine\DBAL\DBALException $e) { $routes = array(); } foreach ($routes as $route) { $collection->add($route->getName(), $route); } return $collection; }
/** * Loads an XML file. * * @param string $file An XML file path * @param string|null $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When the file cannot be loaded or when the XML cannot be * parsed because it does not validate against the scheme. */ public function load($file, $type = null) { $path = $this->locator->locate($file); $xml = $this->loadFile($path); $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); // process routes and imports foreach ($xml->documentElement->childNodes as $node) { if (!$node instanceof \DOMElement) { continue; } $this->parseNode($collection, $node, $path, $file); } return $collection; }
/** * Loads from annotations from a directory. * * @param string $path A directory path * @param string $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When the directory does not exist or its routes cannot be parsed */ public function load($path, $type = null) { $dir = $this->locator->locate($path); $collection = new RouteCollection(); $collection->addResource(new DirectoryResource($dir, '/\\.php$/')); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { if (!$file->isFile() || '.php' !== substr($file->getFilename(), -4)) { continue; } if ($class = $this->findClass($file)) { $collection->addCollection($this->loader->load($class, $type)); } } return $collection; }
public function load($resource, $type = null) { $routes = new RouteCollection(); $nRoutes = $this->nRouteManager->getNestedRoutes(); foreach ($nRoutes as $nRoute) { $flattenRoutes = $this->flattenRouteFactory->getFlattenRoutes($nRoute); $this->fRouteManager->addFlattenRoute($flattenRoutes); $registerRoutes = $this->flattenRouteFactory->getRoutes($flattenRoutes); foreach ($registerRoutes as $key => $route) { $routes->add($key, $route); } $reflection = new ReflectionObject($nRoute); $routes->addResource(new FileResource($reflection->getFileName())); } $routes->addPrefix($this->rootPath); return $routes; }
/** * Copies all routers not marked as hidden from a source to a destination collection. * If the destination collection is not specifies the new instance of RouteCollection will be used. * * @param RouteCollection $src The source route collection * @param RouteCollection|null $dest The destination route collection * * @return RouteCollection The destination route collection */ public static function cloneWithoutHidden(RouteCollection $src, RouteCollection $dest = null) { if (null === $dest) { $dest = new RouteCollection(); } $routes = $src->all(); foreach ($routes as $name => $route) { if (!$route->getOption('hidden')) { $dest->add($name, $route); } } $resources = $src->getResources(); foreach ($resources as $resource) { $dest->addResource($resource); } return $dest; }