1 | <?php namespace Arcanedev\Breadcrumbs; |
||
13 | class Breadcrumbs implements BreadcrumbsContract |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Constants |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | const DEFAULT_TEMPLATE = 'bootstrap-3'; |
||
21 | |||
22 | /* ----------------------------------------------------------------- |
||
23 | | Properties |
||
24 | | ----------------------------------------------------------------- |
||
25 | */ |
||
26 | |||
27 | /** |
||
28 | * Default template view. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $template; |
||
33 | |||
34 | /** |
||
35 | * Supported template views. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $supported = [ |
||
40 | 'bootstrap-3' => 'breadcrumbs::bootstrap-3', |
||
41 | ]; |
||
42 | |||
43 | /** @var array */ |
||
44 | protected $callbacks = []; |
||
45 | |||
46 | /* ----------------------------------------------------------------- |
||
47 | | Constructor |
||
48 | | ----------------------------------------------------------------- |
||
49 | */ |
||
50 | |||
51 | /** |
||
52 | * Create a Breadcrumbs instance. |
||
53 | * |
||
54 | * @param array $supported |
||
55 | * @param string|null $template |
||
56 | */ |
||
57 | 20 | public function __construct(array $supported, $template = null) |
|
62 | |||
63 | /* ----------------------------------------------------------------- |
||
64 | | Getters & Setters |
||
65 | | ----------------------------------------------------------------- |
||
66 | */ |
||
67 | |||
68 | /** |
||
69 | * Set the supported template. |
||
70 | * |
||
71 | * @param array $supported |
||
72 | * |
||
73 | * @return self |
||
74 | */ |
||
75 | 20 | public function setSupported(array $supported) |
|
81 | |||
82 | /** |
||
83 | * Set default template view. |
||
84 | * |
||
85 | * @param string $template |
||
86 | * |
||
87 | * @return self |
||
88 | */ |
||
89 | 20 | public function setTemplate($template) |
|
97 | |||
98 | /** |
||
99 | * Get the template view. |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | 6 | private function getView() |
|
107 | |||
108 | /* ----------------------------------------------------------------- |
||
109 | | Main Methods |
||
110 | | ----------------------------------------------------------------- |
||
111 | */ |
||
112 | |||
113 | /** |
||
114 | * Register a breadcrumb domain. |
||
115 | * |
||
116 | * @param string $name |
||
117 | * @param \Closure $callback |
||
118 | * |
||
119 | * @return self |
||
120 | */ |
||
121 | 20 | public function register($name, Closure $callback) |
|
129 | |||
130 | /** |
||
131 | * Render breadcrumbs items. |
||
132 | * |
||
133 | * @param string|null $name |
||
134 | * @param array $params |
||
135 | * |
||
136 | * @return \Illuminate\Support\HtmlString |
||
137 | */ |
||
138 | 6 | public function render($name = null, ...$params) |
|
146 | |||
147 | /** |
||
148 | * Generate the breadcrumbs. |
||
149 | * |
||
150 | * @param string $name |
||
151 | * @param array $params |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | 10 | public function generate($name, ...$params) |
|
161 | |||
162 | /* ----------------------------------------------------------------- |
||
163 | | Check Methods |
||
164 | | ----------------------------------------------------------------- |
||
165 | */ |
||
166 | |||
167 | /** |
||
168 | * Check Template. |
||
169 | * |
||
170 | * @param string $template |
||
171 | * |
||
172 | * @throws Exceptions\InvalidTemplateException |
||
173 | * @throws Exceptions\InvalidTypeException |
||
174 | */ |
||
175 | 20 | private function checkTemplate($template) |
|
192 | |||
193 | /** |
||
194 | * Check Name. |
||
195 | * |
||
196 | * @param string $name |
||
197 | * |
||
198 | * @throws Exceptions\InvalidTypeException |
||
199 | */ |
||
200 | 20 | private function checkCallbackName(&$name) |
|
212 | } |
||
213 |