load() public method

Loads a Yaml file.
public load ( string $file ) : RouteCollection
$file string A Yaml file path
return Symfony\Component\Routing\RouteCollection A RouteCollection instance
 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;
 }
示例#2
0
 /**
  * Boots the current kernel.
  *
  * @api
  */
 public function boot()
 {
     if (true === $this->booted) {
         return;
     }
     // Setup Routes
     $this->router = new RouteCollection();
     $locator = new FileLocator([$this->get_root_dir() . '/config/']);
     try {
         $loader = new PhpFileLoader($locator);
         $this->router->addCollection($loader->load('routes.php'));
         $loader = new YamlFileLoader($locator);
         $this->router->addCollection($loader->load('routes.yml'));
     } catch (\InvalidArgumentException $e) {
     }
     // Load configuration
     try {
         $this->config = new Configuration();
         $this->config->add_resource($this->get_root_dir() . '/config/');
         $this->config->add_config($this->config->get("config_" . $this->get_environment()));
     } catch (\Exception $e) {
     }
     // init bundles
     $this->initialize_bundles();
     foreach ($this->get_bundles() as $bundle) {
         $bundle->set_application($this);
         $bundle->boot();
     }
     $this->booted = true;
 }
示例#3
0
 public function createRouteCollection()
 {
     $locator = new FileLocator([__DIR__]);
     $loader = new YamlFileLoader($locator);
     $collection = $loader->load('routing.yml');
     return $collection;
 }
 public function runTest()
 {
     $locator = new FileLocator(array(__DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "config"));
     $loader = new YamlFileLoader($locator);
     $routes = $loader->load("routing.yml");
     $validator = new RouteValidator(new UrlMatcher($routes, new RequestContext("/")));
     $validator->validate();
 }
 /**
  * Get an object instance of UrlGenerator class.
  * 
  * @return UrlGenerator
  */
 public static function getInstance()
 {
     $configDirectory = new YamlFileLoader(new FileLocator(array(__DIR__ . '/../../Resources/config')));
     $captchaRoutes = $configDirectory->load('routing.yml');
     $requestContext = new RequestContext();
     $requestContext->fromRequest(Request::createFromGlobals());
     return new SymfonyUrlGenerator($captchaRoutes, $requestContext);
 }
示例#6
0
 static function configure($app)
 {
     $app["routes"] = $app->extend("routes", function (RouteCollection $routes, Application $app) {
         $loader = new YamlFileLoader(new FileLocator(__DIR__ . "/../config"));
         $collection = $loader->load("routes.yml");
         $routes->addCollection($collection);
         return $routes;
     });
 }
 private function initRoutes()
 {
     $this["routes"] = $this->extend("routes", function (RouteCollection $routes, Application $this) {
         $loader = new YamlFileLoader(new FileLocator($this->base . 'etc'));
         $collection = $loader->load('routes.yml');
         $routes->addCollection($collection);
         return $routes;
     });
 }
示例#8
0
 /**
  * @param ControllerResolver $resolver
  */
 public function __construct($resolver)
 {
     // Load routes list
     $locator = new FileLocator([__DIR__]);
     $loader = new YamlFileLoader($locator);
     $this->routes = $loader->load('routes.yml');
     // Set ControllerResolver
     $this->resolver = $resolver;
 }
示例#9
0
 /**
  * {@inheritdoc}
  */
 public static function getRoutes()
 {
     $locator = new FileLocator([ROADIZ_ROOT . '/src/Roadiz/CMS/Resources']);
     if (file_exists(ROADIZ_ROOT . '/src/Roadiz/CMS/Resources/assetsRoutes.yml')) {
         $loader = new YamlFileLoader($locator);
         return $loader->load('assetsRoutes.yml');
     }
     return null;
 }
 /**
  * {@inheritDoc}
  */
 public function register(Application $app)
 {
     $app->extend('routes', function (RouteCollection $routes, Application $app) {
         $loader = new YamlFileLoader(new FileLocator(JAZZ_CONFIG_DIR));
         $collection = $loader->load('routing.yml');
         $routes->addCollection($collection);
         return $routes;
     });
 }
示例#11
0
 private function configureRoutes()
 {
     $this['routes'] = $this->extend('routes', function (RouteCollection $routes, Application $app) {
         $loader = new YamlFileLoader(new FileLocator($app->getConfigDir()));
         $collection = $loader->load('routes.yml');
         $routes->addCollection($collection);
         return $routes;
     });
 }
示例#12
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;
 }
示例#13
0
 protected function parseYmlFile()
 {
     $finder = new Finder();
     $finder->files()->in(__DIR__ . '/../config/routing');
     $locator = new FileLocator(array(__DIR__ . '/../config/routing'));
     $loader = new YamlFileLoader($locator);
     foreach ($finder as $file) {
         $subCollection = $loader->load($file->getRelativePathname());
         $this->routes->addCollection($subCollection);
     }
 }
示例#14
0
 /**
  * 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;
 }
示例#15
0
文件: Yeast.php 项目: nexhero/muffin
 public static function generateURI($tag, $args = NULL)
 {
     $request = Request::createFromGlobals();
     $locator = new FileLocator(array(__DIR__));
     $loader = new YamlFileLoader($locator);
     $routes = $loader->load('../config/routes.yml');
     $context = new RequestContext($request->getBaseUrl());
     $generator = new UrlGenerator($routes, $context);
     $url = $generator->generate($tag);
     return $url;
 }
示例#16
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;
 }
 /**
  * {@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())));
 }
示例#18
0
 public function clean()
 {
     $locator = new FileLocator($this->app['config_path']);
     $loader = new YamlFileLoader($locator);
     $resources = [];
     $routeCollection = new RouteCollection();
     foreach ($this->finder as $file) {
         $resources[] = new FileResource($file->getRealpath());
         $routeCollection->addCollection($loader->load($file->getRealpath()));
     }
     $this->routesCache->write(\serialize($routeCollection), $resources);
 }
 protected function routing()
 {
     $routesDir = StringCommon::replaceKeyWords($this->_config["router"]["routes_dir"]);
     $routesFile = $this->_config["router"]["routes_file"];
     $loader = new YamlFileLoader(new FileLocator($routesDir));
     $loader->load($routesFile);
     $context = new RequestContext();
     $context->fromRequest(Request::createFromGlobals());
     //$matcher = new UrlMatcher($collection, $context);
     $router = new Router($loader, $routesFile);
     $this->action($router, $context);
 }
示例#20
0
 protected function boot()
 {
     $dispatcher = new EventDispatcher($this->container);
     $resolver = new ControllerResolver($this->container);
     $this->httpKernel = new HttpKernel($dispatcher, $resolver);
     $this->legacyKernel = new LegacyIntranetKernel($dispatcher);
     $locator = new FileLocator(array(__DIR__ . '/config'));
     $loader = new YamlFileLoader($locator);
     $collection = $loader->load('routes.yml');
     $context = new RequestContext();
     $matcher = new UrlMatcher($collection, $context);
     $dispatcher->addSubscriber(new RouterListener($matcher, $context));
 }
 public function register(Container $app)
 {
     $app['routes'] = $app->extend('routes', function (RouteCollection $routes, Application $app) {
         $file_locator = $app['router.path'] ? $app['router.path'] : __DIR__ . '/../config/routes.yml';
         $file_locator = explode(DIRECTORY_SEPARATOR, $file_locator);
         $file_name = end($file_locator);
         unset($file_locator[count($file_locator) - 1]);
         $file_locator = implode(DIRECTORY_SEPARATOR, $file_locator);
         $loader = new YamlFileLoader(new FileLocator($file_locator));
         $collection = $loader->load($file_name);
         $routes->addCollection($collection);
         return $routes;
     });
 }
示例#22
0
 public function testLoadWithResource()
 {
     $loader = new YamlFileLoader(new FileLocator(array(__DIR__ . '/../Fixtures')));
     $routeCollection = $loader->load('validresource.yml');
     $routes = $routeCollection->all();
     $this->assertCount(2, $routes, 'Two routes are loaded');
     $this->assertContainsOnly('Symfony\\Component\\Routing\\Route', $routes);
     foreach ($routes as $route) {
         $this->assertSame('/{foo}/blog/{slug}', $route->getPath());
         $this->assertSame('123', $route->getDefault('foo'));
         $this->assertSame('\\d+', $route->getRequirement('foo'));
         $this->assertSame('bar', $route->getOption('foo'));
         $this->assertSame('', $route->getHost());
     }
 }
示例#23
0
文件: init.php 项目: nexhero/muffin
 public static function start()
 {
     /*
      Loading preconfigured DataBased
     */
     try {
         Muffin\System\DataBase::initDB();
     } catch (Exception $e) {
     }
     /*
      Catching global variables, also we create the response
     */
     $request = Request::createFromGlobals();
     $response = new Response();
     /*
               Loading the routes file and define the routes as the container
               of the routers definitions
               More info: http://symfony.com/doc/current/components/routing/introduction.html#load-routes-fr
               om-a-file
     */
     $resolver = new HttpKernel\Controller\ControllerResolver();
     $locator = new FileLocator(array(__DIR__));
     $loader = new YamlFileLoader($locator);
     $routes = $loader->load('config/routes.yml');
     $context = new RequestContext($request->getMethod());
     try {
         $matcher = new UrlMatcher($routes, $context);
         $request->attributes->add($matcher->match($request->getPathInfo()));
         $controller = $resolver->getController($request);
         $arguments = $resolver->getArguments($request, $controller);
         $response = call_user_func_array($controller, $arguments);
         /*
          If the path doesn't exits
         */
     } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
         $response = new Response('Not Found', 404);
     } catch (Exception $e) {
         $response = new Response('An error occurred' . $e, 500);
     }
     $response->send();
     /*
      IF we created a connection to the DataBase we close it at the end
     */
     try {
         Muffin\System\DataBase::close();
     } catch (Exception $e) {
     }
 }
示例#24
0
 /**
  * Returns the route collection on event call
  *
  * @param Enlight_Event_EventArgs $args
  * @return \Symfony\Component\Routing\RouteCollection
  */
 public function onInitResourceRoutes(Enlight_Event_EventArgs $args)
 {
     $configRoutes = $this->Config()->get('routes');
     if (is_string($configRoutes)) {
         $locator = new FileLocator(array('.', $this->Application()->AppPath()));
         $loader = new YamlFileLoader($locator);
         return $loader->load($configRoutes);
     } elseif ($configRoutes instanceof Enlight_Config) {
         $routes = new RouteCollection();
         /** @var $route Enlight_Config */
         foreach ($configRoutes as $routeKey => $route) {
             $routes->add($route->get('name', $routeKey), new Route($route->get('pattern'), $route->get('defaults', array()), $route->get('requirements', array()), $route->get('options', array())));
         }
         return $routes;
     }
     return null;
 }
示例#25
0
 /**
  * @param $bundlePaths
  * @param $cacheDirPath
  * @param $cacheEnabled
  * @param RouteCollection $routeCollection
  * @return RouteCollection
  */
 public function loadRouting($bundlePaths, $cacheDirPath, $cacheEnabled, RouteCollection $routeCollection)
 {
     $cacheClass = 'CachedRouteCollection';
     $cachePath = $cacheDirPath . '/' . $cacheClass . '.php';
     $cache = new ConfigCache($cachePath, !$cacheEnabled);
     if (!$cache->isFresh()) {
         foreach ($bundlePaths as $path) {
             if (file_exists($path . '/Resources/config/routing.yml')) {
                 $loader = new YamlFileLoader(new FileLocator($path . '/Resources/config'));
                 $routeCollection->addCollection($loader->load('routing.yml'));
             }
         }
         $dumper = new PhpMatcherDumper($routeCollection);
         $cache->write($dumper->dump(['class' => $cacheClass, 'base_class' => 'Reliv\\SymfonizeZF\\RouteBridge\\SymfonizeRouteCollection']));
     }
     require $cachePath;
     $routeCollection = new $cacheClass(new RequestContext('/'));
     return $routeCollection;
 }
示例#26
0
 /**
  * (non-PHPdoc)
  * @see \Silex\ServiceProviderInterface::register()
  * @param Application $app
  */
 public function register(Application $app)
 {
     /* @var $routeFile string */
     $routeFile = $this->routes;
     $app['routes'] = $app->extend('routes', function (RouteCollection $routes) use($routeFile) {
         /* @var $routesPath string */
         $routesPath = dirname($routeFile);
         /* @var $routeFile string */
         $routeFile = basename($routeFile);
         /* @var $locator \Symfony\Component\Config\FileLocator */
         $locator = new FileLocator($routesPath);
         /* @var $loader \Symfony\Component\Routing\Loader\YamlFileLoader */
         $loader = new YamlFileLoader($locator);
         $collection = $loader->load($routeFile);
         /* @var $routes \Symfony\Component\Routing\RouteCollection */
         $routes->addCollection($collection);
         return $routes;
     });
 }
示例#27
0
 public static function getKernel($conf)
 {
     $defaultConf = ['config.path' => null, 'view.path' => null, 'routes.yml' => 'routes.yml', 'services.yml' => 'services.yml'];
     $conf = array_merge($defaultConf, $conf);
     $fileLocator = new FileLocator($conf['config.path']);
     $container = new DependencyInjection\ContainerBuilder();
     $container->registerExtension(new RestExtension());
     $loader = new DependencyInjection\Loader\YamlFileLoader($container, $fileLocator);
     $loader->load($conf['services.yml']);
     foreach ($conf as $key => $value) {
         $container->setParameter($key, $value);
     }
     $routes = new Routing\RouteCollection();
     $loader = new Routing\Loader\YamlFileLoader($fileLocator);
     $routes->addCollection($loader->load($conf['routes.yml']));
     if ($container->hasExtension('restResources')) {
         $resources = $container->getExtensionConfig('restResources');
         if (isset($resources[0])) {
             foreach ($resources[0] as $routeName => $routeDefinition) {
                 $methods = ['getAction' => ['GET', '/{id}'], 'getAllAction' => ['GET', ''], 'saveAction' => ['POST', '/{id}'], 'addAction' => ['POST', ''], 'deleteAction' => ['DELETE', '/{id}']];
                 foreach ($methods as $methodAction => $methodConf) {
                     $routes->add("{$routeName}.{$methodAction}", new Routing\Route($routeDefinition['path'] . $methodConf[1], ['_controller' => $routeDefinition['class'] . '::' . $methodAction], [], [], '', [], [$methodConf[0]]));
                 }
             }
         }
     }
     $dependencyResolver = new Resolver($container);
     $controllerResolver = new ControllerResolver($routes, $dependencyResolver);
     $eventDispatcher = new EventDispatcher();
     $eventDispatcher->addListener(KernelEvent::EVENT_CONTROLLER_SECURITY, function (KernelEvent $event) use($container) {
         $security = $container->getParameter('security');
         $obj = new $security['class']($event->getKernel()->getRequest());
     }, 1);
     $eventDispatcher->addListener(KernelEvent::EVENT_LOGIN, function (KernelEvent $event) use($container) {
         $event->getKernel()->setController(explode('::', $container->getParameter('security')['login'], 2));
     }, 1);
     return new HttpKernel($eventDispatcher, $controllerResolver);
 }
示例#28
0
 /**
  * These routes are used to extend Roadiz back-office.
  *
  * @return RouteCollection
  */
 public static function getBackendRoutes()
 {
     $locator = new FileLocator([static::getResourcesFolder()]);
     if (file_exists(static::getResourcesFolder() . '/backend-routes.yml')) {
         $loader = new YamlFileLoader($locator);
         return $loader->load('backend-routes.yml');
     }
     return null;
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testParseRouteThrowsExceptionWithMissingPattern()
 {
     $loader = new YamlFileLoader(new FileLocator(array(__DIR__ . '/../Fixtures')));
     $loader->load('incomplete.yml');
 }
示例#30
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testLoadThrowsExceptionIfNotAnArray()
 {
     $loader = new YamlFileLoader(new FileLocator(array(__DIR__ . '/../Fixtures')));
     $loader->load('nonvalid.yml');
 }