Completed
Push — master ( 4a66c1...7a18b6 )
by Mehmet
03:31
created

ExtensionsAbstract::extendForTranslation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
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
 *
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->extendForTranslation();
0 ignored issues
show
Bug introduced by
The method extendForTranslation() does not seem to exist on object<Selami\View\ExtensionsAbstract>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

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