|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Selami\View; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class ViewExtensionsAbstract |
|
8
|
|
|
* |
|
9
|
|
|
* @package Selami\ViewExtensionsAbstract |
|
10
|
|
|
*/ |
|
11
|
|
|
abstract class ExtensionsAbstract |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Load functions that will be used in the templates |
|
16
|
|
|
*/ |
|
17
|
|
|
protected function loadFunctions() : void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->extendForTranslator(); |
|
20
|
|
|
$this->extendForWidget(); |
|
21
|
|
|
$this->extendForSiteUrl(); |
|
22
|
|
|
$this->extendForGetUrl(); |
|
23
|
|
|
$this->extendForQueryParams(); |
|
24
|
|
|
$this->extendForPagination(); |
|
25
|
|
|
$this->extendForVarDump(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
abstract protected function extendForTranslator() : void; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Extend for function getUrl that returns url path for an alias. |
|
32
|
|
|
* |
|
33
|
|
|
* Let's say $aliases = ['home' => '/', 'about' => '/about-us'] |
|
34
|
|
|
* and $baseUrl = 'http://127.0.0.1'; |
|
35
|
|
|
* {{ getUrl('about') }} produces http://127.0.0.1/about-us |
|
36
|
|
|
* |
|
37
|
|
|
* If returned alias value has parametric strings, you can pass the values of these parameters. |
|
38
|
|
|
* Let's say $aliases = ['home' => '/', 'about' => '/{lang}/about-us'] |
|
39
|
|
|
* and $baseUrl = 'http://127.0.0.1' and $page_lang = 'en_US' |
|
40
|
|
|
* {{ getUrl('about', {'lang': page_lang}) }} produces http://127.0.0.1/en_US/about-us |
|
41
|
|
|
*/ |
|
42
|
|
|
abstract protected function extendForGetUrl() : void; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Extend for wildcard Widget functions. Widget function determines the class and method that will be called. |
|
46
|
|
|
* For example {{Widget_menu_top({'param':2})}} acts like this anonymous function: |
|
47
|
|
|
* (function(){ |
|
48
|
|
|
* $Widget = new Widget\Menu(); |
|
49
|
|
|
* $WidgetContent = $Widget->top(['param' => 2]); |
|
50
|
|
|
* } |
|
51
|
|
|
* )(); |
|
52
|
|
|
*/ |
|
53
|
|
|
abstract protected function extendForWidget() : void; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Extend for queryParams function that returns http_build_query result using passed parameters. |
|
57
|
|
|
* $prefix = '?'; |
|
58
|
|
|
* {{ queryParams({'param1':1,'param2':2}, $prefix) }} returns ?param1=1¶m2=2 |
|
59
|
|
|
*/ |
|
60
|
|
|
abstract protected function extendForQueryParams() : void; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Extend for function siteUrl that returns defined baseUrl of the site |
|
64
|
|
|
* Let's say $baseUrl = 'http://127.0.0.1'; |
|
65
|
|
|
* {{ siteUrl('/home') }} produces http://127.0.0.1/home |
|
66
|
|
|
*/ |
|
67
|
|
|
abstract protected function extendForSiteUrl() : void; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Extend for function varDump. Just outputs var_dump of passed parameter. |
|
71
|
|
|
* |
|
72
|
|
|
* Use it for debugging purposes. |
|
73
|
|
|
*/ |
|
74
|
|
|
abstract protected function extendForVarDump() : void; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Extend for function Pagination. This function builds pagination html. |
|
78
|
|
|
* Example: |
|
79
|
|
|
* $total_number_of_pages = 20; // Mandatory |
|
80
|
|
|
* $current_page = 2; // Mandatory. Starts from 1; |
|
81
|
|
|
* $link_template = '/list?page_num=(page_id)'; // Mandatory. Use "(page_id)" string to replace page number. |
|
82
|
|
|
* $parentTemplate = '<ul class="pagination">(items)</ul>'; // Optional. This is also default value. |
|
83
|
|
|
* Use '(item)' string to place generated item htmls. |
|
84
|
|
|
* $itemTemplate = '<li class="(item_class)">(link)</li>'; // Optional. This is also default value. |
|
85
|
|
|
* Use '(item_class)' string where "active" class will be placed when the page is current page. |
|
86
|
|
|
* Use '(link)' string to place generated link html. |
|
87
|
|
|
* $linkItemTemplate = '<a href="(href)" class="(link_class)">(text)</a>'; // Optional. This is also default value. |
|
88
|
|
|
* '(href)' string is mandatory. generated link uri will be placed. |
|
89
|
|
|
* '(link_class)' string is optional. "active" class will be placed when it is current page. |
|
90
|
|
|
* '(text)' string is mandatory. Page number will be placed. |
|
91
|
|
|
* $ellipsesTemplate = '<li><a>...</a></li>'; // Optional. This is also default value. |
|
92
|
|
|
* |
|
93
|
|
|
* {{ Pagination($total_number_of_pages, $current_page, $link_template, $parentTemplate, $linkItemTemplate, |
|
94
|
|
|
* $ellipsesTemplate) }} |
|
95
|
|
|
* or you can use with default values: |
|
96
|
|
|
* {{ Pagination($total_number_of_pages, $current_page, $link_template) }} |
|
97
|
|
|
* This returns following html. |
|
98
|
|
|
* <ul class="pagination"> |
|
99
|
|
|
* <li class=""><a href="/list?page_num=1" class="">1</a></li> |
|
100
|
|
|
* <li class="active"><a href="/list?page_num=2" class="active">2</a></li> |
|
101
|
|
|
* <li><a href="/list?page_num=3" class="">3</a></li> |
|
102
|
|
|
* <li><a href="/list?page_num=4" class="">4</a></li> |
|
103
|
|
|
* <li><a href="/list?page_num=5" class="">5</a></li> |
|
104
|
|
|
* <li><a>...</a></li> |
|
105
|
|
|
* <li><a href="/list?page_num=18" class="">3</a></li> |
|
106
|
|
|
* <li><a href="/list?page_num=19" class="">3</a></li> |
|
107
|
|
|
* <li><a href="/list?page_num=20" class="">3</a></li> |
|
108
|
|
|
* </ul> |
|
109
|
|
|
*/ |
|
110
|
|
|
abstract protected function extendForPagination() : void; |
|
111
|
|
|
} |
|
112
|
|
|
|