1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2014 Krzysztof Magosa |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
* |
10
|
|
|
* Unless required by applicable law or agreed to in writing, software |
11
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
* See the License for the specific language governing permissions and |
14
|
|
|
* limitations under the License. |
15
|
|
|
*/ |
16
|
|
|
namespace KM\Saffron\UrlBuilder; |
17
|
|
|
|
18
|
|
|
use KM\Saffron\RoutesCollection; |
19
|
|
|
|
20
|
|
|
class Generator extends \KM\Saffron\Generator |
21
|
|
|
{ |
22
|
|
|
protected $collection; |
23
|
|
|
|
24
|
|
|
public function __construct(RoutesCollection $collection) |
25
|
|
|
{ |
26
|
|
|
$this->collection = $collection; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function generateCache() |
30
|
|
|
{ |
31
|
|
|
$result = []; |
32
|
|
|
foreach ($this->collection as $route) { |
33
|
|
|
$result[$route->getName()] = [ |
34
|
|
|
'uri' => $route->getUri(), |
35
|
|
|
'domain' => $route->getDomain(), |
36
|
|
|
'defaults' => $route->getDefaults(), |
37
|
|
|
'https' => $route->getHttps(), |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $result; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function generate($className) |
45
|
|
|
{ |
46
|
|
|
$routes = var_export($this->generateCache(), true); |
47
|
|
|
|
48
|
|
|
return <<<EOB |
49
|
|
|
<?php |
50
|
|
|
use KM\Saffron\UrlBuilder\Base; |
51
|
|
|
|
52
|
|
|
class $className extends Base |
53
|
|
|
{ |
54
|
|
|
protected \$routes = $routes; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
EOB; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|