/** * 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; }
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); }
/** * @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; }
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; }); }
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; }); }
/** * {@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; }
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; }); }
/** * 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; }
/** * {@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; }); }
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; }
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); } }
/** * {@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()))); }
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); }
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 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; }); }
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; }
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()); } }
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) { } }
/** * @param array $config * @param string $name * @param string $path * @todo Find a better solution ($availableKeys is private so no better way to "override" validate for now) */ protected function validate($config, $name, $path) { if (isset($config['i18n'])) { unset($config['i18n']); } parent::validate($config, $name, $path); }
/** * Parses a route and adds it to the RouteCollection. * * @param RouteCollection $collection A RouteCollection instance * @param string $name Route name * @param array $config Route definition * @param string $path Full path of the YAML file being processed */ protected function parseRoute(RouteCollection $collection, $name, array $config, $path) { if (!empty($this->defaults)) { $config['defaults'] = array_merge($config['defaults'], $this->defaults); } parent::parseRoute($collection, $name, $config, $path); }
/** * Initializes yaml loader. * * @param FileLocatorInterface $locator locator * @param RestRouteProcessor $processor route processor * @param boolean $includeFormat whether or not the requested view format must be included in the route path * @param string[] $formats supported view formats * @param string $defaultFormat default view format */ public function __construct(FileLocatorInterface $locator, RestRouteProcessor $processor, $includeFormat = true, array $formats = array(), $defaultFormat = null) { parent::__construct($locator); $this->processor = $processor; $this->includeFormat = $includeFormat; $this->formats = $formats; $this->defaultFormat = $defaultFormat; }
public function __construct(FileLocatorInterface $locator, I18nRouteCollectionBuilder $collectionBuilder = null) { parent::__construct($locator); if ($collectionBuilder === null) { $collectionBuilder = new I18nRouteCollectionBuilder(); } $this->collectionBuilder = $collectionBuilder; }
/** * 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; }
/** * @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; }
/** * (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; }); }
/** * 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; }
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; }