dump() public method

Available options: * class: The class name * base_class: The base class name
public dump ( array $options = [] ) : string
$options array An array of options
return string A PHP class representing the generator class
 public function testDumpWithSchemeRequirement()
 {
     $this->routeCollection->add('Test1', new Route('/testing', array(), array(), array(), '', array('ftp', 'https')));
     $this->routeCollection->add('Test2', new Route('/testing_bc', array(), array('_scheme' => 'https')));
     // BC
     file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'SchemeUrlGenerator')));
     include $this->testTmpFilepath;
     $projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php'));
     $absoluteUrl = $projectUrlGenerator->generate('Test1', array(), true);
     $absoluteUrlBC = $projectUrlGenerator->generate('Test2', array(), true);
     $relativeUrl = $projectUrlGenerator->generate('Test1', array(), false);
     $relativeUrlBC = $projectUrlGenerator->generate('Test2', array(), false);
     $this->assertEquals($absoluteUrl, 'ftp://localhost/app.php/testing');
     $this->assertEquals($absoluteUrlBC, 'https://localhost/app.php/testing_bc');
     $this->assertEquals($relativeUrl, 'ftp://localhost/app.php/testing');
     $this->assertEquals($relativeUrlBC, 'https://localhost/app.php/testing_bc');
     $projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php', 'GET', 'localhost', 'https'));
     $absoluteUrl = $projectUrlGenerator->generate('Test1', array(), true);
     $absoluteUrlBC = $projectUrlGenerator->generate('Test2', array(), true);
     $relativeUrl = $projectUrlGenerator->generate('Test1', array(), false);
     $relativeUrlBC = $projectUrlGenerator->generate('Test2', array(), false);
     $this->assertEquals($absoluteUrl, 'https://localhost/app.php/testing');
     $this->assertEquals($absoluteUrlBC, 'https://localhost/app.php/testing_bc');
     $this->assertEquals($relativeUrl, '/app.php/testing');
     $this->assertEquals($relativeUrlBC, '/app.php/testing_bc');
 }
Exemplo n.º 2
0
 public function testDumpForRouteWithDefaults()
 {
     $this->routeCollection->add('Test', new Route('/testing/{foo}', array('foo' => 'bar')));
     file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'DefaultRoutesUrlGenerator')));
     include $this->testTmpFilepath;
     $projectUrlGenerator = new \DefaultRoutesUrlGenerator(new RequestContext());
     $url = $projectUrlGenerator->generate('Test', array());
     $this->assertEquals($url, '/testing');
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 public function testDumpWithSchemeRequirement()
 {
     $this->routeCollection->add('Test1', new Route('/testing', array(), array(), array(), '', array('ftp', 'https')));
     file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'SchemeUrlGenerator')));
     include $this->testTmpFilepath;
     $projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php'));
     $absoluteUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_URL);
     $relativeUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
     $this->assertEquals('ftp://localhost/app.php/testing', $absoluteUrl);
     $this->assertEquals('ftp://localhost/app.php/testing', $relativeUrl);
     $projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php', 'GET', 'localhost', 'https'));
     $absoluteUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_URL);
     $relativeUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
     $this->assertEquals('https://localhost/app.php/testing', $absoluteUrl);
     $this->assertEquals('/app.php/testing', $relativeUrl);
 }
 /**
  *
  */
 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');
 }
Exemplo n.º 6
0
 /**
  * Creates a new dumped URL Generator (dump it if necessary)
  */
 protected function create_dumped_url_generator()
 {
     try {
         $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_generator.{$this->php_ext}", defined('DEBUG'));
         if (!$cache->isFresh()) {
             $dumper = new PhpGeneratorDumper($this->get_routes());
             $options = array('class' => 'phpbb_url_generator', 'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator');
             $cache->write($dumper->dump($options), $this->get_routes()->getResources());
         }
         require_once $cache->getPath();
         $this->generator = new \phpbb_url_generator($this->context);
     } catch (IOException $e) {
         $this->create_new_url_generator();
     }
 }