1 | <?php |
||
11 | class Url implements \Anax\Configure\ConfigureInterface |
||
12 | { |
||
13 | use \Anax\Configure\ConfigureTrait; |
||
14 | |||
15 | |||
16 | |||
17 | /** |
||
18 | * @const URL_CLEAN controller/action/param1/param2 |
||
19 | * @const URL_APPEND index.php/controller/action/param1/param2 |
||
20 | * @var $urlType What type of urls to generate, select from |
||
21 | * URL_CLEAN or URL_APPEND. |
||
22 | */ |
||
23 | const URL_CLEAN = 'clean'; |
||
24 | const URL_APPEND = 'append'; |
||
25 | private $urlType = self::URL_APPEND; |
||
26 | |||
27 | |||
28 | |||
29 | /** |
||
30 | * @var $siteUrl Siteurl to prepend to all absolute urls created. |
||
31 | * @var $baseUrl Baseurl to prepend to all relative urls created. |
||
32 | * @var $scriptName Name of the frontcontroller script. |
||
33 | */ |
||
34 | private $siteUrl; |
||
35 | private $baseUrl; |
||
36 | private $scriptName; |
||
37 | |||
38 | |||
39 | |||
40 | /** |
||
41 | * @var $staticSiteUrl Siteurl to prepend to all absolute urls for |
||
42 | * assets. |
||
43 | * @var $staticBaseUrl Baseurl to prepend to all relative urls for |
||
44 | * assets. |
||
45 | */ |
||
46 | private $staticSiteUrl; |
||
47 | private $staticBaseUrl; |
||
48 | |||
49 | |||
50 | /** |
||
51 | * Constructor |
||
52 | */ |
||
53 | 49 | public function __construct() |
|
61 | |||
62 | |||
63 | |||
64 | /** |
||
65 | * Set default values from configuration. |
||
66 | * |
||
67 | * @param mixed $configSource optional config source. |
||
68 | * |
||
69 | * @return self |
||
70 | */ |
||
71 | 1 | public function setDefaultsFromConfiguration($configSource = null) |
|
94 | |||
95 | |||
96 | |||
97 | /** |
||
98 | * Create an url and prepending the baseUrl. |
||
99 | * |
||
100 | * @param string $uri part of uri to use when creating an url. |
||
101 | * empty means baseurl to current |
||
102 | * frontcontroller. |
||
103 | * @param string $baseuri optional base to prepend uri. |
||
104 | * |
||
105 | * @return string as resulting url. |
||
106 | */ |
||
107 | 30 | public function create($uri = "", $baseuri = "") |
|
156 | |||
157 | |||
158 | |||
159 | /** |
||
160 | * Create an url and prepend the baseUrl to the directory of |
||
161 | * the frontcontroller. |
||
162 | * |
||
163 | * @param string $uri part of uri to use when creating an url. |
||
164 | * empty means baseurl to directory of |
||
165 | * the current frontcontroller. |
||
166 | * |
||
167 | * @return string as resulting url. |
||
168 | */ |
||
169 | 6 | public function createRelative($uri = "") |
|
188 | |||
189 | |||
190 | |||
191 | /** |
||
192 | * Create an url for a static asset. |
||
193 | * |
||
194 | * @param string $uri part of uri to use when creating an url. |
||
195 | * |
||
196 | * @return string as resulting url. |
||
197 | */ |
||
198 | 15 | public function asset($uri = "") |
|
221 | |||
222 | |||
223 | |||
224 | /** |
||
225 | * Set the siteUrl to prepend all absolute urls created. |
||
226 | * |
||
227 | * @param string $url part of url to use when creating an url. |
||
228 | * |
||
229 | * @return self |
||
230 | */ |
||
231 | 35 | public function setSiteUrl($url) |
|
236 | |||
237 | |||
238 | |||
239 | /** |
||
240 | * Set the baseUrl to prepend all relative urls created. |
||
241 | * |
||
242 | * @param string $url part of url to use when creating an url. |
||
243 | * |
||
244 | * @return self |
||
245 | */ |
||
246 | 39 | public function setBaseUrl($url) |
|
251 | |||
252 | |||
253 | |||
254 | /** |
||
255 | * Set the siteUrl to prepend absolute urls for assets. |
||
256 | * |
||
257 | * @param string $url part of url to use when creating an url. |
||
258 | * |
||
259 | * @return self |
||
260 | */ |
||
261 | 10 | public function setStaticSiteUrl($url) |
|
266 | |||
267 | |||
268 | |||
269 | /** |
||
270 | * Set the baseUrl to prepend relative urls for assets. |
||
271 | * |
||
272 | * @param string $url part of url to use when creating an url. |
||
273 | * |
||
274 | * @return self |
||
275 | */ |
||
276 | 10 | public function setStaticBaseUrl($url) |
|
281 | |||
282 | |||
283 | |||
284 | /** |
||
285 | * Set the scriptname to use when creating URL_APPEND urls. |
||
286 | * |
||
287 | * @param string $name as the scriptname, for example index.php. |
||
288 | * |
||
289 | * @return self |
||
290 | */ |
||
291 | 11 | public function setScriptName($name) |
|
296 | |||
297 | |||
298 | |||
299 | /** |
||
300 | * Set the type of urls to be generated, URL_CLEAN, URL_APPEND. |
||
301 | * |
||
302 | * @param string $type what type of urls to create. |
||
303 | * |
||
304 | * @return self |
||
305 | * |
||
306 | * @throws Exception |
||
307 | */ |
||
308 | 31 | public function setUrlType($type) |
|
317 | |||
318 | |||
319 | |||
320 | /** |
||
321 | * Create a slug of a string, to be used as url. |
||
322 | * |
||
323 | * @param string $str the string to format as slug. |
||
324 | * |
||
325 | * @return string the formatted slug. |
||
326 | */ |
||
327 | 4 | public function slugify($str) |
|
335 | } |
||
336 |