* * 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:----DKKowMThybLTG3oG8vxGpa91PQlqS9iqYR6A04o8tmdy0cO8T/Z7UntRO6Hggxo1lTAVmuNEuYaqcm+vrfIJ0R7JAV4tQOHUxlLnCNooCBO2Y6f9v65tf3dzYt6Uu1NqzIkiwz1yGM9dFCVCqbRzGkuPtFzJcjSELNENsiYTRp3y836o/IxdiXeoJgldTqIIzYJpb0U0e7baFE1Wejnq1GUsTXRUQRAIbfAulo9vCI1Y591bY/fL/35MHXu7Y47UOl9SGvdb4E0gkvBR8XR+hAS/fNOkLvAKCJrFxKF7OHyf5AB81h3u70/RTea0eKhRDINGFpbP7zVpgijosz4OMNOR1SLFV5TXOaJh2rflfne/BnTUF6Eje2mla0yDK7+5/l3Pr4vkdn0PTCYhviw87hmHL7n/v8E3GENq9QaI6SJPrRgc2L39CsyTi8dw0HOf2yE+4JLA8xfe3aAUI3MjZzIvIUhsJAtAPaMeCOGGz3zKocEtcpUUeUwEbwGHLBsRBONe+jey2WfVtNN5gVe06eaOJRwbaqRNM1mEGXQd5TkeqNibyYgP5Zo0zUUH/BNi9t6EZe3JEl8sb8HAB9/WkX5dgrijk3t0hsGzPPzCJscC8mTBDKHMHxltJruEju8fpDUySFAn1K4WIb15B5T3pL1LH6RbTsUyhKmyTauWYqo=----ATTACHMENT:----NzUxMjE2NjU0MDM2NTk0NSA1NzUzODgwOTM0NTM4MDY4IDc3OTAwMjg4ODA1MzEzNDE=