@@ -54,6 +54,9 @@ discard block |
||
54 | 54 | return $user; |
55 | 55 | } |
56 | 56 | |
57 | + /** |
|
58 | + * @param Vtiger_Request $request |
|
59 | + */ |
|
57 | 60 | protected function triggerCheckPermission($handler, $request) |
58 | 61 | { |
59 | 62 | $moduleName = $request->getModule(); |
@@ -73,6 +76,9 @@ discard block |
||
73 | 76 | throw new \Exception\NoPermitted('LBL_NOT_ACCESSIBLE'); |
74 | 77 | } |
75 | 78 | |
79 | + /** |
|
80 | + * @param Vtiger_Request $request |
|
81 | + */ |
|
76 | 82 | protected function triggerPreProcess($handler, $request) |
77 | 83 | { |
78 | 84 | if ($request->isAjax()) { |
@@ -82,6 +88,9 @@ discard block |
||
82 | 88 | $handler->preProcess($request); |
83 | 89 | } |
84 | 90 | |
91 | + /** |
|
92 | + * @param Vtiger_Request $request |
|
93 | + */ |
|
85 | 94 | protected function triggerPostProcess($handler, $request) |
86 | 95 | { |
87 | 96 | if ($request->isAjax()) { |
@@ -48,6 +48,9 @@ |
||
48 | 48 | return $row; |
49 | 49 | } |
50 | 50 | |
51 | + /** |
|
52 | + * @param boolean $t |
|
53 | + */ |
|
51 | 54 | public static function sanitizeData($newRow, $meta, $t = null) |
52 | 55 | { |
53 | 56 |
@@ -24,8 +24,9 @@ discard block |
||
24 | 24 | $fieldColumnMapping = $meta->getFieldColumnMapping(); |
25 | 25 | $columnFieldMapping = array_flip($fieldColumnMapping); |
26 | 26 | foreach ($row as $col => $val) { |
27 | - if (array_key_exists($col, $columnFieldMapping)) |
|
28 | - $newRow[$columnFieldMapping[$col]] = $val; |
|
27 | + if (array_key_exists($col, $columnFieldMapping)) { |
|
28 | + $newRow[$columnFieldMapping[$col]] = $val; |
|
29 | + } |
|
29 | 30 | } |
30 | 31 | $newRow = DataTransform::sanitizeData($newRow, $meta, true); |
31 | 32 | return $newRow; |
@@ -149,8 +150,9 @@ discard block |
||
149 | 150 | $allFields = $meta->getFieldColumnMapping(); |
150 | 151 | $newRow = []; |
151 | 152 | foreach ($allFields as $field => $col) { |
152 | - if (isset($row[$field])) |
|
153 | - $newRow[$field] = $row[$field]; |
|
153 | + if (isset($row[$field])) { |
|
154 | + $newRow[$field] = $row[$field]; |
|
155 | + } |
|
154 | 156 | } |
155 | 157 | if (isset($row[$recordString])) { |
156 | 158 | $newRow[$recordString] = $row[$recordString]; |
@@ -10,6 +10,9 @@ |
||
10 | 10 | |
11 | 11 | require_once("include/Webservices/QueryParser.php"); |
12 | 12 | |
13 | +/** |
|
14 | + * @param string $q |
|
15 | + */ |
|
13 | 16 | function vtws_query($q, $user) |
14 | 17 | { |
15 | 18 |
@@ -21,8 +21,9 @@ |
||
21 | 21 | // Cache the instance for re-use |
22 | 22 | $moduleRegex = "/[fF][rR][Oo][Mm]\s+([^\s;]+)/"; |
23 | 23 | $moduleName = ''; |
24 | - if (preg_match($moduleRegex, $q, $m)) |
|
25 | - $moduleName = trim($m[1]); |
|
24 | + if (preg_match($moduleRegex, $q, $m)) { |
|
25 | + $moduleName = trim($m[1]); |
|
26 | + } |
|
26 | 27 | |
27 | 28 | if (!isset($vtws_create_cache[$moduleName]['webserviceobject'])) { |
28 | 29 | $webserviceObject = VtigerWebserviceObject::fromQuery($adb, $q); |
@@ -12,6 +12,9 @@ |
||
12 | 12 | include_once 'include/Webservices/Query.php'; |
13 | 13 | include_once 'include/Webservices/RelatedTypes.php'; |
14 | 14 | |
15 | +/** |
|
16 | + * @param string $query |
|
17 | + */ |
|
15 | 18 | function vtws_query_related($query, $id, $relatedLabel, $user, $filterClause = null) |
16 | 19 | { |
17 | 20 |
@@ -71,7 +71,7 @@ |
||
71 | 71 | if (!empty($filterClause)) { |
72 | 72 | $query .= " " . $filterClause; |
73 | 73 | } |
74 | - $query.=";"; |
|
74 | + $query .= ";"; |
|
75 | 75 | $relatedRecords = vtws_query($query, $user); |
76 | 76 | } |
77 | 77 |
@@ -148,6 +148,9 @@ |
||
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | |
151 | + /** |
|
152 | + * @param string $id |
|
153 | + */ |
|
151 | 154 | public function retrieve($id) |
152 | 155 | { |
153 | 156 |
@@ -270,8 +270,7 @@ |
||
270 | 270 | foreach ($moduleFields as $fieldName => $webserviceField) { |
271 | 271 | array_push($fields, $this->getDescribeFieldArray($webserviceField)); |
272 | 272 | } |
273 | - $label = ($app_strings[$this->meta->getObectIndexColumn()]) ? $app_strings[$this->meta->getObectIndexColumn()] : |
|
274 | - $this->meta->getObectIndexColumn(); |
|
273 | + $label = ($app_strings[$this->meta->getObectIndexColumn()]) ? $app_strings[$this->meta->getObectIndexColumn()] : $this->meta->getObectIndexColumn(); |
|
275 | 274 | $this->moduleFields = $fields; |
276 | 275 | } |
277 | 276 | return $this->moduleFields; |
@@ -15,6 +15,9 @@ |
||
15 | 15 | protected static $fieldTypeMapping = []; |
16 | 16 | protected static $referenceTypeMapping = []; |
17 | 17 | |
18 | + /** |
|
19 | + * @param PearDatabase $adb |
|
20 | + */ |
|
18 | 21 | public function __construct($tableName, $webserviceObject, $adb, $user) |
19 | 22 | { |
20 | 23 | parent::__construct($webserviceObject, $user); |
@@ -5,6 +5,9 @@ discard block |
||
5 | 5 | $in_started = false; |
6 | 6 | $count = false; |
7 | 7 | |
8 | +/** |
|
9 | + * @param integer $count |
|
10 | + */ |
|
8 | 11 | function incrementN($lexer, $count) |
9 | 12 | { |
10 | 13 | $i = 0; |
@@ -160,6 +163,9 @@ discard block |
||
160 | 163 | } |
161 | 164 | } |
162 | 165 | |
166 | +/** |
|
167 | + * @param VTQL_Lexer $lexer |
|
168 | + */ |
|
163 | 169 | function handleend($lexer, $val) |
164 | 170 | { |
165 | 171 | return VTQL_Parser::SEMICOLON; |
@@ -179,6 +185,9 @@ discard block |
||
179 | 185 | public $mandatory; |
180 | 186 | public $current_state; |
181 | 187 | |
188 | + /** |
|
189 | + * @param string $data |
|
190 | + */ |
|
182 | 191 | public function __construct($data) |
183 | 192 | { |
184 | 193 | $this->index = 0; |
@@ -159,6 +159,9 @@ |
||
159 | 159 | private $syntax_error; |
160 | 160 | private $user; |
161 | 161 | |
162 | + /** |
|
163 | + * @param VTQL_Lexer $lex |
|
164 | + */ |
|
162 | 165 | public function __construct($user, $lex, $out) |
163 | 166 | { |
164 | 167 | if (!is_array($out)) { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | { |
90 | 90 | |
91 | 91 | public $stateno; /* The state-number */ |
92 | - public $major; /* The major token value. This is the code |
|
92 | + public $major; /* The major token value. This is the code |
|
93 | 93 | * * number for the token at this stack level */ |
94 | 94 | public $minor; /* The user-supplied minor token value. This |
95 | 95 | * * is the value of the token */ |
@@ -663,17 +663,17 @@ discard block |
||
663 | 663 | /** |
664 | 664 | * @var int |
665 | 665 | */ |
666 | - public $yyidx; /* Index of top element in stack */ |
|
666 | + public $yyidx; /* Index of top element in stack */ |
|
667 | 667 | |
668 | 668 | /** |
669 | 669 | * @var int |
670 | 670 | */ |
671 | - public $yyerrcnt; /* Shifts left before out of the error */ |
|
671 | + public $yyerrcnt; /* Shifts left before out of the error */ |
|
672 | 672 | |
673 | 673 | /** |
674 | 674 | * @var array |
675 | 675 | */ |
676 | - public $yystack = []; /* The parser's stack */ |
|
676 | + public $yystack = []; /* The parser's stack */ |
|
677 | 677 | |
678 | 678 | /** |
679 | 679 | * For tracing shifts, the names of all terminals and nonterminals |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | * * which appear on the RHS of the rule, but which are not used |
783 | 783 | * * inside the C code. |
784 | 784 | */ |
785 | - default: break; /* If no destructor action specified: do nothing */ |
|
785 | + default: break; /* If no destructor action specified: do nothing */ |
|
786 | 786 | } |
787 | 787 | } |
788 | 788 | |
@@ -1608,7 +1608,7 @@ discard block |
||
1608 | 1608 | { |
1609 | 1609 | // $yyact; /* The parser action. */ |
1610 | 1610 | // $yyendofinput; /* True if we are at the end of input */ |
1611 | - $yyerrorhit = 0; /* True if yymajor has invoked an error */ |
|
1611 | + $yyerrorhit = 0; /* True if yymajor has invoked an error */ |
|
1612 | 1612 | |
1613 | 1613 | /* (re)initialize the parser, if necessary */ |
1614 | 1614 | if ($this->yyidx === null || $this->yyidx < 0) { |
@@ -165,7 +165,7 @@ |
||
165 | 165 | * the next element. |
166 | 166 | * |
167 | 167 | * @param Reader $reader |
168 | - * @return mixed |
|
168 | + * @return Acl |
|
169 | 169 | */ |
170 | 170 | static function xmlDeserialize(Reader $reader) { |
171 | 171 |
@@ -177,7 +177,7 @@ |
||
177 | 177 | |
178 | 178 | $privileges = []; |
179 | 179 | |
180 | - foreach ((array)$reader->parseInnerTree($elementMap) as $element) { |
|
180 | + foreach ((array) $reader->parseInnerTree($elementMap) as $element) { |
|
181 | 181 | |
182 | 182 | if ($element['name'] !== '{DAV:}ace') { |
183 | 183 | continue; |
@@ -136,7 +136,9 @@ |
||
136 | 136 | } |
137 | 137 | echo '<td>', $html->xmlName($privilege['privilege']), '</td>'; |
138 | 138 | echo '<td>'; |
139 | - if (!empty($privilege['protected'])) echo '(protected)'; |
|
139 | + if (!empty($privilege['protected'])) { |
|
140 | + echo '(protected)'; |
|
141 | + } |
|
140 | 142 | echo '</td>'; |
141 | 143 | echo '</tr>'; |
142 | 144 |
@@ -27,251 +27,251 @@ |
||
27 | 27 | */ |
28 | 28 | class Acl implements Element, HtmlOutput { |
29 | 29 | |
30 | - /** |
|
31 | - * List of privileges |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $privileges; |
|
36 | - |
|
37 | - /** |
|
38 | - * Whether or not the server base url is required to be prefixed when |
|
39 | - * serializing the property. |
|
40 | - * |
|
41 | - * @var bool |
|
42 | - */ |
|
43 | - protected $prefixBaseUrl; |
|
44 | - |
|
45 | - /** |
|
46 | - * Constructor |
|
47 | - * |
|
48 | - * This object requires a structure similar to the return value from |
|
49 | - * Sabre\DAVACL\Plugin::getACL(). |
|
50 | - * |
|
51 | - * Each privilege is a an array with at least a 'privilege' property, and a |
|
52 | - * 'principal' property. A privilege may have a 'protected' property as |
|
53 | - * well. |
|
54 | - * |
|
55 | - * The prefixBaseUrl should be set to false, if the supplied principal urls |
|
56 | - * are already full urls. If this is kept to true, the servers base url |
|
57 | - * will automatically be prefixed. |
|
58 | - * |
|
59 | - * @param array $privileges |
|
60 | - * @param bool $prefixBaseUrl |
|
61 | - */ |
|
62 | - public function __construct(array $privileges, $prefixBaseUrl = true) { |
|
63 | - |
|
64 | - $this->privileges = $privileges; |
|
65 | - $this->prefixBaseUrl = $prefixBaseUrl; |
|
66 | - |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Returns the list of privileges for this property |
|
71 | - * |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function getPrivileges() { |
|
75 | - |
|
76 | - return $this->privileges; |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * The xmlSerialize metod is called during xml writing. |
|
82 | - * |
|
83 | - * Use the $writer argument to write its own xml serialization. |
|
84 | - * |
|
85 | - * An important note: do _not_ create a parent element. Any element |
|
86 | - * implementing XmlSerializble should only ever write what's considered |
|
87 | - * its 'inner xml'. |
|
88 | - * |
|
89 | - * The parent of the current element is responsible for writing a |
|
90 | - * containing element. |
|
91 | - * |
|
92 | - * This allows serializers to be re-used for different element names. |
|
93 | - * |
|
94 | - * If you are opening new elements, you must also close them again. |
|
95 | - * |
|
96 | - * @param Writer $writer |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function xmlSerialize(Writer $writer) { |
|
100 | - |
|
101 | - foreach ($this->privileges as $ace) { |
|
102 | - |
|
103 | - $this->serializeAce($writer, $ace); |
|
104 | - |
|
105 | - } |
|
106 | - |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Generate html representation for this value. |
|
111 | - * |
|
112 | - * The html output is 100% trusted, and no effort is being made to sanitize |
|
113 | - * it. It's up to the implementor to sanitize user provided values. |
|
114 | - * |
|
115 | - * The output must be in UTF-8. |
|
116 | - * |
|
117 | - * The baseUri parameter is a url to the root of the application, and can |
|
118 | - * be used to construct local links. |
|
119 | - * |
|
120 | - * @param HtmlOutputHelper $html |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function toHtml(HtmlOutputHelper $html) { |
|
124 | - |
|
125 | - ob_start(); |
|
126 | - echo "<table>"; |
|
127 | - echo "<tr><th>Principal</th><th>Privilege</th><th></th></tr>"; |
|
128 | - foreach ($this->privileges as $privilege) { |
|
129 | - |
|
130 | - echo '<tr>'; |
|
131 | - // if it starts with a {, it's a special principal |
|
132 | - if ($privilege['principal'][0] === '{') { |
|
133 | - echo '<td>', $html->xmlName($privilege['principal']), '</td>'; |
|
134 | - } else { |
|
135 | - echo '<td>', $html->link($privilege['principal']), '</td>'; |
|
136 | - } |
|
137 | - echo '<td>', $html->xmlName($privilege['privilege']), '</td>'; |
|
138 | - echo '<td>'; |
|
139 | - if (!empty($privilege['protected'])) echo '(protected)'; |
|
140 | - echo '</td>'; |
|
141 | - echo '</tr>'; |
|
142 | - |
|
143 | - } |
|
144 | - echo "</table>"; |
|
145 | - return ob_get_clean(); |
|
146 | - |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * The deserialize method is called during xml parsing. |
|
151 | - * |
|
152 | - * This method is called statictly, this is because in theory this method |
|
153 | - * may be used as a type of constructor, or factory method. |
|
154 | - * |
|
155 | - * Often you want to return an instance of the current class, but you are |
|
156 | - * free to return other data as well. |
|
157 | - * |
|
158 | - * Important note 2: You are responsible for advancing the reader to the |
|
159 | - * next element. Not doing anything will result in a never-ending loop. |
|
160 | - * |
|
161 | - * If you just want to skip parsing for this element altogether, you can |
|
162 | - * just call $reader->next(); |
|
163 | - * |
|
164 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
165 | - * the next element. |
|
166 | - * |
|
167 | - * @param Reader $reader |
|
168 | - * @return mixed |
|
169 | - */ |
|
170 | - static function xmlDeserialize(Reader $reader) { |
|
171 | - |
|
172 | - $elementMap = [ |
|
173 | - '{DAV:}ace' => 'Sabre\Xml\Element\KeyValue', |
|
174 | - '{DAV:}privilege' => 'Sabre\Xml\Element\Elements', |
|
175 | - '{DAV:}principal' => 'Sabre\DAVACL\Xml\Property\Principal', |
|
176 | - ]; |
|
177 | - |
|
178 | - $privileges = []; |
|
179 | - |
|
180 | - foreach ((array)$reader->parseInnerTree($elementMap) as $element) { |
|
181 | - |
|
182 | - if ($element['name'] !== '{DAV:}ace') { |
|
183 | - continue; |
|
184 | - } |
|
185 | - $ace = $element['value']; |
|
186 | - |
|
187 | - if (empty($ace['{DAV:}principal'])) { |
|
188 | - throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element'); |
|
189 | - } |
|
190 | - $principal = $ace['{DAV:}principal']; |
|
191 | - |
|
192 | - switch ($principal->getType()) { |
|
193 | - case Principal::HREF : |
|
194 | - $principal = $principal->getHref(); |
|
195 | - break; |
|
196 | - case Principal::AUTHENTICATED : |
|
197 | - $principal = '{DAV:}authenticated'; |
|
198 | - break; |
|
199 | - case Principal::UNAUTHENTICATED : |
|
200 | - $principal = '{DAV:}unauthenticated'; |
|
201 | - break; |
|
202 | - case Principal::ALL : |
|
203 | - $principal = '{DAV:}all'; |
|
204 | - break; |
|
205 | - |
|
206 | - } |
|
207 | - |
|
208 | - $protected = array_key_exists('{DAV:}protected', $ace); |
|
209 | - |
|
210 | - if (!isset($ace['{DAV:}grant'])) { |
|
211 | - throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported'); |
|
212 | - } |
|
213 | - foreach ($ace['{DAV:}grant'] as $elem) { |
|
214 | - if ($elem['name'] !== '{DAV:}privilege') { |
|
215 | - continue; |
|
216 | - } |
|
217 | - |
|
218 | - foreach ($elem['value'] as $priv) { |
|
219 | - $privileges[] = [ |
|
220 | - 'principal' => $principal, |
|
221 | - 'protected' => $protected, |
|
222 | - 'privilege' => $priv, |
|
223 | - ]; |
|
224 | - } |
|
225 | - |
|
226 | - } |
|
227 | - |
|
228 | - } |
|
229 | - |
|
230 | - return new self($privileges); |
|
231 | - |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Serializes a single access control entry. |
|
236 | - * |
|
237 | - * @param Writer $writer |
|
238 | - * @param array $ace |
|
239 | - * @return void |
|
240 | - */ |
|
241 | - private function serializeAce(Writer $writer, array $ace) { |
|
242 | - |
|
243 | - $writer->startElement('{DAV:}ace'); |
|
244 | - |
|
245 | - switch ($ace['principal']) { |
|
246 | - case '{DAV:}authenticated' : |
|
247 | - $principal = new Principal(Principal::AUTHENTICATED); |
|
248 | - break; |
|
249 | - case '{DAV:}unauthenticated' : |
|
250 | - $principal = new Principal(Principal::UNAUTHENTICATED); |
|
251 | - break; |
|
252 | - case '{DAV:}all' : |
|
253 | - $principal = new Principal(Principal::ALL); |
|
254 | - break; |
|
255 | - default: |
|
256 | - $principal = new Principal(Principal::HREF, $ace['principal']); |
|
257 | - break; |
|
258 | - } |
|
259 | - |
|
260 | - $writer->writeElement('{DAV:}principal', $principal); |
|
261 | - $writer->startElement('{DAV:}grant'); |
|
262 | - $writer->startElement('{DAV:}privilege'); |
|
263 | - |
|
264 | - $writer->writeElement($ace['privilege']); |
|
265 | - |
|
266 | - $writer->endElement(); // privilege |
|
267 | - $writer->endElement(); // grant |
|
268 | - |
|
269 | - if (!empty($ace['protected'])) { |
|
270 | - $writer->writeElement('{DAV:}protected'); |
|
271 | - } |
|
272 | - |
|
273 | - $writer->endElement(); // ace |
|
274 | - |
|
275 | - } |
|
30 | + /** |
|
31 | + * List of privileges |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $privileges; |
|
36 | + |
|
37 | + /** |
|
38 | + * Whether or not the server base url is required to be prefixed when |
|
39 | + * serializing the property. |
|
40 | + * |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | + protected $prefixBaseUrl; |
|
44 | + |
|
45 | + /** |
|
46 | + * Constructor |
|
47 | + * |
|
48 | + * This object requires a structure similar to the return value from |
|
49 | + * Sabre\DAVACL\Plugin::getACL(). |
|
50 | + * |
|
51 | + * Each privilege is a an array with at least a 'privilege' property, and a |
|
52 | + * 'principal' property. A privilege may have a 'protected' property as |
|
53 | + * well. |
|
54 | + * |
|
55 | + * The prefixBaseUrl should be set to false, if the supplied principal urls |
|
56 | + * are already full urls. If this is kept to true, the servers base url |
|
57 | + * will automatically be prefixed. |
|
58 | + * |
|
59 | + * @param array $privileges |
|
60 | + * @param bool $prefixBaseUrl |
|
61 | + */ |
|
62 | + public function __construct(array $privileges, $prefixBaseUrl = true) { |
|
63 | + |
|
64 | + $this->privileges = $privileges; |
|
65 | + $this->prefixBaseUrl = $prefixBaseUrl; |
|
66 | + |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Returns the list of privileges for this property |
|
71 | + * |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function getPrivileges() { |
|
75 | + |
|
76 | + return $this->privileges; |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * The xmlSerialize metod is called during xml writing. |
|
82 | + * |
|
83 | + * Use the $writer argument to write its own xml serialization. |
|
84 | + * |
|
85 | + * An important note: do _not_ create a parent element. Any element |
|
86 | + * implementing XmlSerializble should only ever write what's considered |
|
87 | + * its 'inner xml'. |
|
88 | + * |
|
89 | + * The parent of the current element is responsible for writing a |
|
90 | + * containing element. |
|
91 | + * |
|
92 | + * This allows serializers to be re-used for different element names. |
|
93 | + * |
|
94 | + * If you are opening new elements, you must also close them again. |
|
95 | + * |
|
96 | + * @param Writer $writer |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function xmlSerialize(Writer $writer) { |
|
100 | + |
|
101 | + foreach ($this->privileges as $ace) { |
|
102 | + |
|
103 | + $this->serializeAce($writer, $ace); |
|
104 | + |
|
105 | + } |
|
106 | + |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Generate html representation for this value. |
|
111 | + * |
|
112 | + * The html output is 100% trusted, and no effort is being made to sanitize |
|
113 | + * it. It's up to the implementor to sanitize user provided values. |
|
114 | + * |
|
115 | + * The output must be in UTF-8. |
|
116 | + * |
|
117 | + * The baseUri parameter is a url to the root of the application, and can |
|
118 | + * be used to construct local links. |
|
119 | + * |
|
120 | + * @param HtmlOutputHelper $html |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function toHtml(HtmlOutputHelper $html) { |
|
124 | + |
|
125 | + ob_start(); |
|
126 | + echo "<table>"; |
|
127 | + echo "<tr><th>Principal</th><th>Privilege</th><th></th></tr>"; |
|
128 | + foreach ($this->privileges as $privilege) { |
|
129 | + |
|
130 | + echo '<tr>'; |
|
131 | + // if it starts with a {, it's a special principal |
|
132 | + if ($privilege['principal'][0] === '{') { |
|
133 | + echo '<td>', $html->xmlName($privilege['principal']), '</td>'; |
|
134 | + } else { |
|
135 | + echo '<td>', $html->link($privilege['principal']), '</td>'; |
|
136 | + } |
|
137 | + echo '<td>', $html->xmlName($privilege['privilege']), '</td>'; |
|
138 | + echo '<td>'; |
|
139 | + if (!empty($privilege['protected'])) echo '(protected)'; |
|
140 | + echo '</td>'; |
|
141 | + echo '</tr>'; |
|
142 | + |
|
143 | + } |
|
144 | + echo "</table>"; |
|
145 | + return ob_get_clean(); |
|
146 | + |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * The deserialize method is called during xml parsing. |
|
151 | + * |
|
152 | + * This method is called statictly, this is because in theory this method |
|
153 | + * may be used as a type of constructor, or factory method. |
|
154 | + * |
|
155 | + * Often you want to return an instance of the current class, but you are |
|
156 | + * free to return other data as well. |
|
157 | + * |
|
158 | + * Important note 2: You are responsible for advancing the reader to the |
|
159 | + * next element. Not doing anything will result in a never-ending loop. |
|
160 | + * |
|
161 | + * If you just want to skip parsing for this element altogether, you can |
|
162 | + * just call $reader->next(); |
|
163 | + * |
|
164 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
165 | + * the next element. |
|
166 | + * |
|
167 | + * @param Reader $reader |
|
168 | + * @return mixed |
|
169 | + */ |
|
170 | + static function xmlDeserialize(Reader $reader) { |
|
171 | + |
|
172 | + $elementMap = [ |
|
173 | + '{DAV:}ace' => 'Sabre\Xml\Element\KeyValue', |
|
174 | + '{DAV:}privilege' => 'Sabre\Xml\Element\Elements', |
|
175 | + '{DAV:}principal' => 'Sabre\DAVACL\Xml\Property\Principal', |
|
176 | + ]; |
|
177 | + |
|
178 | + $privileges = []; |
|
179 | + |
|
180 | + foreach ((array)$reader->parseInnerTree($elementMap) as $element) { |
|
181 | + |
|
182 | + if ($element['name'] !== '{DAV:}ace') { |
|
183 | + continue; |
|
184 | + } |
|
185 | + $ace = $element['value']; |
|
186 | + |
|
187 | + if (empty($ace['{DAV:}principal'])) { |
|
188 | + throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element'); |
|
189 | + } |
|
190 | + $principal = $ace['{DAV:}principal']; |
|
191 | + |
|
192 | + switch ($principal->getType()) { |
|
193 | + case Principal::HREF : |
|
194 | + $principal = $principal->getHref(); |
|
195 | + break; |
|
196 | + case Principal::AUTHENTICATED : |
|
197 | + $principal = '{DAV:}authenticated'; |
|
198 | + break; |
|
199 | + case Principal::UNAUTHENTICATED : |
|
200 | + $principal = '{DAV:}unauthenticated'; |
|
201 | + break; |
|
202 | + case Principal::ALL : |
|
203 | + $principal = '{DAV:}all'; |
|
204 | + break; |
|
205 | + |
|
206 | + } |
|
207 | + |
|
208 | + $protected = array_key_exists('{DAV:}protected', $ace); |
|
209 | + |
|
210 | + if (!isset($ace['{DAV:}grant'])) { |
|
211 | + throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported'); |
|
212 | + } |
|
213 | + foreach ($ace['{DAV:}grant'] as $elem) { |
|
214 | + if ($elem['name'] !== '{DAV:}privilege') { |
|
215 | + continue; |
|
216 | + } |
|
217 | + |
|
218 | + foreach ($elem['value'] as $priv) { |
|
219 | + $privileges[] = [ |
|
220 | + 'principal' => $principal, |
|
221 | + 'protected' => $protected, |
|
222 | + 'privilege' => $priv, |
|
223 | + ]; |
|
224 | + } |
|
225 | + |
|
226 | + } |
|
227 | + |
|
228 | + } |
|
229 | + |
|
230 | + return new self($privileges); |
|
231 | + |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Serializes a single access control entry. |
|
236 | + * |
|
237 | + * @param Writer $writer |
|
238 | + * @param array $ace |
|
239 | + * @return void |
|
240 | + */ |
|
241 | + private function serializeAce(Writer $writer, array $ace) { |
|
242 | + |
|
243 | + $writer->startElement('{DAV:}ace'); |
|
244 | + |
|
245 | + switch ($ace['principal']) { |
|
246 | + case '{DAV:}authenticated' : |
|
247 | + $principal = new Principal(Principal::AUTHENTICATED); |
|
248 | + break; |
|
249 | + case '{DAV:}unauthenticated' : |
|
250 | + $principal = new Principal(Principal::UNAUTHENTICATED); |
|
251 | + break; |
|
252 | + case '{DAV:}all' : |
|
253 | + $principal = new Principal(Principal::ALL); |
|
254 | + break; |
|
255 | + default: |
|
256 | + $principal = new Principal(Principal::HREF, $ace['principal']); |
|
257 | + break; |
|
258 | + } |
|
259 | + |
|
260 | + $writer->writeElement('{DAV:}principal', $principal); |
|
261 | + $writer->startElement('{DAV:}grant'); |
|
262 | + $writer->startElement('{DAV:}privilege'); |
|
263 | + |
|
264 | + $writer->writeElement($ace['privilege']); |
|
265 | + |
|
266 | + $writer->endElement(); // privilege |
|
267 | + $writer->endElement(); // grant |
|
268 | + |
|
269 | + if (!empty($ace['protected'])) { |
|
270 | + $writer->writeElement('{DAV:}protected'); |
|
271 | + } |
|
272 | + |
|
273 | + $writer->endElement(); // ace |
|
274 | + |
|
275 | + } |
|
276 | 276 | |
277 | 277 | } |