@@ -43,17 +43,45 @@ public function dump(array $options = array())
43
43
'base_class ' => 'Symfony \\Component \\Routing \\Generator \\UrlGenerator ' ,
44
44
), $ options );
45
45
46
- return
47
- $ this ->startClass ($ options ['class ' ], $ options ['base_class ' ]).
48
- $ this ->addConstructor ().
49
- $ this ->addGenerator ().
50
- $ this ->endClass ()
51
- ;
46
+ $ declaredRouteNames = "array( \n" ;
47
+ foreach ($ this ->getRoutes ()->all () as $ name => $ route ) {
48
+ $ declaredRouteNames .= " ' $ name' => true, \n" ;
49
+ }
50
+ $ declaredRouteNames .= ' ); ' ;
51
+
52
+ return <<<EOF
53
+ <?php
54
+
55
+ use Symfony\Component\Routing\RequestContext;
56
+ use Symfony\Component\Routing\Exception\RouteNotFoundException;
57
+
58
+ /**
59
+ * {$ options ['class ' ]}
60
+ *
61
+ * This class has been auto-generated
62
+ * by the Symfony Routing Component.
63
+ */
64
+ class {$ options ['class ' ]} extends {$ options ['base_class ' ]}
65
+ {
66
+ static private \$declaredRouteNames = $ declaredRouteNames
67
+
68
+ /**
69
+ * Constructor.
70
+ */
71
+ public function __construct(RequestContext \$context)
72
+ {
73
+ \$this->context = \$context;
74
+ }
75
+
76
+ {$ this ->addGenerator ()}
77
+ }
78
+
79
+ EOF ;
52
80
}
53
81
54
82
private function addGenerator ()
55
83
{
56
- $ methods = array () ;
84
+ $ methods = '' ;
57
85
foreach ($ this ->getRoutes ()->all () as $ name => $ route ) {
58
86
$ compiledRoute = $ route ->compile ();
59
87
@@ -64,20 +92,16 @@ private function addGenerator()
64
92
65
93
$ escapedName = str_replace ('. ' , '__ ' , $ name );
66
94
67
- $ methods[] = <<<EOF
95
+ $ methods . = <<<EOF
68
96
private function get {$ escapedName }RouteInfo()
69
97
{
70
98
return array( $ variables, $ defaults, $ requirements, $ tokens);
71
99
}
72
100
73
- EOF
74
- ;
101
+ EOF ;
75
102
}
76
103
77
- $ methods = implode ("\n" , $ methods );
78
-
79
104
return <<<EOF
80
-
81
105
public function generate( \$name, \$parameters = array(), \$absolute = false)
82
106
{
83
107
if (!isset(self:: \$declaredRouteNames[ \$name])) {
@@ -92,59 +116,6 @@ public function generate(\$name, \$parameters = array(), \$absolute = false)
92
116
}
93
117
94
118
$ methods
95
- EOF ;
96
- }
97
-
98
- private function startClass ($ class , $ baseClass )
99
- {
100
- $ routes = array ();
101
- foreach ($ this ->getRoutes ()->all () as $ name => $ route ) {
102
- $ routes [] = " ' $ name' => true, " ;
103
- }
104
- $ routes = implode ("\n" , $ routes );
105
-
106
- return <<<EOF
107
- <?php
108
-
109
- use Symfony\Component\Routing\RequestContext;
110
- use Symfony\Component\Routing\Exception\RouteNotFoundException;
111
-
112
-
113
- /**
114
- * $ class
115
- *
116
- * This class has been auto-generated
117
- * by the Symfony Routing Component.
118
- */
119
- class $ class extends $ baseClass
120
- {
121
- static private \$declaredRouteNames = array(
122
- $ routes
123
- );
124
-
125
-
126
- EOF ;
127
- }
128
-
129
- private function addConstructor ()
130
- {
131
- return <<<EOF
132
- /**
133
- * Constructor.
134
- */
135
- public function __construct(RequestContext \$context)
136
- {
137
- \$this->context = \$context;
138
- }
139
-
140
- EOF ;
141
- }
142
-
143
- private function endClass ()
144
- {
145
- return <<<EOF
146
- }
147
-
148
119
EOF ;
149
120
}
150
121
}
0 commit comments