1 | <?php namespace Arcanedev\Breadcrumbs; |
||
12 | class Breadcrumbs implements BreadcrumbsContract |
||
13 | { |
||
14 | /* ------------------------------------------------------------------------------------------------ |
||
15 | | Constants |
||
16 | | ------------------------------------------------------------------------------------------------ |
||
17 | */ |
||
18 | const DEFAULT_TEMPLATE = 'bootstrap-3'; |
||
19 | |||
20 | /* ------------------------------------------------------------------------------------------------ |
||
21 | | Properties |
||
22 | | ------------------------------------------------------------------------------------------------ |
||
23 | */ |
||
24 | /** |
||
25 | * Default template view. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | private $template; |
||
30 | |||
31 | /** |
||
32 | * Supported template views. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $supported = [ |
||
37 | 'bootstrap-3' => 'breadcrumbs::bootstrap-3', |
||
38 | ]; |
||
39 | |||
40 | /** @var array */ |
||
41 | protected $callbacks = []; |
||
42 | |||
43 | /* ------------------------------------------------------------------------------------------------ |
||
44 | | Constructor |
||
45 | | ------------------------------------------------------------------------------------------------ |
||
46 | */ |
||
47 | /** |
||
48 | * Create a Breadcrumbs instance. |
||
49 | * |
||
50 | * @param array $supported |
||
51 | * @param string|null $template |
||
52 | */ |
||
53 | 108 | public function __construct(array $supported, $template = null) |
|
58 | |||
59 | /* ------------------------------------------------------------------------------------------------ |
||
60 | | Getters & Setters |
||
61 | | ------------------------------------------------------------------------------------------------ |
||
62 | */ |
||
63 | /** |
||
64 | * Set the supported template. |
||
65 | * |
||
66 | * @param array $supported |
||
67 | * |
||
68 | * @return self |
||
69 | */ |
||
70 | 108 | public function setSupported(array $supported) |
|
76 | |||
77 | /** |
||
78 | * Set default template view. |
||
79 | * |
||
80 | * @param string $template |
||
81 | * |
||
82 | * @return self |
||
83 | */ |
||
84 | 108 | public function setTemplate($template) |
|
92 | |||
93 | /** |
||
94 | * Get the template view. |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | 36 | private function getView() |
|
102 | |||
103 | /* ------------------------------------------------------------------------------------------------ |
||
104 | | Main functions |
||
105 | | ------------------------------------------------------------------------------------------------ |
||
106 | */ |
||
107 | /** |
||
108 | * Register a breadcrumb domain. |
||
109 | * |
||
110 | * @param string $name |
||
111 | * @param \Closure $callback |
||
112 | * |
||
113 | * @return self |
||
114 | */ |
||
115 | 108 | public function register($name, Closure $callback) |
|
123 | |||
124 | /** |
||
125 | * Render breadcrumbs items. |
||
126 | * |
||
127 | * @param string|null $name |
||
128 | * |
||
129 | * @return string |
||
130 | */ |
||
131 | 36 | public function render($name = null) |
|
139 | |||
140 | /** |
||
141 | * Generate the breadcrumbs. |
||
142 | * |
||
143 | * @param string $name |
||
144 | * |
||
145 | * @return array |
||
146 | */ |
||
147 | 12 | public function generate($name) |
|
153 | |||
154 | /** |
||
155 | * Generate array. |
||
156 | * |
||
157 | * @param string $name |
||
158 | * @param array $args |
||
159 | * |
||
160 | * @return array |
||
161 | */ |
||
162 | 48 | private function generateArray($name, array $args = []) |
|
168 | |||
169 | /* ------------------------------------------------------------------------------------------------ |
||
170 | | Check functions |
||
171 | | ------------------------------------------------------------------------------------------------ |
||
172 | */ |
||
173 | /** |
||
174 | * Check Template. |
||
175 | * |
||
176 | * @param string $template |
||
177 | * |
||
178 | * @throws Exceptions\InvalidTemplateException |
||
179 | * @throws Exceptions\InvalidTypeException |
||
180 | */ |
||
181 | 108 | private function checkTemplate($template) |
|
198 | |||
199 | /** |
||
200 | * Check Name. |
||
201 | * |
||
202 | * @param string $name |
||
203 | * |
||
204 | * @throws Exceptions\InvalidTypeException |
||
205 | */ |
||
206 | 108 | private function checkCallbackName(&$name) |
|
218 | } |
||
219 |