Inheritance: extends Symfony\Component\Routing\Matcher\Dumper\MatcherDumper
 /**
  * @expectedException \LogicException
  */
 public function testDumpWhenSchemeIsUsedWithoutAProperDumper()
 {
     $collection = new RouteCollection();
     $collection->add('secure', new Route('/secure', array(), array('_scheme' => 'https')));
     $dumper = new PhpMatcherDumper($collection, new RequestContext());
     $dumper->dump();
 }
 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')));
     // 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')));
     $dumper = new PhpMatcherDumper($collection);
     $this->assertStringEqualsFile(self::$fixturesPath . '/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');
     $this->assertStringEqualsFile(self::$fixturesPath . '/dumper/url_matcher2.php', $dumper->dump(array('base_class' => 'Symfony\\Tests\\Component\\Routing\\Fixtures\\RedirectableUrlMatcher')), '->dump() dumps basic routes to the correct PHP file.');
 }
Ejemplo n.º 3
0
 private static function createMatcher($sourceFolder, $reader, $context)
 {
     $matcher = null;
     $routeCacheFile = self::$CACHE_FOLDER . "/" . self::ROUTE_CACHE_FILE;
     if (!self::$DEBUG) {
         if (!file_exists($routeCacheFile)) {
             $routeLoader = new RouteAnnotationClassLoader($reader);
             $loader = new AnnotationDirectoryLoader(new FileLocator([$sourceFolder]), $routeLoader);
             $routes = $loader->load($sourceFolder);
             $dumper = new PhpMatcherDumper($routes);
             file_put_contents($routeCacheFile, $dumper->dump(["class" => self::ROUTE_CACHE_CLASS]));
             $matcher = new UrlMatcher($routes, $context);
         } else {
             $routes = (include self::$CACHE_FOLDER . "/" . self::ROUTE_CACHE_FILE);
             $className = self::ROUTE_CACHE_CLASS;
             $matcher = new $className($context);
         }
     } else {
         $routeLoader = new RouteAnnotationClassLoader($reader);
         $loader = new AnnotationDirectoryLoader(new FileLocator([$sourceFolder]), $routeLoader);
         $routes = $loader->load($sourceFolder);
         $matcher = new UrlMatcher($routes, $context);
     }
     return $matcher;
 }
Ejemplo n.º 4
0
    /**
     * @dataProvider getRouteCollections
     */
    public function testDump(RouteCollection $collection, $fixture, $options = array())
    {
        $basePath = __DIR__.'/../../Fixtures/dumper/';

        $dumper = new PhpMatcherDumper($collection);
        $this->assertStringEqualsFile($basePath.$fixture, $dumper->dump($options), '->dump() correctly dumps routes as optimized PHP code.');
    }
/**
* Create a new UrlMatcher class and dump it into the cache file
*
* @param \phpbb\extension\manager $manager Extension manager
* @param string $root_path Root path
* @param string $php_ext PHP file extension
* @return null
*/
function phpbb_create_dumped_url_matcher(\phpbb\extension\manager $manager, $root_path, $php_ext)
{
    $provider = new \phpbb\controller\provider();
    $provider->find_routing_files($manager->get_finder());
    $routes = $provider->find($root_path)->get_routes();
    $dumper = new PhpMatcherDumper($routes);
    $cached_url_matcher_dump = $dumper->dump(array('class' => 'phpbb_url_matcher'));
    file_put_contents($root_path . 'cache/url_matcher.' . $php_ext, $cached_url_matcher_dump);
}
Ejemplo n.º 6
0
 public function testDump()
 {
     $collection = new RouteCollection();
     $collection->add('foo', new Route('/foo/:bar', array('def' => 'test'), array('bar' => 'baz|symfony')));
     $collection->add('bar', new Route('/bar/:foo', array(), array('_method' => 'GET|head')));
     $collection->add('baz', new Route('/test/baz'));
     $dumper = new PhpMatcherDumper($collection);
     $this->assertStringEqualsFile(self::$fixturesPath . '/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');
 }
Ejemplo n.º 7
0
 /**
  * @param ContainerBuilder $container
  * @param array $routes
  * @codeCoverageIgnore
  */
 protected function dumpMatcher(ContainerBuilder $container, array $routes)
 {
     ksort($routes);
     $this->dumpVariableToCache(SerializedRouteCollection::CACHE_FILE, $routes);
     /** @var SerializedRouteCollection $routerCollection */
     $routerCollection = $container->get('Core.RouteCollection');
     $routerFile = sprintf('%scache/router_matcher.php', ROOT);
     $routeDumper = new PhpMatcherDumper($routerCollection);
     $content = $routeDumper->dump();
     file_put_contents($routerFile, $content);
     @chmod($routerFile, 0777);
 }
Ejemplo n.º 8
0
 /**
  * Dump route matcher and generators.
  */
 public function dump()
 {
     $this->createCacheDirectory();
     /*
      * Generate custom UrlMatcher
      */
     $dumper = new PhpMatcherDumper($this->routeCollection);
     $class = $dumper->dump(['class' => $this->matcherClassName]);
     $this->fs->dumpFile($this->cacheDirectory . '/' . $this->matcherClassName . '.php', $class);
     /*
      * Generate custom UrlGenerator
      */
     $dumper = new PhpGeneratorDumper($this->routeCollection);
     $class = $dumper->dump(['class' => $this->generatorClassName]);
     $this->fs->dumpFile($this->cacheDirectory . '/' . $this->generatorClassName . '.php', $class);
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 /**
  *
  */
 public function onKernelRequest()
 {
     $this->stopwatch->start('dumpUrlUtils');
     if (!$this->fs->exists(ROADIZ_ROOT . '/gen-src/Compiled')) {
         $this->fs->mkdir(ROADIZ_ROOT . '/gen-src/Compiled', 0755);
     }
     /*
      * Generate custom UrlMatcher
      */
     $dumper = new PhpMatcherDumper($this->routeCollection);
     $class = $dumper->dump(['class' => 'GlobalUrlMatcher']);
     $this->fs->dumpFile(ROADIZ_ROOT . '/gen-src/Compiled/GlobalUrlMatcher.php', $class);
     /*
      * Generate custom UrlGenerator
      */
     $dumper = new PhpGeneratorDumper($this->routeCollection);
     $class = $dumper->dump(['class' => 'GlobalUrlGenerator']);
     $this->fs->dumpFile(ROADIZ_ROOT . '/gen-src/Compiled/GlobalUrlGenerator.php', $class);
     $this->stopwatch->stop('dumpUrlUtils');
 }
Ejemplo n.º 11
0
 /**
  * @param RouteCollection $routes
  */
 public function __construct(RouteCollection $routes)
 {
     parent::__construct(RouteCollectionUtil::cloneWithoutHidden($routes));
 }
Ejemplo n.º 12
0
 /**
  * Creates a new dumped URL Matcher (dump it if necessary)
  */
 protected function create_dumped_url_matcher()
 {
     try {
         $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_matcher.{$this->php_ext}", defined('DEBUG'));
         if (!$cache->isFresh()) {
             $dumper = new PhpMatcherDumper($this->get_routes());
             $options = array('class' => 'phpbb_url_matcher', 'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher');
             $cache->write($dumper->dump($options), $this->get_routes()->getResources());
         }
         require_once $cache->getPath();
         $this->matcher = new \phpbb_url_matcher($this->context);
     } catch (IOException $e) {
         $this->create_new_url_matcher();
     }
 }