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