-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathParserComponent.php
More file actions
201 lines (181 loc) · 5.23 KB
/
ParserComponent.php
File metadata and controls
201 lines (181 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/**
* Component which enables CakeML views.
*
* PHP 5
*
* Cake Markup Language (http://github.com/jameswatts/cake-markup-language)
* Copyright 2013, James Watts (http://github.com/jameswatts)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2013, James Watts (http://github.com/jameswatts)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cml.Controller.Component
* @since CakePHP(tm) v 2.1.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Component', 'Controller');
/**
* The Parser component parses the markup and compiles the output.
*
* @package Cml.Controller.Component
*/
class ParserComponent extends Component {
/**
* An array containing the names of helpers this controller uses. The array elements should
* not contain the "Helper" part of the classname.
*
* @var mixed A single name as a string or a list of names as an array.
*/
public $helpers = null;
/**
* The name of the layout file to render the view inside of. The name specified
* is the filename of the layout in /app/View/Layouts without the .ctp
* extension.
*
* @var string
*/
public $layout = null;
/**
* Used to define methods a controller that will be cached. To cache a
* single action, the value is set to an array containing keys that match
* action names and values that denote cache expiration times (in seconds).
*
* $cacheAction can also be set to a strtotime() compatible string. This
* marks all the actions in the controller for view caching.
*
* @var mixed
*/
public $cacheAction = false;
/**
* Determines which actions of the controller should not have their views rendered
* using the CakeML view. Can be a single action as a string, or an array of
* actions to ignore.
*
* @var mixed
*/
public $ignoreAction = null;
/**
* An array containing the namespaces this view uses, specifying the plugin
* name using dot notation, for example, Example.Tools, where "Example" is the
* plugin name, and "Tools" is the namespace.
*
* @var mixed A single name as a string or a list of names as an array.
*/
public $namespaces = null;
/**
* Defines if View variable lookup includes Configure variables.
*
* @var boolean
*/
public $loadConfigure = false;
/**
* Defines if View variable lookup includes Session variables.
*
* @var boolean
*/
public $loadSession = false;
/**
* Determines if layouts are parsed as markup.
*
* @var boolean
*/
public $renderLayout = false;
/**
* Determines if elements are parsed as markup.
*
* @var boolean
*/
public $renderElement = false;
/**
* Fallback to ".ctp" if a ".cml" file is not found.
*
* @var boolean
*/
public $fallback = false;
/**
* Determines if debug mode is enabled.
*
* @var boolean
*/
public $debug = false;
/**
* Static load settings for the View object.
*
* @var boolean
*/
public static $loadSettings = array();
/**
* Static render settings for the View object.
*
* @var boolean
*/
public static $renderSettings = array();
/**
* Called before the Controller::beforeRender(), and before the view class is
* loaded, and before Controller::render().
*
* @param Controller $controller Controller with components to beforeRender.
* @return void
*/
public function beforeRender(Controller $controller) {
if (!$this->ignoreAction || ((is_string($this->ignoreAction) && $this->ignoreAction != $controller->action) || (is_array($this->ignoreAction) && !in_array($controller->action, $this->ignoreAction)))) {
self::$loadSettings['configure'] = $this->loadConfigure;
self::$loadSettings['session'] = $this->loadSession;
self::$renderSettings['layout'] = $this->renderLayout;
self::$renderSettings['element'] = $this->renderElement;
self::$renderSettings['fallback'] = $this->fallback;
$controller->viewClass = 'Cml.Cml';
if (is_array($this->helpers)) {
if (!is_array($controller->helpers)) {
$controller->helpers = $this->helpers;
} else {
$controller->helpers = array_merge($controller->helpers, $this->helpers);
}
}
if (is_string($this->layout)) {
$controller->layout = $this->layout;
}
if (is_array($this->cacheAction)) {
if (!is_array($controller->cacheAction)) {
$controller->cacheAction = $this->cacheAction;
} else {
$controller->cacheAction = array_merge($controller->cacheAction, $this->cacheAction);
}
}
}
}
/**
* Formats the array as a short array syntax string for the View.
*
* @param array $array The array to format.
* @return string
*/
public function formatArray($array = array()) {
$items = array();
foreach ($array as $key => $value) {
$item = '';
if (!is_numeric($key)) {
$item .= "'" . $this->formatString($key) . "' => ";
}
if (is_array($value)) {
$item .= $this->formatArray($value);
} else {
$item .= (is_string($value))? "'" . $this->formatString($value) . "'" : $value;
}
$items[] = $item;
}
return '[' . implode(', ', $items) . ']';
}
/**
* Formats the string as escaped for the View.
*
* @param string $string The string to format.
* @return string
*/
public function formatString($string = '') {
return htmlentities($string, ENT_QUOTES, 'UTF-8', false);
}
}