|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Pagerfanta package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Pablo Díez <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Pagerfanta\View\Template; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Pablo Díez <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class Template implements TemplateInterface |
|
18
|
|
|
{ |
|
19
|
|
|
protected static $defaultOptions = array(); |
|
20
|
|
|
|
|
21
|
|
|
private $routeGenerator; |
|
22
|
|
|
private $options; |
|
23
|
|
|
|
|
24
|
52 |
|
public function __construct() |
|
25
|
|
|
{ |
|
26
|
52 |
|
$this->initializeOptions(); |
|
27
|
52 |
|
} |
|
28
|
|
|
|
|
29
|
52 |
|
public function setRouteGenerator($routeGenerator) |
|
30
|
|
|
{ |
|
31
|
52 |
|
$this->routeGenerator = $routeGenerator; |
|
32
|
52 |
|
} |
|
33
|
|
|
|
|
34
|
52 |
|
public function setOptions(array $options) |
|
35
|
|
|
{ |
|
36
|
52 |
|
$this->options = array_merge($this->options, $options); |
|
37
|
52 |
|
} |
|
38
|
|
|
|
|
39
|
52 |
|
private function initializeOptions() |
|
40
|
|
|
{ |
|
41
|
52 |
|
$this->options = static::$defaultOptions; |
|
42
|
52 |
|
} |
|
43
|
|
|
|
|
44
|
52 |
|
protected function generateRoute($page) |
|
45
|
|
|
{ |
|
46
|
52 |
|
return call_user_func($this->getRouteGenerator(), $page); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
52 |
|
private function getRouteGenerator() |
|
50
|
|
|
{ |
|
51
|
52 |
|
if (!$this->routeGenerator) { |
|
52
|
|
|
throw new \RuntimeException('There is no route generator.'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
52 |
|
return $this->routeGenerator; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
52 |
|
protected function option($name) |
|
59
|
|
|
{ |
|
60
|
52 |
|
if (!isset($this->options[$name])) { |
|
61
|
|
|
throw new \InvalidArgumentException(sprintf('The option "%s" does not exist.', $name)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
52 |
|
return $this->options[$name]; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|