|
1
|
|
|
<?php |
|
2
|
|
|
namespace keeko\core\routing; |
|
3
|
|
|
|
|
4
|
|
|
use Symfony\Component\Routing\Route; |
|
5
|
|
|
use Symfony\Component\Routing\RouteCollection; |
|
6
|
|
|
|
|
7
|
|
|
class PageRouter extends AbstractRouter implements RouterInterface { |
|
8
|
|
|
|
|
9
|
|
|
/* |
|
10
|
|
|
* (non-PHPdoc) @see \keeko\core\routing\AbstractRouter::__construct() |
|
11
|
|
|
*/ |
|
12
|
|
|
public function __construct(array $options) { |
|
13
|
|
|
// options |
|
14
|
|
|
parent::__construct($options); |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
// routes |
|
17
|
|
|
$routes = new RouteCollection(); |
|
18
|
|
|
$routes->add('slug', new Route('/{slug}')); |
|
19
|
|
|
$routes->add('params', new Route(sprintf('/{slug}%s{params}', $this->options['param-separator']))); |
|
20
|
|
|
|
|
21
|
|
|
$this->init($routes); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/* |
|
26
|
|
|
* (non-PHPdoc) @see \keeko\core\routing\RouteMatcherInterface::match() |
|
27
|
|
|
*/ |
|
28
|
|
View Code Duplication |
public function match($destination) { |
|
|
|
|
|
|
29
|
|
|
if ($destination == '') { |
|
30
|
|
|
$destination = '/'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$data = $this->matcher->match($destination); |
|
34
|
|
|
|
|
35
|
|
|
// find page for matched slug |
|
36
|
|
|
if (array_key_exists('slug', $data)) { |
|
|
|
|
|
|
37
|
|
|
// $data['page'] = PageQuery::create() |
|
|
|
|
|
|
38
|
|
|
// ->filterByApplication($this->options['application']) |
|
39
|
|
|
// ->useRouteQuery() |
|
40
|
|
|
// ->filterBySlug($data['slug']) |
|
41
|
|
|
// ->endUse() |
|
42
|
|
|
// ->find() |
|
43
|
|
|
// ; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// unserialize params |
|
47
|
|
|
if (array_key_exists('params', $data)) { |
|
48
|
|
|
$data['params'] = $this->unserializeParams($data['params']); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $data; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/* |
|
55
|
|
|
* @TODO: More data params (e.g. page) (non-PHPdoc) @see \keeko\core\routing\RouteGeneratorInterface::match() |
|
56
|
|
|
*/ |
|
57
|
|
|
public function generate($data) { |
|
58
|
|
|
|
|
59
|
|
|
// params route |
|
60
|
|
View Code Duplication |
if (array_key_exists('params', $data)) { |
|
|
|
|
|
|
61
|
|
|
$data['params'] = $this->serializeParams($data['params']); |
|
62
|
|
|
return $this->generator->generate('params', $data); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// slug route |
|
66
|
|
|
return $this->generator->generate('slug', $data); |
|
67
|
|
|
} |
|
68
|
|
|
} |
This check looks for function calls that miss required arguments.