addCollection() public method

Adds a route collection to the current set of routes (at the end of the current set).
public addCollection ( RouteCollection $collection, string $prefix = '' )
$collection RouteCollection A RouteCollection instance
$prefix string An optional prefix to add before each pattern of the route collection
 /**
  * @param mixed $resource
  * @param null $type
  * @return \Symfony\Component\Routing\RouteCollection
  * @throws \RuntimeException
  */
 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     /*
      * For each core bunle then for each module
      */
     // CoreBundle
     $loader = $this->resolver->resolve('@EtuCoreBundle/Api/Resource/', 'annotation');
     if ($loader) {
         $routes->addCollection($loader->load('@EtuCoreBundle/Api/Resource/', 'annotation'));
     }
     // UserBundle
     $loader = $this->resolver->resolve('@EtuUserBundle/Api/Resource/', 'annotation');
     if ($loader) {
         $routes->addCollection($loader->load('@EtuUserBundle/Api/Resource/', 'annotation'));
     }
     /** @var $module Module */
     foreach ($this->kernel->getModulesDefinitions() as $module) {
         $routing = $module->getApiRouting();
         $loader = $this->resolver->resolve($routing['resource'], $routing['type']);
         if ($loader) {
             $routes->addCollection($loader->load($routing['resource'], $routing['type']));
         }
     }
     return $routes;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function addRoutes(RouteCollection $routes)
 {
     if (empty($this->routes)) {
         $this->routes = $routes;
     } else {
         $this->routes->addCollection($routes);
     }
 }
Exemplo n.º 3
0
 /**
  * Find a list of controllers
  *
  * @param string $base_path Base path to prepend to file paths
  * @return provider
  */
 public function find($base_path = '')
 {
     $this->routes = new RouteCollection();
     foreach ($this->routing_files as $file_path) {
         $loader = new YamlFileLoader(new FileLocator(phpbb_realpath($base_path)));
         $this->routes->addCollection($loader->load($file_path));
     }
     return $this;
 }
Exemplo n.º 4
0
 public function testDump()
 {
     $collection = new RouteCollection();
     // defaults and requirements
     $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'), array('bar' => 'baz|symfony')));
     // method requirement
     $collection->add('bar', new Route('/bar/{foo}', array(), array('_method' => 'GET|head')));
     // GET method requirement automatically adds HEAD as valid
     $collection->add('barhead', new Route('/barhead/{foo}', array(), array('_method' => 'GET')));
     // simple
     $collection->add('baz', new Route('/test/baz'));
     // simple with extension
     $collection->add('baz2', new Route('/test/baz.html'));
     // trailing slash
     $collection->add('baz3', new Route('/test/baz3/'));
     // trailing slash with variable
     $collection->add('baz4', new Route('/test/{foo}/'));
     // trailing slash and method
     $collection->add('baz5', new Route('/test/{foo}/', array(), array('_method' => 'post')));
     // complex name
     $collection->add('baz.baz6', new Route('/test/{foo}/', array(), array('_method' => 'put')));
     // defaults without variable
     $collection->add('foofoo', new Route('/foofoo', array('def' => 'test')));
     // pattern with quotes
     $collection->add('quoter', new Route('/{quoter}', array(), array('quoter' => '[\']+')));
     // prefixes
     $collection1 = new RouteCollection();
     $collection1->add('foo', new Route('/{foo}'));
     $collection1->add('bar', new Route('/{bar}'));
     $collection2 = new RouteCollection();
     $collection2->addCollection($collection1, '/b\'b');
     $collection1 = new RouteCollection();
     $collection1->add('foo1', new Route('/{foo1}'));
     $collection1->add('bar1', new Route('/{bar1}'));
     $collection2->addCollection($collection1, '/b\'b');
     $collection->addCollection($collection2, '/a');
     // "dynamic" prefix
     $collection1 = new RouteCollection();
     $collection1->add('foo', new Route('/{foo}'));
     $collection1->add('bar', new Route('/{bar}'));
     $collection2 = new RouteCollection();
     $collection2->addCollection($collection1, '/b');
     $collection->addCollection($collection2, '/{_locale}');
     $collection->add('ababa', new Route('/ababa'));
     // some more prefixes
     $collection1 = new RouteCollection();
     $collection1->add('foo', new Route('/{foo}'));
     $collection->addCollection($collection1, '/aba');
     $dumper = new PhpMatcherDumper($collection, new RequestContext());
     $this->assertStringEqualsFile(__DIR__ . '/../../Fixtures/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');
     // force HTTPS redirection
     $collection->add('secure', new Route('/secure', array(), array('_scheme' => 'https')));
     // force HTTP redirection
     $collection->add('nonsecure', new Route('/nonsecure', array(), array('_scheme' => 'http')));
     $this->assertStringEqualsFile(__DIR__ . '/../../Fixtures/dumper/url_matcher2.php', $dumper->dump(array('base_class' => 'Symfony\\Tests\\Component\\Routing\\Fixtures\\RedirectableUrlMatcher')), '->dump() dumps basic routes to the correct PHP file.');
 }
 protected function getRouteCollection()
 {
     $collection = new RouteCollection();
     $collection->add('overriden', new Route('/overriden'));
     // defaults and requirements
     $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'), array('bar' => 'baz|symfony')));
     // method requirement
     $collection->add('bar', new Route('/bar/{foo}', array(), array('_method' => 'GET|head')));
     // GET method requirement automatically adds HEAD as valid
     $collection->add('barhead', new Route('/barhead/{foo}', array(), array('_method' => 'GET')));
     // simple
     $collection->add('baz', new Route('/test/baz'));
     // simple with extension
     $collection->add('baz2', new Route('/test/baz.html'));
     // trailing slash
     $collection->add('baz3', new Route('/test/baz3/'));
     // trailing slash with variable
     $collection->add('baz4', new Route('/test/{foo}/'));
     // trailing slash and method
     $collection->add('baz5', new Route('/test/{foo}/', array(), array('_method' => 'post')));
     // complex name
     $collection->add('baz.baz6', new Route('/test/{foo}/', array(), array('_method' => 'put')));
     // defaults without variable
     $collection->add('foofoo', new Route('/foofoo', array('def' => 'test')));
     // pattern with quotes
     $collection->add('quoter', new Route('/{quoter}', array(), array('quoter' => '[\']+')));
     // prefixes
     $collection1 = new RouteCollection();
     $collection1->add('overriden', new Route('/overriden1'));
     $collection1->add('foo1', new Route('/{foo}'));
     $collection1->add('bar1', new Route('/{bar}'));
     $collection2 = new RouteCollection();
     $collection2->addCollection($collection1, '/b\'b');
     $collection2->add('overriden', new Route('/overriden2'));
     $collection1 = new RouteCollection();
     $collection1->add('foo2', new Route('/{foo1}'));
     $collection1->add('bar2', new Route('/{bar1}'));
     $collection2->addCollection($collection1, '/b\'b');
     $collection->addCollection($collection2, '/a');
     // "dynamic" prefix
     $collection1 = new RouteCollection();
     $collection1->add('foo3', new Route('/{foo}'));
     $collection1->add('bar3', new Route('/{bar}'));
     $collection2 = new RouteCollection();
     $collection2->addCollection($collection1, '/b');
     $collection->addCollection($collection2, '/{_locale}');
     $collection->add('ababa', new Route('/ababa'));
     // some more prefixes
     $collection1 = new RouteCollection();
     $collection1->add('foo4', new Route('/{foo}'));
     $collection->addCollection($collection1, '/aba');
     return $collection;
 }
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add this loader twice');
     }
     $collection = new RouteCollection();
     $resource = __DIR__ . '/../Resources/config';
     $locator = new FileLocator($resource);
     $loader = new YamlFileLoader($locator);
     $collection->addCollection($loader->load('routing.yml'));
     $collection->addCollection($loader->load('routing_admin.yml'));
     $this->loaded = true;
     return $collection;
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function load($data, $type = null)
 {
     $routeCollection = new RouteCollection();
     $routeCollection->addCollection($this->fileLoader->load('json_ld.xml'));
     $routeCollection->addCollection($this->fileLoader->load('hydra.xml'));
     foreach ($this->resourceCollection as $resource) {
         foreach ($resource->getCollectionOperations() as $operation) {
             $routeCollection->add($operation->getRouteName(), $operation->getRoute());
         }
         foreach ($resource->getItemOperations() as $operation) {
             $routeCollection->add($operation->getRouteName(), $operation->getRoute());
         }
     }
     return $routeCollection;
 }
Exemplo n.º 8
0
 /**
  * @todo clean this
  */
 public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add this loader twice');
     }
     $routes = new RouteCollection();
     $frontPageConfig = $this->container->get('system')->get('system.frontpage', 'blog');
     $frontPageProvider = $this->container->get('drafterbit_system.frontpage_provider');
     $reservedBaseUrl = [$this->container->getParameter('admin')];
     foreach ($frontPageProvider->all() as $prefix => $frontPage) {
         $frontRoutes = $frontPage->getRoutes();
         if ($prefix !== $frontPageConfig) {
             $frontRoutes->addPrefix($frontPage->getRoutePrefix());
             $reservedBaseUrl[] = $prefix;
         }
         $routes->addCollection($frontRoutes);
     }
     $defaults = array('_controller' => 'DrafterbitPageBundle:Frontend:view');
     // check if configured frontpage is not an app
     if (!array_key_exists($frontPageConfig, $frontPageProvider->all())) {
         // its page
         $defaults['slug'] = $frontPageConfig;
         $routes->add('_home', new Route('/', $defaults));
     }
     $reservedBaseUrl = implode('|', $reservedBaseUrl);
     // @link http://stackoverflow.com/questions/25496704/regex-match-slug-except-particular-start-words
     // @prototype  'slug' => "^(?!(?:backend|blog)(?:/|$)).*$"
     $requirements = array('slug' => "^(?!(?:%admin%|" . $reservedBaseUrl . "|)(?:/|\$)).*\$");
     $route2 = new Route('/{slug}', $defaults, $requirements);
     $routes->add('misc', $route2);
     return $routes;
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = null)
 {
     $collection = new RouteCollection();
     foreach ($this->localeResolver->getDomainConfig() as $_domain => $_locale) {
         $_collection = parent::load($resource, $type);
         foreach ($_collection->all() as $_name => $_route) {
             $_route->addDefaults(['_locale' => $_locale]);
             $_route->setHost($_domain);
             $collection->add($_locale . '__' . $this->urlizer->urlize($_domain, '_') . '__' . $_name, $_route);
         }
     }
     /*
      * Add default(fallback) route for default locale/domain
      * needs to be after the loop
      * */
     $defaultCollection = parent::load($resource, $type);
     $defaultCollection->addDefaults(['_locale' => $this->localeResolver->defaultLocale]);
     $collection->addCollection($defaultCollection);
     if ($this->localeResolver->localePattern == LocaleResolver::PATTERN_PARAMETER) {
         $collection = parent::load($resource, $type);
         //Prefix every victoire route with the locale
         $collection->addPrefix('/{_locale}');
         $collection->addCollection($collection);
         //Add a redirection to the default locale homepage when empty url '/'
         $this->addHomepageRedirection($collection);
     }
     return $collection;
 }
Exemplo n.º 10
0
 /**
  * @param string $resource
  * @param null $type
  * @return \Symfony\Component\Routing\RouteCollection
  */
 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     $logger = $this->container->get('logger');
     $logger->info('Загрузка рубрик для построения роутинга');
     $a = microtime(true);
     $rubrics = $this->em->getRepository('ApplicationIphpCoreBundle:Rubric')->createQueryBuilder('r')->orderBy('r.level', 'DESC')->getQuery()->getResult();
     foreach ($rubrics as $rubric) {
         $controller = $rubric->getControllerName();
         $rubricRoutes = null;
         //В контроллере можеть быть: Класс модуля
         if ($controller && substr($controller, -6) == 'Module') {
             $module = $this->moduleManager->getModuleFromRubric($rubric);
             if ($module) {
                 $rubricRoutes = $module->getRoutes();
             }
         }
         if ($rubricRoutes) {
             foreach ($rubricRoutes as $route) {
                 $route->setDefault('_rubric', $rubric->getFullPath());
             }
             $routes->addCollection($rubricRoutes, substr($rubric->getFullPath(), 0, -1));
         }
     }
     $b = microtime(true) - $a;
     $logger->info('Загрузили роуты за' . $b . ' с');
     return $routes;
 }
Exemplo n.º 11
0
 /**
  * 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;
 }
Exemplo n.º 12
0
 public function addGroup($config, $callback)
 {
     $router = $this->getSubRouter();
     if (is_callable($callback)) {
         $callback($router);
     } else {
         $e = new Error();
         $e->log(new \Exception('Segundo parâmetro não é uma função do tipo callable'));
     }
     $sub_collection = $router->getCollection();
     if (isset($config['defaults'])) {
         $sub_collection->addDefaults($config['defaults']);
     }
     if (isset($config['mask'])) {
         $sub_collection->addRequirements($config['mask']);
     }
     if (isset($config['options'])) {
         $sub_collection->addOptions($config['options']);
     }
     if (isset($config['host'])) {
         $sub_collection->setHost($config['host']);
     }
     if (isset($config['schemes'])) {
         $sub_collection->setSchemes($config['schemes']);
     }
     if (isset($config['methods'])) {
         $sub_collection->setMethods($config['methods']);
     }
     $this->collection->addCollection($sub_collection);
 }
Exemplo n.º 13
0
 /**
  * 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;
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = null)
 {
     if (true === $this->isLoaded) {
         throw new \RuntimeException('Do not add the "modera_routing" loader twice');
     }
     $resources = array();
     $items = $this->resourcesProvider->getItems();
     foreach ($items as $index => $resource) {
         if (!is_array($resource)) {
             $resource = array('resource' => $resource);
         }
         $resource = array_merge(array('order' => 0, 'type' => null), $resource);
         $resource['index'] = $index;
         $resources[] = $resource;
     }
     usort($resources, function ($a, $b) {
         if ($a['order'] == $b['order']) {
             return $a['index'] < $b['index'] ? -1 : 1;
         }
         return $a['order'] < $b['order'] ? -1 : 1;
     });
     $collection = new RouteCollection();
     foreach ($resources as $item) {
         $collection->addCollection($this->rootLoader->load($item['resource'], $item['type']));
     }
     $this->isLoaded = true;
     return $collection;
 }
 /**
  * @param string[] $paths
  */
 protected function loadRouteCollectionFromFiles(array $paths) : RouteCollection
 {
     $routeCollection = new RouteCollection();
     foreach ($paths as $path) {
         $routeCollection->addCollection($this->loadRouteCollectionFromFile($path));
     }
     return $routeCollection;
 }
Exemplo n.º 16
0
 /**
  * Loads from annotations from a directory glob pattern.
  *
  * @param string $glob A directory glob pattern containing "*"
  * @param string $type The resource type
  *
  * @return RouteCollection A RouteCollection instance
  *
  * @throws \InvalidArgumentException When route can't be parsed
  */
 public function load($glob, $type = null)
 {
     $collection = new RouteCollection();
     foreach ($this->getAbsolutePaths($glob) as $path) {
         $collection->addCollection(parent::load($path, $type));
     }
     return $collection;
 }
Exemplo n.º 17
0
 /**
  * Loads from annotations from an array of directories.
  *
  * @param  array $resource An array of directories prefixed with annotations:
  *
  * @return RouteCollection A RouteCollection instance
  *
  * @throws \InvalidArgumentException When route can't be parsed
  */
 public function load($resource)
 {
     $collection = new RouteCollection();
     foreach ($this->getAbsolutePaths(substr($resource, 12)) as $resource) {
         $collection->addCollection(parent::load('annotations:' . $resource));
     }
     return $collection;
 }
Exemplo n.º 18
0
 /**
  * Returns all routes in this collection.
  *
  * @return Route[] An array of routes
  */
 public function all()
 {
     $routeCollectionAll = new RouteCollection();
     foreach ($this->routeCollections as $routeCollection) {
         $routeCollectionAll->addCollection($routeCollection);
     }
     return $routeCollectionAll->all();
 }
 /**
  * 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;
 }
Exemplo n.º 20
0
 public function onKernelRequest(GetResponseEvent $event)
 {
     $collection = new RouteCollection();
     $collection->addPrefix('en');
     $collection->add('test', new Route('/hello', array('controller' => 'AppBundle/Controller/HelloController', 'action' => 'index')));
     $secondCollection = new RouteCollection();
     $secondCollection->addPrefix('prod');
     $collection->addCollection($secondCollection);
 }
 /**
  * {@inheritdoc}
  */
 public function load($routingResource, $type = null)
 {
     $collection = new RouteCollection();
     $routingResource = '@CaptchaBundle/Resources/config/routing.yml';
     $type = 'yaml';
     $importedRoutes = $this->import($routingResource, $type);
     $collection->addCollection($importedRoutes);
     return $collection;
 }
 public function load($resource, $type = null)
 {
     $locator = new PlatformResourceLocator([$this->kernel->getRootDir() . '/../src', $this->kernel->getRootDir() . '/../vendor']);
     $resources = $locator->locate('routing.yml');
     $collection = new RouteCollection();
     foreach ($resources as $resource) {
         $collection->addCollection($this->loader->load($resource));
     }
     return $collection;
 }
Exemplo n.º 23
0
 /**
  * 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;
 }
Exemplo n.º 24
0
 public function getRouteCollection()
 {
     if (!$this->routeCollection instanceof RouteCollection) {
         $this->routeCollection = new RouteCollection();
         foreach ($this->all() as $router) {
             $this->routeCollection->addCollection($router->getRouteCollection());
         }
     }
     return $this->routeCollection;
 }
Exemplo n.º 25
0
 protected function addWidgetsRouting(RouteCollection &$collection)
 {
     foreach ($this->widgets as $widgetParams) {
         $controllerResource = '@VictoireWidget' . $widgetParams['name'] . 'Bundle/Controller/';
         if ($this->getResolver()->resolve($controllerResource)) {
             $importedRoutes = $this->import($controllerResource, 'annotation');
             $collection->addCollection($importedRoutes);
         }
     }
 }
Exemplo n.º 26
0
 /**
  * Loads the routes
  *
  * @param null|string $app
  */
 public function loadRoutes($app = null)
 {
     if (is_string($app)) {
         $app = \OC_App::cleanAppId($app);
     }
     $requestedApp = $app;
     if ($this->loaded) {
         return;
     }
     if (is_null($app)) {
         $this->loaded = true;
         $routingFiles = $this->getRoutingFiles();
     } else {
         if (isset($this->loadedApps[$app])) {
             return;
         }
         $file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
         if ($file !== false && file_exists($file)) {
             $routingFiles = [$app => $file];
         } else {
             $routingFiles = [];
         }
     }
     \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
     foreach ($routingFiles as $app => $file) {
         if (!isset($this->loadedApps[$app])) {
             if (!\OC_App::isAppLoaded($app)) {
                 // app MUST be loaded before app routes
                 // try again next time loadRoutes() is called
                 $this->loaded = false;
                 continue;
             }
             $this->loadedApps[$app] = true;
             $this->useCollection($app);
             $this->requireRouteFile($file, $app);
             $collection = $this->getCollection($app);
             $collection->addPrefix('/apps/' . $app);
             $this->root->addCollection($collection);
         }
     }
     if (!isset($this->loadedApps['core'])) {
         $this->loadedApps['core'] = true;
         $this->useCollection('root');
         require_once __DIR__ . '/../../../settings/routes.php';
         require_once __DIR__ . '/../../../core/routes.php';
     }
     if ($this->loaded) {
         // include ocs routes, must be loaded last for /ocs prefix
         require_once __DIR__ . '/../../../ocs/routes.php';
         $collection = $this->getCollection('ocs');
         $collection->addPrefix('/ocs');
         $this->root->addCollection($collection);
     }
     \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array(__DIR__ . '/../../../Resources/views/Elfinder/helper')));
     $this->extension = new FMElfinderTinymceExtension($this->twig);
     $this->twig->addExtension($this->extension);
     $loader = new YamlFileLoader(new FileLocator(__DIR__ . '/../../../Resources/config'));
     $routes = new RouteCollection();
     $collection = $loader->load('routing.yml');
     $routes->addCollection($collection);
     $this->twig->addExtension(new RoutingExtension(new UrlGenerator($routes, new RequestContext())));
 }
Exemplo n.º 28
0
 public function load($file, $type = null)
 {
     $routes = new RouteCollection();
     foreach ($this->kernel->getBundles() as $bundle) {
         $path = $bundle->getPath() . '/Resources/config/' . $this->routeFileName;
         if (is_file($path)) {
             $routes->addCollection(parent::load($path, $type));
         }
     }
     return $routes;
 }
 public function addCollection(RouteCollection $collection)
 {
     foreach ($collection->all() as $name => $route) {
         $this->add($name, $route);
     }
     // remove all the routes so that we have an empty collection when calling parent method
     // and we are not re-adding the routes again
     $collection->remove(array_keys($collection->all()));
     // call parent method with empty collection to merge the collection's resources
     parent::addCollection($collection);
 }
Exemplo n.º 30
0
 /**
  * Find a list of controllers
  *
  * @param string $base_path Base path to prepend to file paths
  * @return router
  */
 public function find($base_path = '')
 {
     if ($this->route_collection === null || $this->route_collection->count() === 0) {
         $this->route_collection = new RouteCollection();
         foreach ($this->routing_files as $file_path) {
             $loader = new YamlFileLoader(new FileLocator($this->filesystem->realpath($base_path)));
             $this->route_collection->addCollection($loader->load($file_path));
         }
     }
     return $this;
 }