|
1
|
|
|
<?php |
|
2
|
|
|
namespace Pagerfanta\View\Template; |
|
3
|
|
|
|
|
4
|
|
|
use Pagerfanta\View\Template\Template; |
|
5
|
|
|
/** |
|
6
|
|
|
* @author Vitor Mattos <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
class TelegramInlineTemplate extends Template |
|
9
|
|
|
{ |
|
10
|
|
|
static protected $defaultOptions = array( |
|
11
|
|
|
'first_page_template' => '« %text%', |
|
12
|
|
|
'last_page_template' => '%text% »', |
|
13
|
|
|
'previous_template' => '‹ %text%', |
|
14
|
|
|
'next_template' => '%text% ›', |
|
15
|
|
|
'page_template' => '%text%', |
|
16
|
|
|
'current_template' => '· %text% ·', |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
|
|
public function container() { } |
|
20
|
|
|
|
|
21
|
10 |
|
public function page($page) |
|
22
|
|
|
{ |
|
23
|
10 |
|
$text = $page; |
|
24
|
|
|
|
|
25
|
10 |
|
return $this->pageWithText($page, $text); |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
10 |
|
public function pageWithText($page, $text) |
|
29
|
|
|
{ |
|
30
|
|
|
return array( |
|
|
|
|
|
|
31
|
10 |
|
'text' => str_replace('%text%', $text, $this->option('page_template')), |
|
32
|
10 |
|
'callback_data' => $this->generateRoute($page), |
|
33
|
|
|
'page' => $page |
|
34
|
10 |
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function previousDisabled() { } |
|
38
|
|
|
|
|
39
|
3 |
|
public function previousEnabled($page) |
|
40
|
|
|
{ |
|
41
|
3 |
|
return $this->pageWithText($page, str_replace('%text%', $page, $this->option('previous_template'))); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function nextDisabled() { } |
|
45
|
|
|
|
|
46
|
9 |
|
public function nextEnabled($page) |
|
47
|
|
|
{ |
|
48
|
9 |
|
return $this->pageWithText($page, str_replace('%text%', $page, $this->option('next_template'))); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
3 |
|
public function first() |
|
52
|
|
|
{ |
|
53
|
3 |
|
$text = str_replace('%text%', 1, $this->option('first_page_template')); |
|
54
|
|
|
|
|
55
|
3 |
|
return $this->pageWithText(1, $text); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
7 |
|
public function last($page) |
|
59
|
|
|
{ |
|
60
|
7 |
|
$text = str_replace('%text%', $page, $this->option('last_page_template')); |
|
61
|
|
|
|
|
62
|
7 |
|
return $this->pageWithText($page, $text); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
10 |
|
public function current($page) |
|
66
|
|
|
{ |
|
67
|
10 |
|
$text = str_replace('%text%', $page, $this->option('current_template')); |
|
68
|
|
|
|
|
69
|
10 |
|
return $this->pageWithText($page, $text); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function separator() { } |
|
73
|
|
|
|
|
74
|
|
|
private function generateSpan($class, $page) |
|
75
|
|
|
{ |
|
76
|
|
|
$search = array('%class%', '%text%'); |
|
77
|
|
|
$replace = array($class, $page); |
|
78
|
|
|
|
|
79
|
|
|
return str_replace($search, $replace, $this->option('span_template')); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.