Completed
Push — master ( 1512d1...448951 )
by Mehmet
03:09
created

ExtensionsAbstract::extendForVarDump()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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