1 | <?php |
||
2 | /** |
||
3 | * @package toolkit |
||
4 | */ |
||
5 | /** |
||
6 | * TextPage extends the Page class to provide an object representation |
||
7 | * of a Symphony backend text page. |
||
8 | */ |
||
9 | |||
10 | abstract class TextPage extends Page |
||
11 | { |
||
12 | /** |
||
13 | * The body string response of the TextPage |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $_Result; |
||
17 | |||
18 | /** |
||
19 | * The constructor for `TextPage`. This sets the page status to `Page::HTTP_STATUS_OK`, |
||
20 | * the default content type to `text/plain` and initialises `$this->_Result` |
||
21 | * with an empty `string`. The constructor also starts the Profiler for this |
||
22 | * page template. |
||
23 | * |
||
24 | * @see toolkit.Profiler |
||
25 | */ |
||
26 | public function __construct() |
||
27 | { |
||
28 | $this->_Result = ""; |
||
0 ignored issues
–
show
|
|||
29 | |||
30 | $this->setHttpStatus(self::HTTP_STATUS_OK); |
||
31 | $this->addHeaderToPage('Content-Type', 'text/plain'); |
||
32 | |||
33 | Symphony::Profiler()->sample('Page template created', PROFILE_LAP); |
||
0 ignored issues
–
show
|
|||
34 | } |
||
35 | |||
36 | /** |
||
37 | * This function is called by Administration class when a user is not authenticated |
||
38 | * to the Symphony backend. It sets the status of this page to |
||
39 | * `Page::HTTP_STATUS_UNAUTHORIZED` and appends a message for generation |
||
40 | */ |
||
41 | public function handleFailedAuthorisation() |
||
42 | { |
||
43 | $this->setHttpStatus(self::HTTP_STATUS_UNAUTHORIZED); |
||
44 | $this->_Result = __('You are not authorised to access this page.'); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Calls the view function of this page. If a context is passed, it is |
||
49 | * also set. |
||
50 | * |
||
51 | * @see view() |
||
52 | * @param array $context |
||
53 | * The context of the page as an array. Defaults to null |
||
54 | */ |
||
55 | public function build($context = null) |
||
0 ignored issues
–
show
|
|||
56 | { |
||
57 | if ($context) { |
||
58 | $this->_context = $context; |
||
0 ignored issues
–
show
|
|||
59 | } |
||
60 | |||
61 | $this->view(); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * The generate functions outputs the correct headers for |
||
66 | * this `TextPage`, before calling the parent generate function and |
||
67 | * returning the `$this->_Result` string |
||
68 | * |
||
69 | * @param null $page |
||
0 ignored issues
–
show
|
|||
70 | * @return string |
||
71 | */ |
||
72 | public function generate($page = null) |
||
0 ignored issues
–
show
|
|||
73 | { |
||
74 | parent::generate($page); |
||
75 | return $this->_Result; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * All classes that extend the `TextPage` class must define a view method |
||
80 | * which contains the logic for the content of this page. The resulting values |
||
81 | * must be appended to `$this->_Result` where it is generated as json on build |
||
82 | * |
||
83 | * @see build() |
||
84 | */ |
||
85 | abstract public function view(); |
||
86 | } |
||
87 |
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.