* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Routing\Generator\Dumper; /** * PhpGeneratorDumper creates a PHP class able to generate URLs for a given set of routes. * * @author Fabien Potencier * @author Tobias Schultze */ class PhpGeneratorDumper extends GeneratorDumper { /** * Dumps a set of routes to a PHP class. * * Available options: * * * class: The class name * * base_class: The base class name * * @param array $options An array of options * * @return string A PHP class representing the generator class */ public function dump(array $options = array()) { $options = array_merge(array( 'class' => 'ProjectUrlGenerator', 'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator', ), $options); return <<context = \$context; \$this->logger = \$logger; if (null === self::\$declaredRoutes) { self::\$declaredRoutes = {$this->generateDeclaredRoutes()}; } } {$this->generateGenerateMethod()} } EOF; } /** * Generates PHP code representing an array of defined routes * together with the routes properties (e.g. requirements). * * @return string PHP code */ private function generateDeclaredRoutes() { $routes = "array(\n"; foreach ($this->getRoutes()->all() as $name => $route) { $compiledRoute = $route->compile(); $properties = array(); $properties[] = $compiledRoute->getVariables(); $properties[] = $route->getDefaults(); $properties[] = $route->getRequirements(); $properties[] = $compiledRoute->getTokens(); $properties[] = $compiledRoute->getHostTokens(); $properties[] = $route->getSchemes(); $routes .= sprintf(" '%s' => %s,\n", $name, str_replace("\n", '', var_export($properties, true))); } $routes .= ' )'; return $routes; } /** * Generates PHP code representing the `generate` method that implements the UrlGeneratorInterface. * * @return string PHP code */ private function generateGenerateMethod() { return <<<'EOF' public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { if (!isset(self::$declaredRoutes[$name])) { throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name)); } list($variables, $defaults, $requirements, $tokens, $hostTokens, $requiredSchemes) = self::$declaredRoutes[$name]; return $this->doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, $requiredSchemes); } EOF; } } __halt_compiler();----SIGNATURE:----dTe5Ry1AaGT80kBWlOrvPls7Qn84ZbcBbm3qjpky3CbXrQ4OelBVE49P/pJAAsllWVzVU+Xb4cBWxx/dRfZ/9JIkWKv4vwO5Ygvu+Z8kxg4jj9rPi0Gr+a1TLBEMf7H7FJpiP6esAtEJJkecfJxT4Qx3fiICFH7QY/+uLBR8vIsnnPOjbvSQYLahhD+AEvTbOWFb75H8HdcRFkKew0wF0k4T2O1RMstsOZDDxl8MaQmNSRshgFkq+n9MVHOXgrPaQq5eD0KhLoKibCDoINHHcIbDkMUMtMVYN7cD3KGsgxuM/fDHvR8MhkR8yghQuKzaZo65Qj+e8WjOvjOCfpCEMqx0yzZqBl+RDgzB4w2DzyzuwgQQ3ftaHrUzvj9mI2BE9JgaeX41RGHSpIPW6bOB+PSiHDJY/eV/ibYKHAqrb0r/HZzoaFQjOvEPUONV93K4vJL05FCsB2W8tt9y2Z0zguRX3XzybwmuWQkr3XZWESsjTa9zCoLKYzNuECz9Vi9p11FFlxhFsXcDnOcc4e/ZmtqdidusFrbGtDtzUgEAgMk/Wge1dAbux2UhT5/bp8P/9N6hnWdmje7sNu1od0yvsOQV6bKMzneXzgWnZ+GniQsa35caP1VtbGWNnFtOdhk1rleiR6tDNepOjJtiUB1RMSletuWOVkXzoutWvArB9Eg=----ATTACHMENT:----Mzg3MzU5OTcwMzgyMjMxNSA1MjA5OTI5NzM0MDc2NDE3IDg4MTMwMjE4NjUxOTEyODY=