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
|
42 |
|
public function __construct() |
25
|
|
|
{ |
26
|
42 |
|
$this->initializeOptions(); |
27
|
42 |
|
} |
28
|
|
|
|
29
|
42 |
|
public function setRouteGenerator($routeGenerator) |
30
|
|
|
{ |
31
|
42 |
|
$this->routeGenerator = $routeGenerator; |
32
|
42 |
|
} |
33
|
|
|
|
34
|
42 |
|
public function setOptions(array $options) |
35
|
|
|
{ |
36
|
42 |
|
$this->options = array_merge($this->options, $options); |
37
|
42 |
|
} |
38
|
|
|
|
39
|
|
|
public function getOptions() |
40
|
|
|
{ |
41
|
|
|
return $this->options; |
42
|
|
|
} |
43
|
|
|
|
44
|
42 |
|
private function initializeOptions() |
45
|
|
|
{ |
46
|
42 |
|
$this->options = static::$defaultOptions; |
47
|
42 |
|
} |
48
|
|
|
|
49
|
42 |
|
protected function generateRoute($page) |
50
|
|
|
{ |
51
|
42 |
|
return call_user_func($this->getRouteGenerator(), $page); |
52
|
|
|
} |
53
|
|
|
|
54
|
42 |
|
private function getRouteGenerator() |
55
|
|
|
{ |
56
|
42 |
|
if (!$this->routeGenerator) { |
57
|
|
|
throw new \RuntimeException('There is no route generator.'); |
58
|
|
|
} |
59
|
|
|
|
60
|
42 |
|
return $this->routeGenerator; |
61
|
|
|
} |
62
|
|
|
|
63
|
42 |
|
protected function option($name) |
64
|
|
|
{ |
65
|
42 |
|
if (!isset($this->options[$name])) { |
66
|
|
|
throw new \InvalidArgumentException(sprintf('The option "%s" does not exist.', $name)); |
67
|
|
|
} |
68
|
|
|
|
69
|
42 |
|
return $this->options[$name]; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|