Completed
Push — master ( 1d0354...1512d1 )
by Mehmet
04:41
created

ExtensionsAbstract   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 38.46%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 130
ccs 10
cts 26
cp 0.3846
rs 10
c 0
b 0
f 0

9 Methods

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