1 | <?php namespace Arcanedev\LaravelSitemap\Entities; |
||
13 | class Sitemap implements SitemapContract |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Properties |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | /** @var string|null */ |
||
21 | protected $path; |
||
22 | |||
23 | /** @var \Illuminate\Support\Collection */ |
||
24 | protected $urls; |
||
25 | |||
26 | /* ----------------------------------------------------------------- |
||
27 | | Constructor |
||
28 | | ----------------------------------------------------------------- |
||
29 | */ |
||
30 | |||
31 | /** |
||
32 | * Sitemap constructor. |
||
33 | */ |
||
34 | 34 | public function __construct() |
|
38 | |||
39 | /* ----------------------------------------------------------------- |
||
40 | | Main Methods |
||
41 | | ----------------------------------------------------------------- |
||
42 | */ |
||
43 | |||
44 | /** |
||
45 | * Set the sitemap path. |
||
46 | * |
||
47 | * @param string $path |
||
48 | * |
||
49 | * @return self |
||
50 | */ |
||
51 | 16 | public function setPath($path) |
|
57 | |||
58 | /** |
||
59 | * Get the sitemap path. |
||
60 | * |
||
61 | * @return string|null |
||
62 | */ |
||
63 | 4 | public function getPath() |
|
67 | |||
68 | /** |
||
69 | * Get the sitemap's URLs. |
||
70 | * |
||
71 | * @return \Illuminate\Support\Collection |
||
72 | */ |
||
73 | 20 | public function getUrls() |
|
77 | |||
78 | /** |
||
79 | * Get a URL instance by its loc. |
||
80 | * |
||
81 | * @param string $loc |
||
82 | * @param mixed|null $default |
||
83 | * |
||
84 | * @return \Arcanedev\LaravelSitemap\Entities\Url|null |
||
85 | */ |
||
86 | 2 | public function getUrl($loc, $default = null) |
|
90 | |||
91 | /** |
||
92 | * Add a sitemap URL to the collection. |
||
93 | * |
||
94 | * @param \Arcanedev\LaravelSitemap\Contracts\Entities\Url $url |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | 28 | public function add(UrlContract $url) |
|
104 | |||
105 | /** |
||
106 | * Create and Add a sitemap URL to the collection. |
||
107 | * |
||
108 | * @param string $loc |
||
109 | * @param callable $callback |
||
110 | * |
||
111 | * @return self |
||
112 | */ |
||
113 | 14 | public function create($loc, callable $callback) |
|
117 | |||
118 | /** |
||
119 | * Check if the url exists in the sitemap items. |
||
120 | * |
||
121 | * @param string $url |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | 4 | public function has($url) |
|
129 | |||
130 | /** |
||
131 | * Get the urls' count. |
||
132 | * |
||
133 | * @return int |
||
134 | */ |
||
135 | 8 | public function count() |
|
139 | |||
140 | /** |
||
141 | * Get the collection of items as a plain array. |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | 8 | public function toArray() |
|
149 | |||
150 | /** |
||
151 | * Get the sitemap and its urls as JSON. |
||
152 | * |
||
153 | * @param int $options |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | 2 | public function toJson($options = 0) |
|
161 | |||
162 | /** |
||
163 | * Convert the object into something JSON serializable. |
||
164 | * |
||
165 | * @return array |
||
166 | */ |
||
167 | 2 | public function jsonSerialize() |
|
171 | } |
||
172 |