Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

PhpGeneratorDumper.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 3.55 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\Routing\Generator\Dumper;
013   
014  /**
015   * PhpGeneratorDumper creates a PHP class able to generate URLs for a given set of routes.
016   *
017   * @author Fabien Potencier <fabien@symfony.com>
018   * @author Tobias Schultze <http://tobion.de>
019   */
020  class PhpGeneratorDumper extends GeneratorDumper
021  {
022      /**
023       * Dumps a set of routes to a PHP class.
024       *
025       * Available options:
026       *
027       *  * class:      The class name
028       *  * base_class: The base class name
029       *
030       * @param array $options An array of options
031       *
032       * @return string A PHP class representing the generator class
033       */
034      public function dump(array $options = array())
035      {
036          $options = array_merge(array(
037              'class' => 'ProjectUrlGenerator',
038              'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
039          ), $options);
040   
041          return <<<EOF
042  <?php
043   
044  use Symfony\Component\Routing\RequestContext;
045  use Symfony\Component\Routing\Exception\RouteNotFoundException;
046  use Psr\Log\LoggerInterface;
047   
048  /**
049   * {$options['class']}
050   *
051   * This class has been auto-generated
052   * by the Symfony Routing Component.
053   */
054  class {$options['class']} extends {$options['base_class']}
055  {
056      private static \$declaredRoutes;
057   
058      /**
059       * Constructor.
060       */
061      public function __construct(RequestContext \$context, LoggerInterface \$logger = null)
062      {
063          \$this->context = \$context;
064          \$this->logger = \$logger;
065          if (null === self::\$declaredRoutes) {
066              self::\$declaredRoutes = {$this->generateDeclaredRoutes()};
067          }
068      }
069   
070  {$this->generateGenerateMethod()}
071  }
072   
073  EOF;
074   
075      }
076   
077      /**
078       * Generates PHP code representing an array of defined routes
079       * together with the routes properties (e.g. requirements).
080       *
081       * @return string PHP code
082       */
083      private function generateDeclaredRoutes()
084      {
085          $routes = "array(\n";
086          foreach ($this->getRoutes()->all() as $name => $route) {
087              $compiledRoute = $route->compile();
088   
089              $properties = array();
090              $properties[] = $compiledRoute->getVariables();
091              $properties[] = $route->getDefaults();
092              $properties[] = $route->getRequirements();
093              $properties[] = $compiledRoute->getTokens();
094              $properties[] = $compiledRoute->getHostTokens();
095              $properties[] = $route->getSchemes();
096   
097              $routes .= sprintf("        '%s' => %s,\n", $name, str_replace("\n", '', var_export($properties, true)));
098          }
099          $routes .= '    )';
100   
101          return $routes;
102      }
103   
104      /**
105       * Generates PHP code representing the `generate` method that implements the UrlGeneratorInterface.
106       *
107       * @return string PHP code
108       */
109      private function generateGenerateMethod()
110      {
111          return <<<'EOF'
112      public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
113      {
114          if (!isset(self::$declaredRoutes[$name])) {
115              throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
116          }
117   
118          list($variables, $defaults, $requirements, $tokens, $hostTokens, $requiredSchemes) = self::$declaredRoutes[$name];
119   
120          return $this->doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, $requiredSchemes);
121      }
122  EOF;
123   
124      }
125  }
126