Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
PhpGeneratorDumper.php
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 * @api
021 */
022 class PhpGeneratorDumper extends GeneratorDumper
023 {
024 /**
025 * Dumps a set of routes to a PHP class.
026 *
027 * Available options:
028 *
029 * * class: The class name
030 * * base_class: The base class name
031 *
032 * @param array $options An array of options
033 *
034 * @return string A PHP class representing the generator class
035 *
036 * @api
037 */
038 public function dump(array $options = array())
039 {
040 $options = array_merge(array(
041 'class' => 'ProjectUrlGenerator',
042 'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
043 ), $options);
044
045 return <<<EOF
046 <?php
047
048 use Symfony\Component\Routing\RequestContext;
049 use Symfony\Component\Routing\Exception\RouteNotFoundException;
050 use Psr\Log\LoggerInterface;
051
052 /**
053 * {$options['class']}
054 *
055 * This class has been auto-generated
056 * by the Symfony Routing Component.
057 */
058 class {$options['class']} extends {$options['base_class']}
059 {
060 private static \$declaredRoutes = {$this->generateDeclaredRoutes()};
061
062 /**
063 * Constructor.
064 */
065 public function __construct(RequestContext \$context, LoggerInterface \$logger = null)
066 {
067 \$this->context = \$context;
068 \$this->logger = \$logger;
069 }
070
071 {$this->generateGenerateMethod()}
072 }
073
074 EOF;
075
076 }
077
078 /**
079 * Generates PHP code representing an array of defined routes
080 * together with the routes properties (e.g. requirements).
081 *
082 * @return string PHP code
083 */
084 private function generateDeclaredRoutes()
085 {
086 $routes = "array(\n";
087 foreach ($this->getRoutes()->all() as $name => $route) {
088 $compiledRoute = $route->compile();
089
090 $properties = array();
091 $properties[] = $compiledRoute->getVariables();
092 $properties[] = $route->getDefaults();
093 $properties[] = $route->getRequirements();
094 $properties[] = $compiledRoute->getTokens();
095 $properties[] = $compiledRoute->getHostTokens();
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) = self::\$declaredRoutes[\$name];
119
120 return \$this->doGenerate(\$variables, \$defaults, \$requirements, \$tokens, \$parameters, \$name, \$referenceType, \$hostTokens);
121 }
122 EOF;
123
124 }
125 }
126