1 | <?php |
||
15 | class Builder implements BuilderContract |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Properties |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | /** @var array */ |
||
23 | protected $callbacks = []; |
||
24 | |||
25 | /** |
||
26 | * Breadcrumbs collection. |
||
27 | * |
||
28 | * @var \Arcanedev\Breadcrumbs\Entities\BreadcrumbCollection |
||
29 | */ |
||
30 | protected $breadcrumbs; |
||
31 | |||
32 | /* ----------------------------------------------------------------- |
||
33 | | Constructor |
||
34 | | ----------------------------------------------------------------- |
||
35 | */ |
||
36 | |||
37 | /** |
||
38 | * Create the builder instance. |
||
39 | * |
||
40 | * @param array $callbacks |
||
41 | */ |
||
42 | 48 | public function __construct(array $callbacks = []) |
|
47 | |||
48 | /* ----------------------------------------------------------------- |
||
49 | | Getters & Setters |
||
50 | | ----------------------------------------------------------------- |
||
51 | */ |
||
52 | |||
53 | /** |
||
54 | * Get breadcrumbs collection. |
||
55 | * |
||
56 | * @return \Arcanedev\Breadcrumbs\Entities\BreadcrumbCollection |
||
57 | */ |
||
58 | 6 | public function get(): BreadcrumbCollection |
|
62 | |||
63 | /** |
||
64 | * Get callbacks. |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | 6 | public function getCallbacks(): array |
|
72 | |||
73 | /** |
||
74 | * Set callbacks. |
||
75 | * |
||
76 | * @param array $callbacks |
||
77 | * |
||
78 | * @return $this |
||
79 | */ |
||
80 | 48 | private function setCallbacks(array $callbacks) |
|
86 | |||
87 | /* ----------------------------------------------------------------- |
||
88 | | Main Methods |
||
89 | | ----------------------------------------------------------------- |
||
90 | */ |
||
91 | |||
92 | /** |
||
93 | * Call breadcrumb. |
||
94 | * |
||
95 | * @param string $name |
||
96 | * @param array $params |
||
97 | * |
||
98 | * @return $this |
||
99 | */ |
||
100 | 42 | public function call($name, array $params = []) |
|
109 | |||
110 | /** |
||
111 | * Call parent breadcrumb. |
||
112 | * |
||
113 | * @param string $name |
||
114 | */ |
||
115 | 12 | public function parent($name): void |
|
119 | |||
120 | /** |
||
121 | * Push a breadcrumb. |
||
122 | * |
||
123 | * @param string $title |
||
124 | * @param string|null $url |
||
125 | * @param array $data |
||
126 | * |
||
127 | * @return $this |
||
128 | */ |
||
129 | 30 | public function push($title, $url = null, array $data = []) |
|
135 | |||
136 | /** |
||
137 | * Get the breadcrumbs items as a plain array. |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | 30 | public function toArray(): array |
|
145 | |||
146 | /* ----------------------------------------------------------------- |
||
147 | | Check Methods |
||
148 | | ----------------------------------------------------------------- |
||
149 | */ |
||
150 | |||
151 | /** |
||
152 | * Check Name. |
||
153 | * |
||
154 | * @param string $name |
||
155 | * |
||
156 | * @throws \Arcanedev\Breadcrumbs\Exceptions\InvalidTypeException |
||
157 | * @throws \Arcanedev\Breadcrumbs\Exceptions\InvalidCallbackNameException |
||
158 | */ |
||
159 | 42 | private function checkName($name): void |
|
173 | } |
||
174 |