Completed
Branch develop (fc1aaa)
by
unknown
18:31
created
htdocs/includes/restler/framework/Luracast/Restler/CommentParser.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -177,14 +177,14 @@
 block discarded – undo
177 177
 					break;
178 178
 				case 1 :
179 179
 					if ($addNewline) {
180
-						$line = ' ' . $line;
180
+						$line = ' '.$line;
181 181
 					}
182 182
 					$longDescription[] = $line;
183 183
 					break;
184 184
 				case 2 :
185 185
 					$newParam
186 186
 						? $params[] = $line
187
-						: $params[count($params) - 1] .= ' ' . $line;
187
+						: $params[count($params) - 1] .= ' '.$line;
188 188
 			}
189 189
 			$addNewline = false;
190 190
 		}
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/UI/Tags.php 3 patches
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -34,249 +34,249 @@
 block discarded – undo
34 34
  */
35 35
 class Tags implements ArrayAccess, Countable
36 36
 {
37
-    public static $humanReadable = true;
38
-    public static $initializer = null;
39
-    protected static $instances = array();
40
-    public $prefix = '';
41
-    public $indent = '    ';
42
-    public $tag;
43
-    protected $attributes = array();
44
-    protected $children = array();
45
-    protected $_parent;
37
+	public static $humanReadable = true;
38
+	public static $initializer = null;
39
+	protected static $instances = array();
40
+	public $prefix = '';
41
+	public $indent = '    ';
42
+	public $tag;
43
+	protected $attributes = array();
44
+	protected $children = array();
45
+	protected $_parent;
46 46
 
47
-    public function __construct($name = null, array $children = array())
48
-    {
49
-        $this->tag = $name;
50
-        $c = array();
51
-        foreach ($children as $child) {
52
-            is_array($child)
53
-                ? $c = array_merge($c, $child)
54
-                : $c [] = $child;
55
-        }
56
-        $this->markAsChildren($c);
57
-        $this->children = $c;
58
-        if (static::$initializer)
59
-            call_user_func_array(static::$initializer, array(& $this));
60
-    }
47
+	public function __construct($name = null, array $children = array())
48
+	{
49
+		$this->tag = $name;
50
+		$c = array();
51
+		foreach ($children as $child) {
52
+			is_array($child)
53
+				? $c = array_merge($c, $child)
54
+				: $c [] = $child;
55
+		}
56
+		$this->markAsChildren($c);
57
+		$this->children = $c;
58
+		if (static::$initializer)
59
+			call_user_func_array(static::$initializer, array(& $this));
60
+	}
61 61
 
62
-    /**
63
-     * Get Tag by id
64
-     *
65
-     * Retrieve a tag by its id attribute
66
-     *
67
-     * @param string $id
68
-     *
69
-     * @return Tags|null
70
-     */
71
-    public static function byId($id)
72
-    {
73
-        return Util::nestedValue(static::$instances, $id);
74
-    }
62
+	/**
63
+	 * Get Tag by id
64
+	 *
65
+	 * Retrieve a tag by its id attribute
66
+	 *
67
+	 * @param string $id
68
+	 *
69
+	 * @return Tags|null
70
+	 */
71
+	public static function byId($id)
72
+	{
73
+		return Util::nestedValue(static::$instances, $id);
74
+	}
75 75
 
76
-    /**
77
-     * @param       $name
78
-     * @param array $children
79
-     *
80
-     * @return Tags
81
-     */
82
-    public static function __callStatic($name, array $children)
83
-    {
84
-        return new static($name, $children);
85
-    }
76
+	/**
77
+	 * @param       $name
78
+	 * @param array $children
79
+	 *
80
+	 * @return Tags
81
+	 */
82
+	public static function __callStatic($name, array $children)
83
+	{
84
+		return new static($name, $children);
85
+	}
86 86
 
87
-    public function toString($prefix = '', $indent = '    ')
88
-    {
89
-        $this->prefix = $prefix;
90
-        $this->indent = $indent;
91
-        return $this->__toString();
92
-    }
87
+	public function toString($prefix = '', $indent = '    ')
88
+	{
89
+		$this->prefix = $prefix;
90
+		$this->indent = $indent;
91
+		return $this->__toString();
92
+	}
93 93
 
94
-    public function __toString()
95
-    {
96
-        $children = '';
97
-        if (static::$humanReadable) {
98
-            $lineBreak = false;
99
-            foreach ($this->children as $key => $child) {
100
-                $prefix = $this->prefix;
101
-                if (!is_null($this->tag))
102
-                    $prefix .= $this->indent;
103
-                if ($child instanceof $this) {
104
-                    $child->prefix = $prefix;
105
-                    $child->indent = $this->indent;
106
-                    $children .= PHP_EOL . $child;
107
-                    $lineBreak = true;
108
-                } else {
109
-                    $children .= $child;
110
-                }
111
-            }
112
-            if ($lineBreak)
113
-                $children .= PHP_EOL . $this->prefix;
114
-        } else {
115
-            $children = implode('', $this->children);
116
-        }
117
-        if (is_null($this->tag))
118
-            return $children;
119
-        $attributes = '';
120
-        foreach ($this->attributes as $attribute => &$value)
121
-            $attributes .= " $attribute=\"$value\"";
94
+	public function __toString()
95
+	{
96
+		$children = '';
97
+		if (static::$humanReadable) {
98
+			$lineBreak = false;
99
+			foreach ($this->children as $key => $child) {
100
+				$prefix = $this->prefix;
101
+				if (!is_null($this->tag))
102
+					$prefix .= $this->indent;
103
+				if ($child instanceof $this) {
104
+					$child->prefix = $prefix;
105
+					$child->indent = $this->indent;
106
+					$children .= PHP_EOL . $child;
107
+					$lineBreak = true;
108
+				} else {
109
+					$children .= $child;
110
+				}
111
+			}
112
+			if ($lineBreak)
113
+				$children .= PHP_EOL . $this->prefix;
114
+		} else {
115
+			$children = implode('', $this->children);
116
+		}
117
+		if (is_null($this->tag))
118
+			return $children;
119
+		$attributes = '';
120
+		foreach ($this->attributes as $attribute => &$value)
121
+			$attributes .= " $attribute=\"$value\"";
122 122
 
123
-        if (count($this->children))
124
-            return static::$humanReadable
125
-                ? "$this->prefix<{$this->tag}{$attributes}>"
126
-                . "$children"
127
-                . "</{$this->tag}>"
128
-                : "<{$this->tag}{$attributes}>$children</{$this->tag}>";
123
+		if (count($this->children))
124
+			return static::$humanReadable
125
+				? "$this->prefix<{$this->tag}{$attributes}>"
126
+				. "$children"
127
+				. "</{$this->tag}>"
128
+				: "<{$this->tag}{$attributes}>$children</{$this->tag}>";
129 129
 
130
-        return "$this->prefix<{$this->tag}{$attributes}/>";
131
-    }
130
+		return "$this->prefix<{$this->tag}{$attributes}/>";
131
+	}
132 132
 
133
-    public function toArray()
134
-    {
135
-        $r = array();
136
-        $r['attributes'] = $this->attributes;
137
-        $r['tag'] = $this->tag;
138
-        $children = array();
139
-        foreach ($this->children as $key => $child) {
140
-            $children[$key] = $child instanceof $this
141
-                ? $child->toArray()
142
-                : $child;
143
-        }
144
-        $r['children'] = $children;
145
-        return $r;
146
-    }
133
+	public function toArray()
134
+	{
135
+		$r = array();
136
+		$r['attributes'] = $this->attributes;
137
+		$r['tag'] = $this->tag;
138
+		$children = array();
139
+		foreach ($this->children as $key => $child) {
140
+			$children[$key] = $child instanceof $this
141
+				? $child->toArray()
142
+				: $child;
143
+		}
144
+		$r['children'] = $children;
145
+		return $r;
146
+	}
147 147
 
148
-    /**
149
-     * Set the id attribute of the current tag
150
-     *
151
-     * @param string $value
152
-     *
153
-     * @return string
154
-     */
155
-    public function id($value)
156
-    {
157
-        if (!empty($value) && is_string($value)) {
158
-            $this->attributes['id'] = $value;
159
-            static::$instances[$value] = $this;
160
-        }
161
-        return $this;
162
-    }
148
+	/**
149
+	 * Set the id attribute of the current tag
150
+	 *
151
+	 * @param string $value
152
+	 *
153
+	 * @return string
154
+	 */
155
+	public function id($value)
156
+	{
157
+		if (!empty($value) && is_string($value)) {
158
+			$this->attributes['id'] = $value;
159
+			static::$instances[$value] = $this;
160
+		}
161
+		return $this;
162
+	}
163 163
 
164
-    public function __get($name)
165
-    {
166
-        if ('parent' == $name)
167
-            return $this->_parent;
168
-        if (isset($this->attributes[$name]))
169
-            return $this->attributes[$name];
170
-        return;
171
-    }
164
+	public function __get($name)
165
+	{
166
+		if ('parent' == $name)
167
+			return $this->_parent;
168
+		if (isset($this->attributes[$name]))
169
+			return $this->attributes[$name];
170
+		return;
171
+	}
172 172
 
173
-    public function __set($name, $value)
174
-    {
175
-        if ('parent' == $name) {
176
-            if ($this->_parent) {
177
-                unset($this->_parent[array_search($this, $this->_parent->children)]);
178
-            }
179
-            if (!empty($value)) {
180
-                $value[] = $this;
181
-            }
182
-        }
183
-    }
173
+	public function __set($name, $value)
174
+	{
175
+		if ('parent' == $name) {
176
+			if ($this->_parent) {
177
+				unset($this->_parent[array_search($this, $this->_parent->children)]);
178
+			}
179
+			if (!empty($value)) {
180
+				$value[] = $this;
181
+			}
182
+		}
183
+	}
184 184
 
185
-    public function __isset($name)
186
-    {
187
-        return isset($this->attributes[$name]);
188
-    }
185
+	public function __isset($name)
186
+	{
187
+		return isset($this->attributes[$name]);
188
+	}
189 189
 
190
-    /**
191
-     * @param $attribute
192
-     * @param $value
193
-     *
194
-     * @return Tags
195
-     */
196
-    public function __call($attribute, $value)
197
-    {
198
-        if (is_null($value)) {
199
-            return isset($this->attributes[$attribute])
200
-                ? $this->attributes[$attribute]
201
-                : null;
202
-        }
203
-        $value = $value[0];
204
-        if (is_null($value)) {
205
-            unset($this->attributes[$attribute]);
206
-            return $this;
207
-        }
208
-        $this->attributes[$attribute] = is_bool($value)
209
-            ? ($value ? 'true' : 'false')
210
-            : @(string)$value;
211
-        return $this;
212
-    }
190
+	/**
191
+	 * @param $attribute
192
+	 * @param $value
193
+	 *
194
+	 * @return Tags
195
+	 */
196
+	public function __call($attribute, $value)
197
+	{
198
+		if (is_null($value)) {
199
+			return isset($this->attributes[$attribute])
200
+				? $this->attributes[$attribute]
201
+				: null;
202
+		}
203
+		$value = $value[0];
204
+		if (is_null($value)) {
205
+			unset($this->attributes[$attribute]);
206
+			return $this;
207
+		}
208
+		$this->attributes[$attribute] = is_bool($value)
209
+			? ($value ? 'true' : 'false')
210
+			: @(string)$value;
211
+		return $this;
212
+	}
213 213
 
214
-    public function offsetGet($index)
215
-    {
216
-        if ($this->offsetExists($index)) {
217
-            return $this->children[$index];
218
-        }
219
-        return false;
220
-    }
214
+	public function offsetGet($index)
215
+	{
216
+		if ($this->offsetExists($index)) {
217
+			return $this->children[$index];
218
+		}
219
+		return false;
220
+	}
221 221
 
222
-    public function offsetExists($index)
223
-    {
224
-        return isset($this->children[$index]);
225
-    }
222
+	public function offsetExists($index)
223
+	{
224
+		return isset($this->children[$index]);
225
+	}
226 226
 
227
-    public function offsetSet($index, $value)
228
-    {
229
-        if ($index) {
230
-            $this->children[$index] = $value;
231
-        } elseif (is_array($value)) {
232
-            $c = array();
233
-            foreach ($value as $child) {
234
-                is_array($child)
235
-                    ? $c = array_merge($c, $child)
236
-                    : $c [] = $child;
237
-            }
238
-            $this->markAsChildren($c);
239
-            $this->children += $c;
240
-        } else {
241
-            $c = array($value);
242
-            $this->markAsChildren($c);
243
-            $this->children[] = $value;
244
-        }
245
-        return true;
246
-    }
227
+	public function offsetSet($index, $value)
228
+	{
229
+		if ($index) {
230
+			$this->children[$index] = $value;
231
+		} elseif (is_array($value)) {
232
+			$c = array();
233
+			foreach ($value as $child) {
234
+				is_array($child)
235
+					? $c = array_merge($c, $child)
236
+					: $c [] = $child;
237
+			}
238
+			$this->markAsChildren($c);
239
+			$this->children += $c;
240
+		} else {
241
+			$c = array($value);
242
+			$this->markAsChildren($c);
243
+			$this->children[] = $value;
244
+		}
245
+		return true;
246
+	}
247 247
 
248
-    public function offsetUnset($index)
249
-    {
250
-        $this->children[$index]->_parent = null;
251
-        unset($this->children[$index]);
252
-        return true;
253
-    }
248
+	public function offsetUnset($index)
249
+	{
250
+		$this->children[$index]->_parent = null;
251
+		unset($this->children[$index]);
252
+		return true;
253
+	}
254 254
 
255
-    public function getContents()
256
-    {
257
-        return $this->children;
258
-    }
255
+	public function getContents()
256
+	{
257
+		return $this->children;
258
+	}
259 259
 
260
-    public function count()
261
-    {
262
-        return count($this->children);
263
-    }
260
+	public function count()
261
+	{
262
+		return count($this->children);
263
+	}
264 264
 
265
-    private function markAsChildren(& $children)
266
-    {
267
-        foreach ($children as $i => $child) {
268
-            if (is_string($child))
269
-                continue;
270
-            if (!is_object($child)) {
271
-                unset($children[$i]);
272
-                continue;
273
-            }
274
-            //echo $child;
275
-            if (isset($child->_parent) && $child->_parent != $this) {
276
-                //remove from current parent
277
-                unset($child->_parent[array_search($child, $child->_parent->children)]);
278
-            }
279
-            $child->_parent = $this;
280
-        }
281
-    }
265
+	private function markAsChildren(& $children)
266
+	{
267
+		foreach ($children as $i => $child) {
268
+			if (is_string($child))
269
+				continue;
270
+			if (!is_object($child)) {
271
+				unset($children[$i]);
272
+				continue;
273
+			}
274
+			//echo $child;
275
+			if (isset($child->_parent) && $child->_parent != $this) {
276
+				//remove from current parent
277
+				unset($child->_parent[array_search($child, $child->_parent->children)]);
278
+			}
279
+			$child->_parent = $this;
280
+		}
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
                 if ($child instanceof $this) {
104 104
                     $child->prefix = $prefix;
105 105
                     $child->indent = $this->indent;
106
-                    $children .= PHP_EOL . $child;
106
+                    $children .= PHP_EOL.$child;
107 107
                     $lineBreak = true;
108 108
                 } else {
109 109
                     $children .= $child;
110 110
                 }
111 111
             }
112 112
             if ($lineBreak)
113
-                $children .= PHP_EOL . $this->prefix;
113
+                $children .= PHP_EOL.$this->prefix;
114 114
         } else {
115 115
             $children = implode('', $this->children);
116 116
         }
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
         }
208 208
         $this->attributes[$attribute] = is_bool($value)
209 209
             ? ($value ? 'true' : 'false')
210
-            : @(string)$value;
210
+            : @(string) $value;
211 211
         return $this;
212 212
     }
213 213
 
Please login to merge, or discard this patch.
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -55,8 +55,9 @@  discard block
 block discarded – undo
55 55
         }
56 56
         $this->markAsChildren($c);
57 57
         $this->children = $c;
58
-        if (static::$initializer)
59
-            call_user_func_array(static::$initializer, array(& $this));
58
+        if (static::$initializer) {
59
+                    call_user_func_array(static::$initializer, array(& $this));
60
+        }
60 61
     }
61 62
 
62 63
     /**
@@ -98,8 +99,9 @@  discard block
 block discarded – undo
98 99
             $lineBreak = false;
99 100
             foreach ($this->children as $key => $child) {
100 101
                 $prefix = $this->prefix;
101
-                if (!is_null($this->tag))
102
-                    $prefix .= $this->indent;
102
+                if (!is_null($this->tag)) {
103
+                                    $prefix .= $this->indent;
104
+                }
103 105
                 if ($child instanceof $this) {
104 106
                     $child->prefix = $prefix;
105 107
                     $child->indent = $this->indent;
@@ -109,23 +111,27 @@  discard block
 block discarded – undo
109 111
                     $children .= $child;
110 112
                 }
111 113
             }
112
-            if ($lineBreak)
113
-                $children .= PHP_EOL . $this->prefix;
114
+            if ($lineBreak) {
115
+                            $children .= PHP_EOL . $this->prefix;
116
+            }
114 117
         } else {
115 118
             $children = implode('', $this->children);
116 119
         }
117
-        if (is_null($this->tag))
118
-            return $children;
120
+        if (is_null($this->tag)) {
121
+                    return $children;
122
+        }
119 123
         $attributes = '';
120
-        foreach ($this->attributes as $attribute => &$value)
121
-            $attributes .= " $attribute=\"$value\"";
124
+        foreach ($this->attributes as $attribute => &$value) {
125
+                    $attributes .= " $attribute=\"$value\"";
126
+        }
122 127
 
123
-        if (count($this->children))
124
-            return static::$humanReadable
128
+        if (count($this->children)) {
129
+                    return static::$humanReadable
125 130
                 ? "$this->prefix<{$this->tag}{$attributes}>"
126 131
                 . "$children"
127 132
                 . "</{$this->tag}>"
128 133
                 : "<{$this->tag}{$attributes}>$children</{$this->tag}>";
134
+        }
129 135
 
130 136
         return "$this->prefix<{$this->tag}{$attributes}/>";
131 137
     }
@@ -163,10 +169,12 @@  discard block
 block discarded – undo
163 169
 
164 170
     public function __get($name)
165 171
     {
166
-        if ('parent' == $name)
167
-            return $this->_parent;
168
-        if (isset($this->attributes[$name]))
169
-            return $this->attributes[$name];
172
+        if ('parent' == $name) {
173
+                    return $this->_parent;
174
+        }
175
+        if (isset($this->attributes[$name])) {
176
+                    return $this->attributes[$name];
177
+        }
170 178
         return;
171 179
     }
172 180
 
@@ -265,8 +273,9 @@  discard block
 block discarded – undo
265 273
     private function markAsChildren(& $children)
266 274
     {
267 275
         foreach ($children as $i => $child) {
268
-            if (is_string($child))
269
-                continue;
276
+            if (is_string($child)) {
277
+                            continue;
278
+            }
270 279
             if (!is_object($child)) {
271 280
                 unset($children[$i]);
272 281
                 continue;
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/UI/FormStyles.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -14,46 +14,46 @@
 block discarded – undo
14 14
  */
15 15
 class FormStyles
16 16
 {
17
-    public static $html = array(
18
-        'form' => 'form[role=form id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]',
19
-        'input' => '.row>section>label{$label#}^input[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]',
20
-        'textarea' => '.row>label{$label#}^textarea[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}',
21
-        'radio' => '.row>section>label{$label#}^span>label*options>input[id=$id# name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]+{ $text#}',
22
-        'select' => '.row>label{$label#}^select[id=$id# name=$name# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options',
23
-        'submit' => '.row>label{ &nbsp; }^button[id=$id# type=submit disabled=$disabled#]{$label#}',
24
-        'fieldset' => 'fieldset>legend{$label#}',
25
-        'checkbox' => '.row>label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# accept=$accept# disabled=$disabled#]+{$label#}',
26
-        //------------- TYPE BASED STYLES ---------------------//
27
-        'checkbox-array' => 'fieldset>legend{$label#}+section*options>label>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# accept=$accept#]+{ $text#}',
28
-        'select-array' => 'label{$label#}+select[name=$name# required=$required# multiple style="height: auto;background-image: none; outline: inherit;"]>option[value=$value# selected=$selected#]{$text#}*options',
29
-    );
30
-    public static $bootstrap3 = array(
31
-        'form' => 'form[role=form id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]',
32
-        'input' => '.form-group.$error#>label{$label#}+input.form-control[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]+small.help-block>{$message#}',
33
-        'textarea' => '.form-group>label{$label#}+textarea.form-control[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}+small.help-block>{$message#}',
34
-        'radio' => 'fieldset>legend{$label#}>.radio*options>label>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]{$text#}+p.help-block>{$message#}',
35
-        'select' => '.form-group>label{$label#}+select.form-control[id=$id# name=$name# multiple=$multiple# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options',
36
-        'submit' => 'button.btn.btn-primary[id=$id# type=submit]{$label#} disabled=$disabled#',
37
-        'fieldset' => 'fieldset>legend{$label#}',
38
-        'checkbox' => '.checkbox>label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# disabled=$disabled#]+{$label#}^p.help-block>{$error#}',
39
-        //------------- TYPE BASED STYLES ---------------------//
40
-        'checkbox-array' => 'fieldset>legend{$label#}>.checkbox*options>label>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required#]{$text#}',
41
-        'select-array' => '.form-group>label{$label#}+select.form-control[name=$name# multiple=$multiple# required=$required#] size=$options#>option[value=$value# selected=$selected#]{$text#}*options',
42
-        //------------- CUSTOM STYLES ---------------------//
43
-        'radio-inline' => '.form-group>label{$label# : &nbsp;}+label.radio-inline*options>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required#]+{$text#}',
44
-    );
45
-    public static $foundation5 = array(
46
-        'form' => 'form[id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]',
47
-        'input' => 'label{$label#}+input[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]',
48
-        'textarea' => 'label{$label#}+textarea[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}',
49
-        'radio' => 'label{$label# : &nbsp;}+label.radio-inline*options>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]+{$text#}',
50
-        'select' => 'label{$label#}+select[id=$id# name=$name# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options',
51
-        'submit' => 'button.button[id=$id# type=submit disabled=$disabled#]{$label#}',
52
-        'fieldset' => 'fieldset>legend{$label#}',
53
-        'checkbox' => 'label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# disabled=$disabled#]+{ $label#}',
54
-        //------------- TYPE BASED STYLES ---------------------//
55
-        'checkbox-array' => 'fieldset>legend{$label#}+label*options>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus#]+{ $text#}',
56
-        'select-array' => 'label{$label#}+select[name=$name# required=$required# multiple style="height: auto;background-image: none; outline: inherit;"]>option[value=$value# selected=$selected#]{$text#}*options',
57
-        //------------- CUSTOM STYLES ---------------------//
58
-    );
17
+	public static $html = array(
18
+		'form' => 'form[role=form id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]',
19
+		'input' => '.row>section>label{$label#}^input[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]',
20
+		'textarea' => '.row>label{$label#}^textarea[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}',
21
+		'radio' => '.row>section>label{$label#}^span>label*options>input[id=$id# name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]+{ $text#}',
22
+		'select' => '.row>label{$label#}^select[id=$id# name=$name# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options',
23
+		'submit' => '.row>label{ &nbsp; }^button[id=$id# type=submit disabled=$disabled#]{$label#}',
24
+		'fieldset' => 'fieldset>legend{$label#}',
25
+		'checkbox' => '.row>label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# accept=$accept# disabled=$disabled#]+{$label#}',
26
+		//------------- TYPE BASED STYLES ---------------------//
27
+		'checkbox-array' => 'fieldset>legend{$label#}+section*options>label>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# accept=$accept#]+{ $text#}',
28
+		'select-array' => 'label{$label#}+select[name=$name# required=$required# multiple style="height: auto;background-image: none; outline: inherit;"]>option[value=$value# selected=$selected#]{$text#}*options',
29
+	);
30
+	public static $bootstrap3 = array(
31
+		'form' => 'form[role=form id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]',
32
+		'input' => '.form-group.$error#>label{$label#}+input.form-control[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]+small.help-block>{$message#}',
33
+		'textarea' => '.form-group>label{$label#}+textarea.form-control[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}+small.help-block>{$message#}',
34
+		'radio' => 'fieldset>legend{$label#}>.radio*options>label>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]{$text#}+p.help-block>{$message#}',
35
+		'select' => '.form-group>label{$label#}+select.form-control[id=$id# name=$name# multiple=$multiple# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options',
36
+		'submit' => 'button.btn.btn-primary[id=$id# type=submit]{$label#} disabled=$disabled#',
37
+		'fieldset' => 'fieldset>legend{$label#}',
38
+		'checkbox' => '.checkbox>label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# disabled=$disabled#]+{$label#}^p.help-block>{$error#}',
39
+		//------------- TYPE BASED STYLES ---------------------//
40
+		'checkbox-array' => 'fieldset>legend{$label#}>.checkbox*options>label>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required#]{$text#}',
41
+		'select-array' => '.form-group>label{$label#}+select.form-control[name=$name# multiple=$multiple# required=$required#] size=$options#>option[value=$value# selected=$selected#]{$text#}*options',
42
+		//------------- CUSTOM STYLES ---------------------//
43
+		'radio-inline' => '.form-group>label{$label# : &nbsp;}+label.radio-inline*options>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required#]+{$text#}',
44
+	);
45
+	public static $foundation5 = array(
46
+		'form' => 'form[id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]',
47
+		'input' => 'label{$label#}+input[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]',
48
+		'textarea' => 'label{$label#}+textarea[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}',
49
+		'radio' => 'label{$label# : &nbsp;}+label.radio-inline*options>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]+{$text#}',
50
+		'select' => 'label{$label#}+select[id=$id# name=$name# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options',
51
+		'submit' => 'button.button[id=$id# type=submit disabled=$disabled#]{$label#}',
52
+		'fieldset' => 'fieldset>legend{$label#}',
53
+		'checkbox' => 'label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# disabled=$disabled#]+{ $label#}',
54
+		//------------- TYPE BASED STYLES ---------------------//
55
+		'checkbox-array' => 'fieldset>legend{$label#}+label*options>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus#]+{ $text#}',
56
+		'select-array' => 'label{$label#}+select[name=$name# required=$required# multiple style="height: auto;background-image: none; outline: inherit;"]>option[value=$value# selected=$selected#]{$text#}*options',
57
+		//------------- CUSTOM STYLES ---------------------//
58
+	);
59 59
 }
60 60
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/UI/Nav.php 3 patches
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -23,201 +23,201 @@
 block discarded – undo
23 23
  */
24 24
 class Nav
25 25
 {
26
-    protected static $tree = array();
27
-    public static $root = 'home';
26
+	protected static $tree = array();
27
+	public static $root = 'home';
28 28
 
29
-    /**
30
-     * @var array all paths beginning with any of the following will be excluded
31
-     * from documentation. if an empty string is given it will exclude the root
32
-     */
33
-    public static $excludedPaths = array('');
34
-    /**
35
-     * @var array prefix additional menu items with one of the following syntax
36
-     *            [$path => $text]
37
-     *            [$path]
38
-     *            [$path => ['text' => $text, 'url' => $url, 'trail'=> $trail]]
39
-     */
40
-    public static $prepends = array();
41
-    /**
42
-     * @var array suffix additional menu items with one of the following syntax
43
-     *            [$path => $text]
44
-     *            [$path]
45
-     *            [$path => ['text' => $text, 'url' => $url, 'trail'=> $trail]]
46
-     */
47
-    public static $appends = array();
29
+	/**
30
+	 * @var array all paths beginning with any of the following will be excluded
31
+	 * from documentation. if an empty string is given it will exclude the root
32
+	 */
33
+	public static $excludedPaths = array('');
34
+	/**
35
+	 * @var array prefix additional menu items with one of the following syntax
36
+	 *            [$path => $text]
37
+	 *            [$path]
38
+	 *            [$path => ['text' => $text, 'url' => $url, 'trail'=> $trail]]
39
+	 */
40
+	public static $prepends = array();
41
+	/**
42
+	 * @var array suffix additional menu items with one of the following syntax
43
+	 *            [$path => $text]
44
+	 *            [$path]
45
+	 *            [$path => ['text' => $text, 'url' => $url, 'trail'=> $trail]]
46
+	 */
47
+	public static $appends = array();
48 48
 
49
-    public static $addExtension = true;
49
+	public static $addExtension = true;
50 50
 
51
-    protected static $extension = '';
52
-    protected static $activeTrail = '';
53
-    protected static $url;
51
+	protected static $extension = '';
52
+	protected static $activeTrail = '';
53
+	protected static $url;
54 54
 
55
-    public static function get($for = '', $activeTrail = null)
56
-    {
57
-        if (empty(static::$tree)) {
58
-            /** @var Restler $restler */
59
-            $restler = Scope::get('Restler');
60
-            if (static::$addExtension)
61
-                static::$extension = isset($restler->responseFormat)
62
-                    ? '.' . $restler->responseFormat->getExtension()
63
-                    : '.html';
64
-            static::$url = $restler->getBaseUrl();
65
-            if (empty(static::$url))
66
-                static::$url = '';
67
-            static::$activeTrail = $activeTrail = empty($activeTrail)
68
-                ? (empty($restler->url) || $restler->url == 'index'
69
-                    ? static::$root
70
-                    : $restler->url
71
-                )
72
-                : $activeTrail;
73
-            if (static::$addExtension)
74
-                static::$extension = isset($restler->responseFormat)
75
-                    ? '.' . $restler->responseFormat->getExtension()
76
-                    : '.html';
77
-            static::addUrls(static::$prepends);
78
-            $map = Routes::findAll(
79
-                static::$excludedPaths,
80
-                array('POST', 'DELETE', 'PUT', 'PATCH'),
81
-                $restler->getRequestedApiVersion()
82
-            );
83
-            foreach ($map as $path => $data) {
84
-                foreach ($data as $item) {
85
-                    $access = $item['access'];
86
-                    $route = $item['route'];
87
-                    $url = $route['url'];
88
-                    if ($access && !Text::contains($url, '{')) {
89
-                        $label = Util::nestedValue(
90
-                            $route,
91
-                            'metadata',
92
-                            CommentParser::$embeddedDataName,
93
-                            'label'
94
-                        );
95
-                        if (!empty($url)) {
96
-                            $url .= static::$extension;
97
-                        }
98
-                        static::add($url, $label);
99
-                    }
100
-                }
101
-            }
102
-            static::addUrls(static::$appends);
103
-        } elseif (empty($activeTrail)) {
104
-            $activeTrail = static::$activeTrail;
105
-        }
106
-        $tree = static::$tree;
107
-        $activeTrail = explode('/', $activeTrail);
108
-        $nested = & static::nested($tree, $activeTrail);
109
-        if (is_array($nested)) {
110
-            $nested['active'] = true;
111
-        }
112
-        if (!empty($for)) {
113
-            $for = explode('/', $for);
114
-            $tree = static::nested($tree, $for)['children'];
115
-        }
116
-        return array_filter($tree);
117
-    }
55
+	public static function get($for = '', $activeTrail = null)
56
+	{
57
+		if (empty(static::$tree)) {
58
+			/** @var Restler $restler */
59
+			$restler = Scope::get('Restler');
60
+			if (static::$addExtension)
61
+				static::$extension = isset($restler->responseFormat)
62
+					? '.' . $restler->responseFormat->getExtension()
63
+					: '.html';
64
+			static::$url = $restler->getBaseUrl();
65
+			if (empty(static::$url))
66
+				static::$url = '';
67
+			static::$activeTrail = $activeTrail = empty($activeTrail)
68
+				? (empty($restler->url) || $restler->url == 'index'
69
+					? static::$root
70
+					: $restler->url
71
+				)
72
+				: $activeTrail;
73
+			if (static::$addExtension)
74
+				static::$extension = isset($restler->responseFormat)
75
+					? '.' . $restler->responseFormat->getExtension()
76
+					: '.html';
77
+			static::addUrls(static::$prepends);
78
+			$map = Routes::findAll(
79
+				static::$excludedPaths,
80
+				array('POST', 'DELETE', 'PUT', 'PATCH'),
81
+				$restler->getRequestedApiVersion()
82
+			);
83
+			foreach ($map as $path => $data) {
84
+				foreach ($data as $item) {
85
+					$access = $item['access'];
86
+					$route = $item['route'];
87
+					$url = $route['url'];
88
+					if ($access && !Text::contains($url, '{')) {
89
+						$label = Util::nestedValue(
90
+							$route,
91
+							'metadata',
92
+							CommentParser::$embeddedDataName,
93
+							'label'
94
+						);
95
+						if (!empty($url)) {
96
+							$url .= static::$extension;
97
+						}
98
+						static::add($url, $label);
99
+					}
100
+				}
101
+			}
102
+			static::addUrls(static::$appends);
103
+		} elseif (empty($activeTrail)) {
104
+			$activeTrail = static::$activeTrail;
105
+		}
106
+		$tree = static::$tree;
107
+		$activeTrail = explode('/', $activeTrail);
108
+		$nested = & static::nested($tree, $activeTrail);
109
+		if (is_array($nested)) {
110
+			$nested['active'] = true;
111
+		}
112
+		if (!empty($for)) {
113
+			$for = explode('/', $for);
114
+			$tree = static::nested($tree, $for)['children'];
115
+		}
116
+		return array_filter($tree);
117
+	}
118 118
 
119
-    protected static function & nested(array & $tree, array $parts)
120
-    {
121
-        if (!empty($parts)) {
122
-            $part = array_shift($parts);
123
-            if (empty($tree[$part])) {
124
-                return $tree[$part];
125
-            } elseif (empty($parts)) {
126
-                return static::nested($tree[$part], $parts);
127
-            } elseif (!empty($tree[$part]['children'])) {
128
-                return static::nested($tree[$part]['children'], $parts);
129
-            }
130
-        } else {
131
-            return $tree;
132
-        }
133
-        $value = null;
134
-        return $value;
135
-    }
119
+	protected static function & nested(array & $tree, array $parts)
120
+	{
121
+		if (!empty($parts)) {
122
+			$part = array_shift($parts);
123
+			if (empty($tree[$part])) {
124
+				return $tree[$part];
125
+			} elseif (empty($parts)) {
126
+				return static::nested($tree[$part], $parts);
127
+			} elseif (!empty($tree[$part]['children'])) {
128
+				return static::nested($tree[$part]['children'], $parts);
129
+			}
130
+		} else {
131
+			return $tree;
132
+		}
133
+		$value = null;
134
+		return $value;
135
+	}
136 136
 
137
-    public static function addUrls(array $urls)
138
-    {
139
-        foreach ($urls as $url => $label) {
140
-            $trail = null;
141
-            if (is_array($label)) {
142
-                if (isset($label['trail'])) {
143
-                    $trail = $label['trail'];
144
-                }
145
-                if (isset($label['url'])) {
146
-                    $url = $label['url'];
147
-                    $label = isset($label['label']) ? $label['label'] : null;
148
-                } else {
149
-                    $url = current(array_keys($label));
150
-                    $label = current($label);
151
-                }
137
+	public static function addUrls(array $urls)
138
+	{
139
+		foreach ($urls as $url => $label) {
140
+			$trail = null;
141
+			if (is_array($label)) {
142
+				if (isset($label['trail'])) {
143
+					$trail = $label['trail'];
144
+				}
145
+				if (isset($label['url'])) {
146
+					$url = $label['url'];
147
+					$label = isset($label['label']) ? $label['label'] : null;
148
+				} else {
149
+					$url = current(array_keys($label));
150
+					$label = current($label);
151
+				}
152 152
 
153
-            }
154
-            if (is_numeric($url)) {
155
-                $url = $label;
156
-                $label = null;
157
-            }
158
-            static::add($url, $label, $trail);
159
-        }
160
-        return static::$tree;
161
-    }
153
+			}
154
+			if (is_numeric($url)) {
155
+				$url = $label;
156
+				$label = null;
157
+			}
158
+			static::add($url, $label, $trail);
159
+		}
160
+		return static::$tree;
161
+	}
162 162
 
163
-    public static function add($url, $label = null, $trail = null)
164
-    {
165
-        $r = parse_url($url);
166
-        if (is_null($trail)) {
167
-            $trail = isset($r['path']) ? $r['path'] : static::$root;
168
-        }
169
-        //remove / prefix and / suffixes and any extension
170
-        $trail = strtok(trim($trail, '/'), '.');
171
-        $parts = explode('/', $trail);
172
-        if (count($parts) == 1 && empty($parts[0]))
173
-            $parts = array(static::$root);
174
-        if (isset($r['fragment'])) {
175
-            $parts[] = $r['fragment'];
176
-            if (is_null($label)) {
177
-                $label = Text::title($r['fragment']);
178
-            }
179
-        }
180
-        if (empty($r['scheme'])) {
181
-            //relative url found
182
-            if (empty($url)) {
183
-                $label = Text::title(static::$root);
184
-                $url = static::$url;
185
-            } else {
186
-                $url = static::$url . '/' . ltrim($url, '/');
187
-            }
188
-        }
189
-        if (is_null($label)) {
190
-            $label = Text::title(strtok(end($parts), '.'));
191
-        }
192
-        $r['url'] = $url;
193
-        $r['path'] = $trail;
194
-        $r['parts'] = $parts;
195
-        $r['label'] = $label;
196
-        static::build($r);
197
-        return $r;
198
-    }
163
+	public static function add($url, $label = null, $trail = null)
164
+	{
165
+		$r = parse_url($url);
166
+		if (is_null($trail)) {
167
+			$trail = isset($r['path']) ? $r['path'] : static::$root;
168
+		}
169
+		//remove / prefix and / suffixes and any extension
170
+		$trail = strtok(trim($trail, '/'), '.');
171
+		$parts = explode('/', $trail);
172
+		if (count($parts) == 1 && empty($parts[0]))
173
+			$parts = array(static::$root);
174
+		if (isset($r['fragment'])) {
175
+			$parts[] = $r['fragment'];
176
+			if (is_null($label)) {
177
+				$label = Text::title($r['fragment']);
178
+			}
179
+		}
180
+		if (empty($r['scheme'])) {
181
+			//relative url found
182
+			if (empty($url)) {
183
+				$label = Text::title(static::$root);
184
+				$url = static::$url;
185
+			} else {
186
+				$url = static::$url . '/' . ltrim($url, '/');
187
+			}
188
+		}
189
+		if (is_null($label)) {
190
+			$label = Text::title(strtok(end($parts), '.'));
191
+		}
192
+		$r['url'] = $url;
193
+		$r['path'] = $trail;
194
+		$r['parts'] = $parts;
195
+		$r['label'] = $label;
196
+		static::build($r);
197
+		return $r;
198
+	}
199 199
 
200
-    public static function build(array $r)
201
-    {
202
-        $p = & static::$tree;
203
-        $parts = $r['parts'];
204
-        $last = count($parts) - 1;
205
-        foreach ($parts as $i => $part) {
206
-            if ($i == $last) {
207
-                $p[$part]['text'] = $r['label'];
208
-                $p[$part]['href'] = $r['url'];
209
-                $p[$part]['class'] = Text::slug($part);
210
-                /* dynamically do it at run time instead
200
+	public static function build(array $r)
201
+	{
202
+		$p = & static::$tree;
203
+		$parts = $r['parts'];
204
+		$last = count($parts) - 1;
205
+		foreach ($parts as $i => $part) {
206
+			if ($i == $last) {
207
+				$p[$part]['text'] = $r['label'];
208
+				$p[$part]['href'] = $r['url'];
209
+				$p[$part]['class'] = Text::slug($part);
210
+				/* dynamically do it at run time instead
211 211
                 if ($r['path'] == static::$activeTrail)
212 212
                     $p[$part]['active'] = true;
213 213
                 */
214
-            } elseif (!isset($p[$part])) {
215
-                $p[$part] = array();
216
-                $p[$part]['text'] = Text::title($part);
217
-                $p[$part]['href'] = '#';
218
-                $p[$part]['children'] = array();
219
-            }
220
-            $p = & $p[$part]['children'];
221
-        }
222
-    }
214
+			} elseif (!isset($p[$part])) {
215
+				$p[$part] = array();
216
+				$p[$part]['text'] = Text::title($part);
217
+				$p[$part]['href'] = '#';
218
+				$p[$part]['children'] = array();
219
+			}
220
+			$p = & $p[$part]['children'];
221
+		}
222
+	}
223 223
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             $restler = Scope::get('Restler');
60 60
             if (static::$addExtension)
61 61
                 static::$extension = isset($restler->responseFormat)
62
-                    ? '.' . $restler->responseFormat->getExtension()
62
+                    ? '.'.$restler->responseFormat->getExtension()
63 63
                     : '.html';
64 64
             static::$url = $restler->getBaseUrl();
65 65
             if (empty(static::$url))
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
                 : $activeTrail;
73 73
             if (static::$addExtension)
74 74
                 static::$extension = isset($restler->responseFormat)
75
-                    ? '.' . $restler->responseFormat->getExtension()
75
+                    ? '.'.$restler->responseFormat->getExtension()
76 76
                     : '.html';
77 77
             static::addUrls(static::$prepends);
78 78
             $map = Routes::findAll(
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
                 $label = Text::title(static::$root);
184 184
                 $url = static::$url;
185 185
             } else {
186
-                $url = static::$url . '/' . ltrim($url, '/');
186
+                $url = static::$url.'/'.ltrim($url, '/');
187 187
             }
188 188
         }
189 189
         if (is_null($label)) {
Please login to merge, or discard this patch.
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -57,23 +57,26 @@  discard block
 block discarded – undo
57 57
         if (empty(static::$tree)) {
58 58
             /** @var Restler $restler */
59 59
             $restler = Scope::get('Restler');
60
-            if (static::$addExtension)
61
-                static::$extension = isset($restler->responseFormat)
60
+            if (static::$addExtension) {
61
+                            static::$extension = isset($restler->responseFormat)
62 62
                     ? '.' . $restler->responseFormat->getExtension()
63 63
                     : '.html';
64
+            }
64 65
             static::$url = $restler->getBaseUrl();
65
-            if (empty(static::$url))
66
-                static::$url = '';
66
+            if (empty(static::$url)) {
67
+                            static::$url = '';
68
+            }
67 69
             static::$activeTrail = $activeTrail = empty($activeTrail)
68 70
                 ? (empty($restler->url) || $restler->url == 'index'
69 71
                     ? static::$root
70 72
                     : $restler->url
71 73
                 )
72 74
                 : $activeTrail;
73
-            if (static::$addExtension)
74
-                static::$extension = isset($restler->responseFormat)
75
+            if (static::$addExtension) {
76
+                            static::$extension = isset($restler->responseFormat)
75 77
                     ? '.' . $restler->responseFormat->getExtension()
76 78
                     : '.html';
79
+            }
77 80
             static::addUrls(static::$prepends);
78 81
             $map = Routes::findAll(
79 82
                 static::$excludedPaths,
@@ -169,8 +172,9 @@  discard block
 block discarded – undo
169 172
         //remove / prefix and / suffixes and any extension
170 173
         $trail = strtok(trim($trail, '/'), '.');
171 174
         $parts = explode('/', $trail);
172
-        if (count($parts) == 1 && empty($parts[0]))
173
-            $parts = array(static::$root);
175
+        if (count($parts) == 1 && empty($parts[0])) {
176
+                    $parts = array(static::$root);
177
+        }
174 178
         if (isset($r['fragment'])) {
175 179
             $parts[] = $r['fragment'];
176 180
             if (is_null($label)) {
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/UI/Forms.php 2 patches
Indentation   +428 added lines, -428 removed lines patch added patch discarded remove patch
@@ -34,453 +34,453 @@
 block discarded – undo
34 34
  */
35 35
 class Forms implements iFilter
36 36
 {
37
-    const FORM_KEY = 'form_key';
38
-    public static $filterFormRequestsOnly = false;
37
+	const FORM_KEY = 'form_key';
38
+	public static $filterFormRequestsOnly = false;
39 39
 
40
-    public static $excludedPaths = array();
40
+	public static $excludedPaths = array();
41 41
 
42
-    private static $style;
43
-    /**
44
-     * @var bool should we fill up the form using given data?
45
-     */
46
-    public static $preFill = true;
47
-    /**
48
-     * @var ValidationInfo
49
-     */
50
-    public static $validationInfo = null;
51
-    protected static $inputTypes = array(
52
-        'hidden',
53
-        'password',
54
-        'button',
55
-        'image',
56
-        'file',
57
-        'reset',
58
-        'submit',
59
-        'search',
60
-        'checkbox',
61
-        'radio',
62
-        'email',
63
-        'text',
64
-        'color',
65
-        'date',
66
-        'datetime',
67
-        'datetime-local',
68
-        'email',
69
-        'month',
70
-        'number',
71
-        'range',
72
-        'search',
73
-        'tel',
74
-        'time',
75
-        'url',
76
-        'week',
77
-    );
78
-    protected static $fileUpload = false;
79
-    private static $key = array();
80
-    /**
81
-     * @var ApiMethodInfo;
82
-     */
83
-    private static $info;
42
+	private static $style;
43
+	/**
44
+	 * @var bool should we fill up the form using given data?
45
+	 */
46
+	public static $preFill = true;
47
+	/**
48
+	 * @var ValidationInfo
49
+	 */
50
+	public static $validationInfo = null;
51
+	protected static $inputTypes = array(
52
+		'hidden',
53
+		'password',
54
+		'button',
55
+		'image',
56
+		'file',
57
+		'reset',
58
+		'submit',
59
+		'search',
60
+		'checkbox',
61
+		'radio',
62
+		'email',
63
+		'text',
64
+		'color',
65
+		'date',
66
+		'datetime',
67
+		'datetime-local',
68
+		'email',
69
+		'month',
70
+		'number',
71
+		'range',
72
+		'search',
73
+		'tel',
74
+		'time',
75
+		'url',
76
+		'week',
77
+	);
78
+	protected static $fileUpload = false;
79
+	private static $key = array();
80
+	/**
81
+	 * @var ApiMethodInfo;
82
+	 */
83
+	private static $info;
84 84
 
85
-    public static function setStyles(HtmlForm $style)
86
-    {
87
-        static::$style = get_class($style);
88
-    }
85
+	public static function setStyles(HtmlForm $style)
86
+	{
87
+		static::$style = get_class($style);
88
+	}
89 89
 
90
-    /**
91
-     * Get the form
92
-     *
93
-     * @param string $method   http method to submit the form
94
-     * @param string $action   relative path from the web root. When set to null
95
-     *                         it uses the current api method's path
96
-     * @param bool   $dataOnly if you want to render the form yourself use this
97
-     *                         option
98
-     * @param string $prefix   used for adjusting the spacing in front of
99
-     *                         form elements
100
-     * @param string $indent   used for adjusting indentation
101
-     *
102
-     * @return array|T
103
-     *
104
-     * @throws RestException
105
-     */
106
-    public static function get($method = 'POST', $action = null, $dataOnly = false, $prefix = '', $indent = '    ')
107
-    {
108
-        if (!static::$style) {
109
-            static::$style = 'Luracast\\Restler\\UI\HtmlForm';
110
-        }
90
+	/**
91
+	 * Get the form
92
+	 *
93
+	 * @param string $method   http method to submit the form
94
+	 * @param string $action   relative path from the web root. When set to null
95
+	 *                         it uses the current api method's path
96
+	 * @param bool   $dataOnly if you want to render the form yourself use this
97
+	 *                         option
98
+	 * @param string $prefix   used for adjusting the spacing in front of
99
+	 *                         form elements
100
+	 * @param string $indent   used for adjusting indentation
101
+	 *
102
+	 * @return array|T
103
+	 *
104
+	 * @throws RestException
105
+	 */
106
+	public static function get($method = 'POST', $action = null, $dataOnly = false, $prefix = '', $indent = '    ')
107
+	{
108
+		if (!static::$style) {
109
+			static::$style = 'Luracast\\Restler\\UI\HtmlForm';
110
+		}
111 111
 
112
-        try {
113
-            /** @var Restler $restler */
114
-            $restler = Scope::get('Restler');
115
-            if (is_null($action)) {
116
-                $action = $restler->url;
117
-            }
112
+		try {
113
+			/** @var Restler $restler */
114
+			$restler = Scope::get('Restler');
115
+			if (is_null($action)) {
116
+				$action = $restler->url;
117
+			}
118 118
 
119
-            $info = $restler->url == $action
120
-            && Util::getRequestMethod() == $method
121
-                ? $restler->apiMethodInfo
122
-                : Routes::find(
123
-                    trim($action, '/'),
124
-                    $method,
125
-                    $restler->getRequestedApiVersion(),
126
-                    static::$preFill ||
127
-                    ($restler->requestMethod == $method &&
128
-                        $restler->url == $action)
129
-                        ? $restler->getRequestData()
130
-                        : array()
131
-                );
119
+			$info = $restler->url == $action
120
+			&& Util::getRequestMethod() == $method
121
+				? $restler->apiMethodInfo
122
+				: Routes::find(
123
+					trim($action, '/'),
124
+					$method,
125
+					$restler->getRequestedApiVersion(),
126
+					static::$preFill ||
127
+					($restler->requestMethod == $method &&
128
+						$restler->url == $action)
129
+						? $restler->getRequestData()
130
+						: array()
131
+				);
132 132
 
133
-        } catch (RestException $e) {
134
-            //echo $e->getErrorMessage();
135
-            $info = false;
136
-        }
137
-        if (!$info) {
138
-            throw new RestException(500, 'invalid action path for form `' . $method . ' ' . $action . '`');
139
-        }
140
-        static::$info = $info;
141
-        $m = $info->metadata;
142
-        $r = static::fields($dataOnly);
143
-        if ($method != 'GET' && $method != 'POST') {
144
-            if (empty(Defaults::$httpMethodOverrideProperty)) {
145
-                throw new RestException(
146
-                    500,
147
-                    'Forms require `Defaults::\$httpMethodOverrideProperty`' .
148
-                    "for supporting HTTP $method"
149
-                );
150
-            }
151
-            if ($dataOnly) {
152
-                $r[] = array(
153
-                    'tag'   => 'input',
154
-                    'name'  => Defaults::$httpMethodOverrideProperty,
155
-                    'type'  => 'hidden',
156
-                    'value' => 'method',
157
-                );
158
-            } else {
159
-                $r[] = T::input()
160
-                    ->name(Defaults::$httpMethodOverrideProperty)
161
-                    ->value($method)
162
-                    ->type('hidden');
163
-            }
133
+		} catch (RestException $e) {
134
+			//echo $e->getErrorMessage();
135
+			$info = false;
136
+		}
137
+		if (!$info) {
138
+			throw new RestException(500, 'invalid action path for form `' . $method . ' ' . $action . '`');
139
+		}
140
+		static::$info = $info;
141
+		$m = $info->metadata;
142
+		$r = static::fields($dataOnly);
143
+		if ($method != 'GET' && $method != 'POST') {
144
+			if (empty(Defaults::$httpMethodOverrideProperty)) {
145
+				throw new RestException(
146
+					500,
147
+					'Forms require `Defaults::\$httpMethodOverrideProperty`' .
148
+					"for supporting HTTP $method"
149
+				);
150
+			}
151
+			if ($dataOnly) {
152
+				$r[] = array(
153
+					'tag'   => 'input',
154
+					'name'  => Defaults::$httpMethodOverrideProperty,
155
+					'type'  => 'hidden',
156
+					'value' => 'method',
157
+				);
158
+			} else {
159
+				$r[] = T::input()
160
+					->name(Defaults::$httpMethodOverrideProperty)
161
+					->value($method)
162
+					->type('hidden');
163
+			}
164 164
 
165
-            $method = 'POST';
166
-        }
167
-        if (session_id() != '') {
168
-            $form_key = static::key($method, $action);
169
-            if ($dataOnly) {
170
-                $r[] = array(
171
-                    'tag'   => 'input',
172
-                    'name'  => static::FORM_KEY,
173
-                    'type'  => 'hidden',
174
-                    'value' => 'hidden',
175
-                );
176
-            } else {
177
-                $key = T::input()
178
-                    ->name(static::FORM_KEY)
179
-                    ->type('hidden')
180
-                    ->value($form_key);
181
-                $r[] = $key;
182
-            }
183
-        }
165
+			$method = 'POST';
166
+		}
167
+		if (session_id() != '') {
168
+			$form_key = static::key($method, $action);
169
+			if ($dataOnly) {
170
+				$r[] = array(
171
+					'tag'   => 'input',
172
+					'name'  => static::FORM_KEY,
173
+					'type'  => 'hidden',
174
+					'value' => 'hidden',
175
+				);
176
+			} else {
177
+				$key = T::input()
178
+					->name(static::FORM_KEY)
179
+					->type('hidden')
180
+					->value($form_key);
181
+				$r[] = $key;
182
+			}
183
+		}
184 184
 
185
-        $s = array(
186
-            'tag'   => 'button',
187
-            'type'  => 'submit',
188
-            'label' =>
189
-                Util::nestedValue($m, 'return', CommentParser::$embeddedDataName, 'label')
190
-                    ?: 'Submit'
191
-        );
185
+		$s = array(
186
+			'tag'   => 'button',
187
+			'type'  => 'submit',
188
+			'label' =>
189
+				Util::nestedValue($m, 'return', CommentParser::$embeddedDataName, 'label')
190
+					?: 'Submit'
191
+		);
192 192
 
193
-        if (!$dataOnly) {
194
-            $s = Emmet::make(static::style('submit', $m), $s);
195
-        }
196
-        $r[] = $s;
197
-        $t = array(
198
-            'action' => $restler->getBaseUrl() . '/' . rtrim($action, '/'),
199
-            'method' => $method,
200
-        );
201
-        if (static::$fileUpload) {
202
-            static::$fileUpload = false;
203
-            $t['enctype'] = 'multipart/form-data';
204
-        }
205
-        if (isset($m[CommentParser::$embeddedDataName])) {
206
-            $t += $m[CommentParser::$embeddedDataName];
207
-        }
208
-        if (!$dataOnly) {
209
-            $t = Emmet::make(static::style('form', $m), $t);
210
-            $t->prefix = $prefix;
211
-            $t->indent = $indent;
212
-            $t[] = $r;
213
-        } else {
214
-            $t['fields'] = $r;
215
-        }
216
-        return $t;
217
-    }
193
+		if (!$dataOnly) {
194
+			$s = Emmet::make(static::style('submit', $m), $s);
195
+		}
196
+		$r[] = $s;
197
+		$t = array(
198
+			'action' => $restler->getBaseUrl() . '/' . rtrim($action, '/'),
199
+			'method' => $method,
200
+		);
201
+		if (static::$fileUpload) {
202
+			static::$fileUpload = false;
203
+			$t['enctype'] = 'multipart/form-data';
204
+		}
205
+		if (isset($m[CommentParser::$embeddedDataName])) {
206
+			$t += $m[CommentParser::$embeddedDataName];
207
+		}
208
+		if (!$dataOnly) {
209
+			$t = Emmet::make(static::style('form', $m), $t);
210
+			$t->prefix = $prefix;
211
+			$t->indent = $indent;
212
+			$t[] = $r;
213
+		} else {
214
+			$t['fields'] = $r;
215
+		}
216
+		return $t;
217
+	}
218 218
 
219
-    public static function style($name, array $metadata, $type = '')
220
-    {
221
-        if (isset($metadata[CommentParser::$embeddedDataName][$name])) {
222
-            return $metadata[CommentParser::$embeddedDataName][$name];
223
-        }
224
-        $style = static::$style . '::' . $name;
225
-        $typedStyle = $style . '_' . $type;
226
-        if (defined($typedStyle)) {
227
-            return constant($typedStyle);
228
-        }
229
-        if (defined($style)) {
230
-            return constant($style);
231
-        }
232
-        return null;
233
-    }
219
+	public static function style($name, array $metadata, $type = '')
220
+	{
221
+		if (isset($metadata[CommentParser::$embeddedDataName][$name])) {
222
+			return $metadata[CommentParser::$embeddedDataName][$name];
223
+		}
224
+		$style = static::$style . '::' . $name;
225
+		$typedStyle = $style . '_' . $type;
226
+		if (defined($typedStyle)) {
227
+			return constant($typedStyle);
228
+		}
229
+		if (defined($style)) {
230
+			return constant($style);
231
+		}
232
+		return null;
233
+	}
234 234
 
235
-    public static function fields($dataOnly = false)
236
-    {
237
-        $m = static::$info->metadata;
238
-        $params = $m['param'];
239
-        $values = static::$info->parameters;
240
-        $r = array();
241
-        foreach ($params as $k => $p) {
242
-            $value = Util::nestedValue($values, $k);
243
-            if (
244
-                is_scalar($value) ||
245
-                ($p['type'] == 'array' && is_array($value) && $value == array_values($value)) ||
246
-                is_object($value) && $p['type'] == get_class($value)
247
-            ) {
248
-                $p['value'] = $value;
249
-            }
250
-            static::$validationInfo = $v = new ValidationInfo($p);
251
-            if ($v->from == 'path') {
252
-                continue;
253
-            }
254
-            if (!empty($v->children)) {
255
-                $t = Emmet::make(static::style('fieldset', $m), array('label' => $v->label));
256
-                foreach ($v->children as $n => $c) {
257
-                    $value = Util::nestedValue($v->value, $n);
258
-                    if (
259
-                        is_scalar($value) ||
260
-                        ($c['type'] == 'array' && is_array($value) && $value == array_values($value)) ||
261
-                        is_object($value) && $c['type'] == get_class($value)
262
-                    ) {
263
-                        $c['value'] = $value;
264
-                    }
265
-                    static::$validationInfo = $vc = new ValidationInfo($c);
266
-                    if ($vc->from == 'path') {
267
-                        continue;
268
-                    }
269
-                    $vc->name = $v->name . '[' . $vc->name . ']';
270
-                    $t [] = static::field($vc, $dataOnly);
271
-                }
272
-                $r[] = $t;
273
-                static::$validationInfo = null;
274
-            } else {
275
-                $f = static::field($v, $dataOnly);
276
-                $r [] = $f;
277
-            }
278
-            static::$validationInfo = null;
279
-        }
280
-        return $r;
281
-    }
235
+	public static function fields($dataOnly = false)
236
+	{
237
+		$m = static::$info->metadata;
238
+		$params = $m['param'];
239
+		$values = static::$info->parameters;
240
+		$r = array();
241
+		foreach ($params as $k => $p) {
242
+			$value = Util::nestedValue($values, $k);
243
+			if (
244
+				is_scalar($value) ||
245
+				($p['type'] == 'array' && is_array($value) && $value == array_values($value)) ||
246
+				is_object($value) && $p['type'] == get_class($value)
247
+			) {
248
+				$p['value'] = $value;
249
+			}
250
+			static::$validationInfo = $v = new ValidationInfo($p);
251
+			if ($v->from == 'path') {
252
+				continue;
253
+			}
254
+			if (!empty($v->children)) {
255
+				$t = Emmet::make(static::style('fieldset', $m), array('label' => $v->label));
256
+				foreach ($v->children as $n => $c) {
257
+					$value = Util::nestedValue($v->value, $n);
258
+					if (
259
+						is_scalar($value) ||
260
+						($c['type'] == 'array' && is_array($value) && $value == array_values($value)) ||
261
+						is_object($value) && $c['type'] == get_class($value)
262
+					) {
263
+						$c['value'] = $value;
264
+					}
265
+					static::$validationInfo = $vc = new ValidationInfo($c);
266
+					if ($vc->from == 'path') {
267
+						continue;
268
+					}
269
+					$vc->name = $v->name . '[' . $vc->name . ']';
270
+					$t [] = static::field($vc, $dataOnly);
271
+				}
272
+				$r[] = $t;
273
+				static::$validationInfo = null;
274
+			} else {
275
+				$f = static::field($v, $dataOnly);
276
+				$r [] = $f;
277
+			}
278
+			static::$validationInfo = null;
279
+		}
280
+		return $r;
281
+	}
282 282
 
283
-    /**
284
-     * @param ValidationInfo $p
285
-     *
286
-     * @param bool           $dataOnly
287
-     *
288
-     * @return array|T
289
-     */
290
-    public static function field(ValidationInfo $p, $dataOnly = false)
291
-    {
292
-        if (is_string($p->value)) {
293
-            //prevent XSS attacks
294
-            $p->value = htmlspecialchars($p->value, ENT_QUOTES | ENT_HTML401, 'UTF-8');
295
-        }
296
-        $type = $p->field ?: static::guessFieldType($p);
297
-        $tag = in_array($type, static::$inputTypes)
298
-            ? 'input' : $type;
299
-        $options = array();
300
-        $name = $p->name;
301
-        $multiple = null;
302
-        if ($p->type == 'array' && $p->contentType != 'associative') {
303
-            $name .= '[]';
304
-            $multiple = true;
305
-        }
306
-        if ($p->choice) {
307
-            foreach ($p->choice as $i => $choice) {
308
-                $option = array('name' => $name, 'value' => $choice);
309
-                $option['text'] = isset($p->rules['select'][$i])
310
-                    ? $p->rules['select'][$i]
311
-                    : $choice;
312
-                if ($choice == $p->value) {
313
-                    $option['selected'] = true;
314
-                }
315
-                $options[] = $option;
316
-            }
317
-        } elseif ($p->type == 'boolean' || $p->type == 'bool') {
318
-            if (Text::beginsWith($type, 'radio') || Text::beginsWith($type, 'select')) {
319
-                $options[] = array(
320
-                    'name'  => $p->name,
321
-                    'text'  => ' Yes ',
322
-                    'value' => 'true'
323
-                );
324
-                $options[] = array(
325
-                    'name'  => $p->name,
326
-                    'text'  => ' No ',
327
-                    'value' => 'false'
328
-                );
329
-                if ($p->value || $p->default) {
330
-                    $options[0]['selected'] = true;
331
-                }
332
-            } else { //checkbox
333
-                $r = array(
334
-                    'tag'     => $tag,
335
-                    'name'    => $name,
336
-                    'type'    => $type,
337
-                    'label'   => $p->label,
338
-                    'value'   => 'true',
339
-                    'default' => $p->default,
340
-                );
341
-                $r['text'] = 'Yes';
342
-                if ($p->default) {
343
-                    $r['selected'] = true;
344
-                }
345
-                if (isset($p->rules)) {
346
-                    $r += $p->rules;
347
-                }
348
-            }
349
-        }
350
-        if (empty($r)) {
351
-            $r = array(
352
-                'tag'      => $tag,
353
-                'name'     => $name,
354
-                'type'     => $type,
355
-                'label'    => $p->label,
356
-                'value'    => $p->value,
357
-                'default'  => $p->default,
358
-                'options'  => & $options,
359
-                'multiple' => $multiple,
360
-            );
361
-            if (isset($p->rules)) {
362
-                $r += $p->rules;
363
-            }
364
-        }
365
-        if ($type == 'file') {
366
-            static::$fileUpload = true;
367
-            if (empty($r['accept'])) {
368
-                $r['accept'] = implode(', ', UploadFormat::$allowedMimeTypes);
369
-            }
370
-        }
371
-        if (!empty(Validator::$exceptions[$name]) && static::$info->url == Scope::get('Restler')->url) {
372
-            $r['error'] = 'has-error';
373
-            $r['message'] = Validator::$exceptions[$p->name]->getMessage();
374
-        }
283
+	/**
284
+	 * @param ValidationInfo $p
285
+	 *
286
+	 * @param bool           $dataOnly
287
+	 *
288
+	 * @return array|T
289
+	 */
290
+	public static function field(ValidationInfo $p, $dataOnly = false)
291
+	{
292
+		if (is_string($p->value)) {
293
+			//prevent XSS attacks
294
+			$p->value = htmlspecialchars($p->value, ENT_QUOTES | ENT_HTML401, 'UTF-8');
295
+		}
296
+		$type = $p->field ?: static::guessFieldType($p);
297
+		$tag = in_array($type, static::$inputTypes)
298
+			? 'input' : $type;
299
+		$options = array();
300
+		$name = $p->name;
301
+		$multiple = null;
302
+		if ($p->type == 'array' && $p->contentType != 'associative') {
303
+			$name .= '[]';
304
+			$multiple = true;
305
+		}
306
+		if ($p->choice) {
307
+			foreach ($p->choice as $i => $choice) {
308
+				$option = array('name' => $name, 'value' => $choice);
309
+				$option['text'] = isset($p->rules['select'][$i])
310
+					? $p->rules['select'][$i]
311
+					: $choice;
312
+				if ($choice == $p->value) {
313
+					$option['selected'] = true;
314
+				}
315
+				$options[] = $option;
316
+			}
317
+		} elseif ($p->type == 'boolean' || $p->type == 'bool') {
318
+			if (Text::beginsWith($type, 'radio') || Text::beginsWith($type, 'select')) {
319
+				$options[] = array(
320
+					'name'  => $p->name,
321
+					'text'  => ' Yes ',
322
+					'value' => 'true'
323
+				);
324
+				$options[] = array(
325
+					'name'  => $p->name,
326
+					'text'  => ' No ',
327
+					'value' => 'false'
328
+				);
329
+				if ($p->value || $p->default) {
330
+					$options[0]['selected'] = true;
331
+				}
332
+			} else { //checkbox
333
+				$r = array(
334
+					'tag'     => $tag,
335
+					'name'    => $name,
336
+					'type'    => $type,
337
+					'label'   => $p->label,
338
+					'value'   => 'true',
339
+					'default' => $p->default,
340
+				);
341
+				$r['text'] = 'Yes';
342
+				if ($p->default) {
343
+					$r['selected'] = true;
344
+				}
345
+				if (isset($p->rules)) {
346
+					$r += $p->rules;
347
+				}
348
+			}
349
+		}
350
+		if (empty($r)) {
351
+			$r = array(
352
+				'tag'      => $tag,
353
+				'name'     => $name,
354
+				'type'     => $type,
355
+				'label'    => $p->label,
356
+				'value'    => $p->value,
357
+				'default'  => $p->default,
358
+				'options'  => & $options,
359
+				'multiple' => $multiple,
360
+			);
361
+			if (isset($p->rules)) {
362
+				$r += $p->rules;
363
+			}
364
+		}
365
+		if ($type == 'file') {
366
+			static::$fileUpload = true;
367
+			if (empty($r['accept'])) {
368
+				$r['accept'] = implode(', ', UploadFormat::$allowedMimeTypes);
369
+			}
370
+		}
371
+		if (!empty(Validator::$exceptions[$name]) && static::$info->url == Scope::get('Restler')->url) {
372
+			$r['error'] = 'has-error';
373
+			$r['message'] = Validator::$exceptions[$p->name]->getMessage();
374
+		}
375 375
 
376
-        if (true === $p->required) {
377
-            $r['required'] = 'required';
378
-        }
379
-        if (isset($p->rules['autofocus'])) {
380
-            $r['autofocus'] = 'autofocus';
381
-        }
382
-        /*
376
+		if (true === $p->required) {
377
+			$r['required'] = 'required';
378
+		}
379
+		if (isset($p->rules['autofocus'])) {
380
+			$r['autofocus'] = 'autofocus';
381
+		}
382
+		/*
383 383
         echo "<pre>";
384 384
         print_r($r);
385 385
         echo "</pre>";
386 386
         */
387
-        if ($dataOnly) {
388
-            return $r;
389
-        }
390
-        if (isset($p->rules['form'])) {
391
-            return Emmet::make($p->rules['form'], $r);
392
-        }
393
-        $m = static::$info->metadata;
394
-        $t = Emmet::make(static::style($type, $m, $p->type) ?: static::style($tag, $m, $p->type), $r);
395
-        return $t;
396
-    }
387
+		if ($dataOnly) {
388
+			return $r;
389
+		}
390
+		if (isset($p->rules['form'])) {
391
+			return Emmet::make($p->rules['form'], $r);
392
+		}
393
+		$m = static::$info->metadata;
394
+		$t = Emmet::make(static::style($type, $m, $p->type) ?: static::style($tag, $m, $p->type), $r);
395
+		return $t;
396
+	}
397 397
 
398
-    protected static function guessFieldType(ValidationInfo $p, $type = 'type')
399
-    {
400
-        if (in_array($p->$type, static::$inputTypes)) {
401
-            return $p->$type;
402
-        }
403
-        if ($p->choice) {
404
-            return $p->type == 'array' ? 'checkbox' : 'select';
405
-        }
406
-        switch ($p->$type) {
407
-            case 'boolean':
408
-                return 'radio';
409
-            case 'int':
410
-            case 'number':
411
-            case 'float':
412
-                return 'number';
413
-            case 'array':
414
-                return static::guessFieldType($p, 'contentType');
415
-        }
416
-        if ($p->name == 'password') {
417
-            return 'password';
418
-        }
419
-        return 'text';
420
-    }
398
+	protected static function guessFieldType(ValidationInfo $p, $type = 'type')
399
+	{
400
+		if (in_array($p->$type, static::$inputTypes)) {
401
+			return $p->$type;
402
+		}
403
+		if ($p->choice) {
404
+			return $p->type == 'array' ? 'checkbox' : 'select';
405
+		}
406
+		switch ($p->$type) {
407
+			case 'boolean':
408
+				return 'radio';
409
+			case 'int':
410
+			case 'number':
411
+			case 'float':
412
+				return 'number';
413
+			case 'array':
414
+				return static::guessFieldType($p, 'contentType');
415
+		}
416
+		if ($p->name == 'password') {
417
+			return 'password';
418
+		}
419
+		return 'text';
420
+	}
421 421
 
422
-    /**
423
-     * Get the form key
424
-     *
425
-     * @param string $method   http method for form key
426
-     * @param string $action   relative path from the web root. When set to null
427
-     *                         it uses the current api method's path
428
-     *
429
-     * @return string generated form key
430
-     */
431
-    public static function key($method = 'POST', $action = null)
432
-    {
433
-        if (is_null($action)) {
434
-            $action = Scope::get('Restler')->url;
435
-        }
436
-        $target = "$method $action";
437
-        if (empty(static::$key[$target])) {
438
-            static::$key[$target] = md5($target . User::getIpAddress() . uniqid(mt_rand()));
439
-        }
440
-        $_SESSION[static::FORM_KEY] = static::$key;
441
-        return static::$key[$target];
442
-    }
422
+	/**
423
+	 * Get the form key
424
+	 *
425
+	 * @param string $method   http method for form key
426
+	 * @param string $action   relative path from the web root. When set to null
427
+	 *                         it uses the current api method's path
428
+	 *
429
+	 * @return string generated form key
430
+	 */
431
+	public static function key($method = 'POST', $action = null)
432
+	{
433
+		if (is_null($action)) {
434
+			$action = Scope::get('Restler')->url;
435
+		}
436
+		$target = "$method $action";
437
+		if (empty(static::$key[$target])) {
438
+			static::$key[$target] = md5($target . User::getIpAddress() . uniqid(mt_rand()));
439
+		}
440
+		$_SESSION[static::FORM_KEY] = static::$key;
441
+		return static::$key[$target];
442
+	}
443 443
 
444
-    /**
445
-     * Access verification method.
446
-     *
447
-     * API access will be denied when this method returns false
448
-     *
449
-     * @return boolean true when api access is allowed false otherwise
450
-     *
451
-     * @throws RestException 403 security violation
452
-     */
453
-    public function __isAllowed()
454
-    {
455
-        if (session_id() == '') {
456
-            session_start();
457
-        }
458
-        /** @var Restler $restler */
459
-        $restler = $this->restler;
460
-        $url = $restler->url;
461
-        foreach (static::$excludedPaths as $exclude) {
462
-            if (empty($exclude)) {
463
-                if ($url == $exclude) {
464
-                    return true;
465
-                }
466
-            } elseif (Text::beginsWith($url, $exclude)) {
467
-                return true;
468
-            }
469
-        }
470
-        $check = static::$filterFormRequestsOnly
471
-            ? $restler->requestFormat instanceof UrlEncodedFormat || $restler->requestFormat instanceof UploadFormat
472
-            : true;
473
-        if (!empty($_POST) && $check) {
474
-            if (
475
-                isset($_POST[static::FORM_KEY]) &&
476
-                ($target = Util::getRequestMethod() . ' ' . $restler->url) &&
477
-                isset($_SESSION[static::FORM_KEY][$target]) &&
478
-                $_POST[static::FORM_KEY] == $_SESSION[static::FORM_KEY][$target]
479
-            ) {
480
-                return true;
481
-            }
482
-            throw new RestException(403, 'Insecure form submission');
483
-        }
484
-        return true;
485
-    }
444
+	/**
445
+	 * Access verification method.
446
+	 *
447
+	 * API access will be denied when this method returns false
448
+	 *
449
+	 * @return boolean true when api access is allowed false otherwise
450
+	 *
451
+	 * @throws RestException 403 security violation
452
+	 */
453
+	public function __isAllowed()
454
+	{
455
+		if (session_id() == '') {
456
+			session_start();
457
+		}
458
+		/** @var Restler $restler */
459
+		$restler = $this->restler;
460
+		$url = $restler->url;
461
+		foreach (static::$excludedPaths as $exclude) {
462
+			if (empty($exclude)) {
463
+				if ($url == $exclude) {
464
+					return true;
465
+				}
466
+			} elseif (Text::beginsWith($url, $exclude)) {
467
+				return true;
468
+			}
469
+		}
470
+		$check = static::$filterFormRequestsOnly
471
+			? $restler->requestFormat instanceof UrlEncodedFormat || $restler->requestFormat instanceof UploadFormat
472
+			: true;
473
+		if (!empty($_POST) && $check) {
474
+			if (
475
+				isset($_POST[static::FORM_KEY]) &&
476
+				($target = Util::getRequestMethod() . ' ' . $restler->url) &&
477
+				isset($_SESSION[static::FORM_KEY][$target]) &&
478
+				$_POST[static::FORM_KEY] == $_SESSION[static::FORM_KEY][$target]
479
+			) {
480
+				return true;
481
+			}
482
+			throw new RestException(403, 'Insecure form submission');
483
+		}
484
+		return true;
485
+	}
486 486
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
             $info = false;
136 136
         }
137 137
         if (!$info) {
138
-            throw new RestException(500, 'invalid action path for form `' . $method . ' ' . $action . '`');
138
+            throw new RestException(500, 'invalid action path for form `'.$method.' '.$action.'`');
139 139
         }
140 140
         static::$info = $info;
141 141
         $m = $info->metadata;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
             if (empty(Defaults::$httpMethodOverrideProperty)) {
145 145
                 throw new RestException(
146 146
                     500,
147
-                    'Forms require `Defaults::\$httpMethodOverrideProperty`' .
147
+                    'Forms require `Defaults::\$httpMethodOverrideProperty`'.
148 148
                     "for supporting HTTP $method"
149 149
                 );
150 150
             }
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
         }
196 196
         $r[] = $s;
197 197
         $t = array(
198
-            'action' => $restler->getBaseUrl() . '/' . rtrim($action, '/'),
198
+            'action' => $restler->getBaseUrl().'/'.rtrim($action, '/'),
199 199
             'method' => $method,
200 200
         );
201 201
         if (static::$fileUpload) {
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
         if (isset($metadata[CommentParser::$embeddedDataName][$name])) {
222 222
             return $metadata[CommentParser::$embeddedDataName][$name];
223 223
         }
224
-        $style = static::$style . '::' . $name;
225
-        $typedStyle = $style . '_' . $type;
224
+        $style = static::$style.'::'.$name;
225
+        $typedStyle = $style.'_'.$type;
226 226
         if (defined($typedStyle)) {
227 227
             return constant($typedStyle);
228 228
         }
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
                     if ($vc->from == 'path') {
267 267
                         continue;
268 268
                     }
269
-                    $vc->name = $v->name . '[' . $vc->name . ']';
269
+                    $vc->name = $v->name.'['.$vc->name.']';
270 270
                     $t [] = static::field($vc, $dataOnly);
271 271
                 }
272 272
                 $r[] = $t;
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
         }
436 436
         $target = "$method $action";
437 437
         if (empty(static::$key[$target])) {
438
-            static::$key[$target] = md5($target . User::getIpAddress() . uniqid(mt_rand()));
438
+            static::$key[$target] = md5($target.User::getIpAddress().uniqid(mt_rand()));
439 439
         }
440 440
         $_SESSION[static::FORM_KEY] = static::$key;
441 441
         return static::$key[$target];
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
         if (!empty($_POST) && $check) {
474 474
             if (
475 475
                 isset($_POST[static::FORM_KEY]) &&
476
-                ($target = Util::getRequestMethod() . ' ' . $restler->url) &&
476
+                ($target = Util::getRequestMethod().' '.$restler->url) &&
477 477
                 isset($_SESSION[static::FORM_KEY][$target]) &&
478 478
                 $_POST[static::FORM_KEY] == $_SESSION[static::FORM_KEY][$target]
479 479
             ) {
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/UI/Emmet.php 4 patches
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -12,367 +12,367 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class Emmet
14 14
 {
15
-    const DELIMITERS = '.#*>+^[=" ]{$@-#}';
15
+	const DELIMITERS = '.#*>+^[=" ]{$@-#}';
16 16
 
17
-    /**
18
-     * Create the needed tag hierarchy from emmet string
19
-     *
20
-     * @param string       $string
21
-     *
22
-     * @param array|string $data
23
-     *
24
-     * @return array|T
25
-     */
26
-    public static function make($string, $data = null)
27
-    {
28
-        if (!strlen($string))
29
-            return array();
17
+	/**
18
+	 * Create the needed tag hierarchy from emmet string
19
+	 *
20
+	 * @param string       $string
21
+	 *
22
+	 * @param array|string $data
23
+	 *
24
+	 * @return array|T
25
+	 */
26
+	public static function make($string, $data = null)
27
+	{
28
+		if (!strlen($string))
29
+			return array();
30 30
 
31
-        $implicitTag =
32
-            function () use (& $tag) {
33
-                if (empty($tag->tag)) {
34
-                    switch ($tag->parent->tag) {
35
-                        case 'ul':
36
-                        case 'ol':
37
-                            $tag->tag = 'li';
38
-                            break;
39
-                        case 'em':
40
-                            $tag->tag = 'span';
41
-                            break;
42
-                        case 'table':
43
-                        case 'tbody':
44
-                        case 'thead':
45
-                        case 'tfoot':
46
-                            $tag->tag = 'tr';
47
-                            break;
48
-                        case 'tr':
49
-                            $tag->tag = 'td';
50
-                            break;
51
-                        case 'select':
52
-                        case 'optgroup':
53
-                            $tag->tag = 'option';
54
-                            break;
55
-                        default:
56
-                            $tag->tag = 'div';
57
-                    }
58
-                }
59
-            };
31
+		$implicitTag =
32
+			function () use (& $tag) {
33
+				if (empty($tag->tag)) {
34
+					switch ($tag->parent->tag) {
35
+						case 'ul':
36
+						case 'ol':
37
+							$tag->tag = 'li';
38
+							break;
39
+						case 'em':
40
+							$tag->tag = 'span';
41
+							break;
42
+						case 'table':
43
+						case 'tbody':
44
+						case 'thead':
45
+						case 'tfoot':
46
+							$tag->tag = 'tr';
47
+							break;
48
+						case 'tr':
49
+							$tag->tag = 'td';
50
+							break;
51
+						case 'select':
52
+						case 'optgroup':
53
+							$tag->tag = 'option';
54
+							break;
55
+						default:
56
+							$tag->tag = 'div';
57
+					}
58
+				}
59
+			};
60 60
 
61
-        $parseText =
62
-            function (
63
-                $text, $round, $total, $data, $delimiter = null
64
-            )
65
-            use (
66
-                & $tokens, & $tag
67
-            ) {
68
-                $digits = 0;
69
-                if ($delimiter == null)
70
-                    $delimiter = array(
71
-                        '.' => true,
72
-                        '#' => true,
73
-                        '*' => true,
74
-                        '>' => true,
75
-                        '+' => true,
76
-                        '^' => true,
77
-                        '[' => true,
78
-                        ']' => true,
79
-                        '=' => true,
80
-                    );
81
-                while (!empty($tokens) &&
82
-                    !isset($delimiter[$t = array_shift($tokens)])) {
83
-                    while ('$' === $t) {
84
-                        $digits++;
85
-                        $t = array_shift($tokens);
86
-                    }
87
-                    if ($digits) {
88
-                        $negative = false;
89
-                        $offset = 0;
90
-                        if ('@' == $t) {
91
-                            if ('-' == ($t = array_shift($tokens))) {
92
-                                $negative = true;
93
-                                if (is_numeric(reset($tokens))) {
94
-                                    $offset = array_shift($tokens);
95
-                                }
96
-                            } elseif (is_numeric($t)) {
97
-                                $offset = $t;
98
-                            } else {
99
-                                array_unshift($tokens, $t);
100
-                            }
101
-                        } elseif ('#' == ($h = array_shift($tokens))) {
102
-                            if (!empty($t)) {
103
-                                $data = Util::nestedValue($data, $t);
104
-                                if (is_null($data)) {
105
-                                    return null;
106
-                                }
107
-                            }
108
-                            if (is_numeric($data)) {
109
-                                $text .= sprintf("%0{$digits}d", (int)$data);
110
-                            } elseif (is_string($data)) {
111
-                                $text .= $data;
112
-                            }
113
-                            $digits = 0;
114
-                            continue;
115
-                        } else {
116
-                            array_unshift($tokens, $t, $h);
117
-                        }
118
-                        if ($negative) {
119
-                            $n = $total + 1 - $round + $offset;
120
-                        } else {
121
-                            $n = $round + $offset;
122
-                        }
123
-                        $text .= sprintf("%0{$digits}d", $n);
124
-                        $digits = 0;
125
-                    } else {
126
-                        $text .= $t;
127
-                    }
128
-                }
129
-                if (isset($t))
130
-                    array_unshift($tokens, $t);
131
-                return $text;
132
-            };
61
+		$parseText =
62
+			function (
63
+				$text, $round, $total, $data, $delimiter = null
64
+			)
65
+			use (
66
+				& $tokens, & $tag
67
+			) {
68
+				$digits = 0;
69
+				if ($delimiter == null)
70
+					$delimiter = array(
71
+						'.' => true,
72
+						'#' => true,
73
+						'*' => true,
74
+						'>' => true,
75
+						'+' => true,
76
+						'^' => true,
77
+						'[' => true,
78
+						']' => true,
79
+						'=' => true,
80
+					);
81
+				while (!empty($tokens) &&
82
+					!isset($delimiter[$t = array_shift($tokens)])) {
83
+					while ('$' === $t) {
84
+						$digits++;
85
+						$t = array_shift($tokens);
86
+					}
87
+					if ($digits) {
88
+						$negative = false;
89
+						$offset = 0;
90
+						if ('@' == $t) {
91
+							if ('-' == ($t = array_shift($tokens))) {
92
+								$negative = true;
93
+								if (is_numeric(reset($tokens))) {
94
+									$offset = array_shift($tokens);
95
+								}
96
+							} elseif (is_numeric($t)) {
97
+								$offset = $t;
98
+							} else {
99
+								array_unshift($tokens, $t);
100
+							}
101
+						} elseif ('#' == ($h = array_shift($tokens))) {
102
+							if (!empty($t)) {
103
+								$data = Util::nestedValue($data, $t);
104
+								if (is_null($data)) {
105
+									return null;
106
+								}
107
+							}
108
+							if (is_numeric($data)) {
109
+								$text .= sprintf("%0{$digits}d", (int)$data);
110
+							} elseif (is_string($data)) {
111
+								$text .= $data;
112
+							}
113
+							$digits = 0;
114
+							continue;
115
+						} else {
116
+							array_unshift($tokens, $t, $h);
117
+						}
118
+						if ($negative) {
119
+							$n = $total + 1 - $round + $offset;
120
+						} else {
121
+							$n = $round + $offset;
122
+						}
123
+						$text .= sprintf("%0{$digits}d", $n);
124
+						$digits = 0;
125
+					} else {
126
+						$text .= $t;
127
+					}
128
+				}
129
+				if (isset($t))
130
+					array_unshift($tokens, $t);
131
+				return $text;
132
+			};
133 133
 
134
-        $parseAttributes =
135
-            function (Callable $self, $round, $total, $data)
136
-            use (& $tokens, & $tag, $parseText) {
137
-                $a = $parseText(
138
-                    '', $round, $total, $data
139
-                );
140
-                if (is_null($a))
141
-                    return;
142
-                if ('=' == ($v = array_shift($tokens))) {
143
-                    //value
144
-                    if ('"' == ($v = array_shift($tokens))) {
145
-                        $text = '';
146
-                        $tag->$a($parseText(
147
-                            $text, $round, $total, $data,
148
-                            array('"' => true)
149
-                        ));
150
-                    } else {
151
-                        array_unshift($tokens, $v);
152
-                        $text = '';
153
-                        $tag->$a($parseText(
154
-                            $text, $round, $total, $data,
155
-                            array(' ' => true, ']' => true)
156
-                        ));
157
-                    }
158
-                    if (' ' == ($v = array_shift($tokens))) {
159
-                        $self($self, $round, $total, $data);
160
-                    }
161
-                } elseif (']' == $v) {
162
-                    //end
163
-                    $tag->$a('');
164
-                    return;
165
-                } elseif (' ' == $v) {
166
-                    $tag->$a('');
167
-                    $self($self, $round, $total, $data);
168
-                }
169
-            };
134
+		$parseAttributes =
135
+			function (Callable $self, $round, $total, $data)
136
+			use (& $tokens, & $tag, $parseText) {
137
+				$a = $parseText(
138
+					'', $round, $total, $data
139
+				);
140
+				if (is_null($a))
141
+					return;
142
+				if ('=' == ($v = array_shift($tokens))) {
143
+					//value
144
+					if ('"' == ($v = array_shift($tokens))) {
145
+						$text = '';
146
+						$tag->$a($parseText(
147
+							$text, $round, $total, $data,
148
+							array('"' => true)
149
+						));
150
+					} else {
151
+						array_unshift($tokens, $v);
152
+						$text = '';
153
+						$tag->$a($parseText(
154
+							$text, $round, $total, $data,
155
+							array(' ' => true, ']' => true)
156
+						));
157
+					}
158
+					if (' ' == ($v = array_shift($tokens))) {
159
+						$self($self, $round, $total, $data);
160
+					}
161
+				} elseif (']' == $v) {
162
+					//end
163
+					$tag->$a('');
164
+					return;
165
+				} elseif (' ' == $v) {
166
+					$tag->$a('');
167
+					$self($self, $round, $total, $data);
168
+				}
169
+			};
170 170
 
171
-        $tokens = static::tokenize($string);
172
-        $tag = new T(array_shift($tokens));
173
-        $parent = $root = new T;
171
+		$tokens = static::tokenize($string);
172
+		$tag = new T(array_shift($tokens));
173
+		$parent = $root = new T;
174 174
 
175
-        $parse =
176
-            function (
177
-                Callable $self, $round = 1, $total = 1
178
-            )
179
-            use (
180
-                & $tokens, & $parent, & $tag, & $data,
181
-                $parseAttributes, $implicitTag, $parseText
182
-            ) {
183
-                $offsetTokens = null;
184
-                $parent[] = $tag;
185
-                $isInChild = false;
186
-                while ($tokens) {
187
-                    switch (array_shift($tokens)) {
188
-                        //class
189
-                        case '.':
190
-                            $offsetTokens = array_values($tokens);
191
-                            array_unshift($offsetTokens, '.');
192
-                            $implicitTag();
193
-                            $e = array_filter(explode(' ', $tag->class));
194
-                            $e[] = $parseText('', $round, $total, $data);
195
-                            $tag->class(implode(' ', array_unique($e)));
196
-                            break;
197
-                        //id
198
-                        case '#':
199
-                            $offsetTokens = array_values($tokens);
200
-                            array_unshift($offsetTokens, '#');
201
-                            $implicitTag();
202
-                            $tag->id(
203
-                                $parseText(
204
-                                    array_shift($tokens), $round, $total, $data
205
-                                )
206
-                            );
207
-                            break;
208
-                        //attributes
209
-                        case '[':
210
-                            $offsetTokens = array_values($tokens);
211
-                            array_unshift($offsetTokens, '[');
212
-                            $implicitTag();
213
-                            $parseAttributes(
214
-                                $parseAttributes, $round, $total, $data
215
-                            );
216
-                            break;
217
-                        //child
218
-                        case '{':
219
-                            $text = '';
220
-                            $tag[] = $parseText(
221
-                                $text, $round, $total, $data, array('}' => true)
222
-                            );
223
-                            break;
224
-                        case '>':
225
-                            $isInChild = true;
226
-                            $offsetTokens = null;
227
-                            if ('{' == ($t = array_shift($tokens))) {
228
-                                array_unshift($tokens, $t);
229
-                                $child = new T();
230
-                                $tag[] = $child;
231
-                                $parent = $tag;
232
-                                $tag = $child;
233
-                            } elseif ('[' == $t) {
234
-                                array_unshift($tokens, $t);
235
-                            } else {
236
-                                $child = new T($t);
237
-                                $tag[] = $child;
238
-                                $parent = $tag;
239
-                                $tag = $child;
240
-                            }
241
-                            break;
242
-                        //sibling
243
-                        case '+':
244
-                            $offsetTokens = null;
245
-                            if (!$isInChild && $round != $total) {
246
-                                $tokens = array();
247
-                                break;
248
-                            }
249
-                            if ('{' == ($t = array_shift($tokens))) {
250
-                                $tag = $tag->parent;
251
-                                array_unshift($tokens, $t);
252
-                                break;
253
-                            } elseif ('[' == $t) {
254
-                                array_unshift($tokens, $t);
255
-                            } else {
256
-                                $child = new T($t);
257
-                                $tag = $tag->parent;
258
-                                $tag[] = $child;
259
-                                $tag = $child;
260
-                            }
261
-                            break;
262
-                        //sibling of parent
263
-                        case '^':
264
-                            if ($round != $total) {
265
-                                $tokens = array();
266
-                                break;
267
-                            }
268
-                            $tag = $tag->parent;
269
-                            if ($tag->parent)
270
-                                $tag = $tag->parent;
271
-                            while ('^' == ($t = array_shift($tokens))) {
272
-                                if ($tag->parent)
273
-                                    $tag = $tag->parent;
274
-                            }
275
-                            $child = new T($t);
276
-                            $tag[] = $child;
277
-                            $tag = $child;
278
-                            break;
279
-                        //clone
280
-                        case '*':
281
-                            $times = array_shift($tokens);
282
-                            $removeCount = 2;
283
-                            $delimiter = array(
284
-                                '.' => true,
285
-                                '#' => true,
286
-                                '*' => true,
287
-                                '>' => true,
288
-                                '+' => true,
289
-                                '^' => true,
290
-                                '[' => true,
291
-                                ']' => true,
292
-                                '=' => true,
293
-                            );
294
-                            if (!is_numeric($times)) {
295
-                                if (is_string($times)) {
296
-                                    if (!isset($delimiter[$times])) {
297
-                                        $data = Util::nestedValue($data, $times)
298
-                                            ? : $data;
299
-                                    } else {
300
-                                        array_unshift($tokens, $times);
301
-                                        $removeCount = 1;
302
-                                    }
303
-                                }
304
-                                $indexed = array_values($data);
305
-                                $times = is_array($data) && $indexed == $data
306
-                                    ? count($data) : 0;
307
-                            }
308
-                            $source = $tag;
309
-                            if (!empty($offsetTokens)) {
310
-                                if (false !== strpos($source->class, ' ')) {
311
-                                    $class = explode(' ', $source->class);
312
-                                    array_pop($class);
313
-                                    $class = implode(' ', $class);
314
-                                } else {
315
-                                    $class = null;
316
-                                }
317
-                                $tag->class($class);
318
-                                $star = array_search('*', $offsetTokens);
319
-                                array_splice($offsetTokens, $star, $removeCount);
320
-                                $remainingTokens = $offsetTokens;
321
-                            } else {
322
-                                $remainingTokens = $tokens;
323
-                            }
324
-                            $source->parent = null;
325
-                            $sourceData = $data;
326
-                            $currentParent = $parent;
327
-                            for ($i = 1; $i <= $times; $i++) {
328
-                                $tag = clone $source;
329
-                                $parent = $currentParent;
330
-                                $data = is_array($sourceData)
331
-                                && isset($sourceData[$i - 1])
332
-                                    ? $sourceData[$i - 1]
333
-                                    : @(string)$sourceData;
334
-                                $tokens = array_values($remainingTokens);
335
-                                $self($self, $i, $times);
336
-                            }
337
-                            $round = 1;
338
-                            $offsetTokens = null;
339
-                            $tag = $source;
340
-                            $tokens = array(); //$remainingTokens;
341
-                            break;
342
-                    }
343
-                }
344
-            };
345
-        $parse($parse);
346
-        return count($root) == 1 ? $root[0] : $root;
347
-    }
175
+		$parse =
176
+			function (
177
+				Callable $self, $round = 1, $total = 1
178
+			)
179
+			use (
180
+				& $tokens, & $parent, & $tag, & $data,
181
+				$parseAttributes, $implicitTag, $parseText
182
+			) {
183
+				$offsetTokens = null;
184
+				$parent[] = $tag;
185
+				$isInChild = false;
186
+				while ($tokens) {
187
+					switch (array_shift($tokens)) {
188
+						//class
189
+						case '.':
190
+							$offsetTokens = array_values($tokens);
191
+							array_unshift($offsetTokens, '.');
192
+							$implicitTag();
193
+							$e = array_filter(explode(' ', $tag->class));
194
+							$e[] = $parseText('', $round, $total, $data);
195
+							$tag->class(implode(' ', array_unique($e)));
196
+							break;
197
+						//id
198
+						case '#':
199
+							$offsetTokens = array_values($tokens);
200
+							array_unshift($offsetTokens, '#');
201
+							$implicitTag();
202
+							$tag->id(
203
+								$parseText(
204
+									array_shift($tokens), $round, $total, $data
205
+								)
206
+							);
207
+							break;
208
+						//attributes
209
+						case '[':
210
+							$offsetTokens = array_values($tokens);
211
+							array_unshift($offsetTokens, '[');
212
+							$implicitTag();
213
+							$parseAttributes(
214
+								$parseAttributes, $round, $total, $data
215
+							);
216
+							break;
217
+						//child
218
+						case '{':
219
+							$text = '';
220
+							$tag[] = $parseText(
221
+								$text, $round, $total, $data, array('}' => true)
222
+							);
223
+							break;
224
+						case '>':
225
+							$isInChild = true;
226
+							$offsetTokens = null;
227
+							if ('{' == ($t = array_shift($tokens))) {
228
+								array_unshift($tokens, $t);
229
+								$child = new T();
230
+								$tag[] = $child;
231
+								$parent = $tag;
232
+								$tag = $child;
233
+							} elseif ('[' == $t) {
234
+								array_unshift($tokens, $t);
235
+							} else {
236
+								$child = new T($t);
237
+								$tag[] = $child;
238
+								$parent = $tag;
239
+								$tag = $child;
240
+							}
241
+							break;
242
+						//sibling
243
+						case '+':
244
+							$offsetTokens = null;
245
+							if (!$isInChild && $round != $total) {
246
+								$tokens = array();
247
+								break;
248
+							}
249
+							if ('{' == ($t = array_shift($tokens))) {
250
+								$tag = $tag->parent;
251
+								array_unshift($tokens, $t);
252
+								break;
253
+							} elseif ('[' == $t) {
254
+								array_unshift($tokens, $t);
255
+							} else {
256
+								$child = new T($t);
257
+								$tag = $tag->parent;
258
+								$tag[] = $child;
259
+								$tag = $child;
260
+							}
261
+							break;
262
+						//sibling of parent
263
+						case '^':
264
+							if ($round != $total) {
265
+								$tokens = array();
266
+								break;
267
+							}
268
+							$tag = $tag->parent;
269
+							if ($tag->parent)
270
+								$tag = $tag->parent;
271
+							while ('^' == ($t = array_shift($tokens))) {
272
+								if ($tag->parent)
273
+									$tag = $tag->parent;
274
+							}
275
+							$child = new T($t);
276
+							$tag[] = $child;
277
+							$tag = $child;
278
+							break;
279
+						//clone
280
+						case '*':
281
+							$times = array_shift($tokens);
282
+							$removeCount = 2;
283
+							$delimiter = array(
284
+								'.' => true,
285
+								'#' => true,
286
+								'*' => true,
287
+								'>' => true,
288
+								'+' => true,
289
+								'^' => true,
290
+								'[' => true,
291
+								']' => true,
292
+								'=' => true,
293
+							);
294
+							if (!is_numeric($times)) {
295
+								if (is_string($times)) {
296
+									if (!isset($delimiter[$times])) {
297
+										$data = Util::nestedValue($data, $times)
298
+											? : $data;
299
+									} else {
300
+										array_unshift($tokens, $times);
301
+										$removeCount = 1;
302
+									}
303
+								}
304
+								$indexed = array_values($data);
305
+								$times = is_array($data) && $indexed == $data
306
+									? count($data) : 0;
307
+							}
308
+							$source = $tag;
309
+							if (!empty($offsetTokens)) {
310
+								if (false !== strpos($source->class, ' ')) {
311
+									$class = explode(' ', $source->class);
312
+									array_pop($class);
313
+									$class = implode(' ', $class);
314
+								} else {
315
+									$class = null;
316
+								}
317
+								$tag->class($class);
318
+								$star = array_search('*', $offsetTokens);
319
+								array_splice($offsetTokens, $star, $removeCount);
320
+								$remainingTokens = $offsetTokens;
321
+							} else {
322
+								$remainingTokens = $tokens;
323
+							}
324
+							$source->parent = null;
325
+							$sourceData = $data;
326
+							$currentParent = $parent;
327
+							for ($i = 1; $i <= $times; $i++) {
328
+								$tag = clone $source;
329
+								$parent = $currentParent;
330
+								$data = is_array($sourceData)
331
+								&& isset($sourceData[$i - 1])
332
+									? $sourceData[$i - 1]
333
+									: @(string)$sourceData;
334
+								$tokens = array_values($remainingTokens);
335
+								$self($self, $i, $times);
336
+							}
337
+							$round = 1;
338
+							$offsetTokens = null;
339
+							$tag = $source;
340
+							$tokens = array(); //$remainingTokens;
341
+							break;
342
+					}
343
+				}
344
+			};
345
+		$parse($parse);
346
+		return count($root) == 1 ? $root[0] : $root;
347
+	}
348 348
 
349
-    public static function tokenize($string)
350
-    {
351
-        $r = array();
352
-        $f = strtok($string, static::DELIMITERS);
353
-        $pos = 0;
354
-        do {
355
-            $start = $pos;
356
-            $pos = strpos($string, $f, $start);
357
-            $tokens = array();
358
-            for ($i = $start; $i < $pos; $i++) {
359
-                $token = $string[$i];
360
-                if (('#' == $token || '.' == $token) &&
361
-                    (!empty($tokens) || $i == 0)
362
-                ) {
363
-                    $r[] = '';
364
-                }
365
-                $r[] = $tokens[] = $token;
366
-            }
367
-            $pos += strlen($f);
368
-            $r[] = $f;
369
-        } while (false != ($f = strtok(static::DELIMITERS)));
370
-        for ($i = $pos; $i < strlen($string); $i++) {
371
-            $token = $string[$i];
372
-            $r[] = $tokens[] = $token;
373
-        }
374
-        return $r;
375
-        /* sample output produced by ".row*3>.col*3"
349
+	public static function tokenize($string)
350
+	{
351
+		$r = array();
352
+		$f = strtok($string, static::DELIMITERS);
353
+		$pos = 0;
354
+		do {
355
+			$start = $pos;
356
+			$pos = strpos($string, $f, $start);
357
+			$tokens = array();
358
+			for ($i = $start; $i < $pos; $i++) {
359
+				$token = $string[$i];
360
+				if (('#' == $token || '.' == $token) &&
361
+					(!empty($tokens) || $i == 0)
362
+				) {
363
+					$r[] = '';
364
+				}
365
+				$r[] = $tokens[] = $token;
366
+			}
367
+			$pos += strlen($f);
368
+			$r[] = $f;
369
+		} while (false != ($f = strtok(static::DELIMITERS)));
370
+		for ($i = $pos; $i < strlen($string); $i++) {
371
+			$token = $string[$i];
372
+			$r[] = $tokens[] = $token;
373
+		}
374
+		return $r;
375
+		/* sample output produced by ".row*3>.col*3"
376 376
         [0] => div
377 377
         [1] => .
378 378
         [2] => row
@@ -385,5 +385,5 @@  discard block
 block discarded – undo
385 385
         [9] => *
386 386
         [10] => 4
387 387
          */
388
-    }
388
+	}
389 389
 }
390 390
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
             return array();
30 30
 
31 31
         $implicitTag =
32
-            function () use (& $tag) {
32
+            function() use (& $tag) {
33 33
                 if (empty($tag->tag)) {
34 34
                     switch ($tag->parent->tag) {
35 35
                         case 'ul':
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             };
60 60
 
61 61
         $parseText =
62
-            function (
62
+            function(
63 63
                 $text, $round, $total, $data, $delimiter = null
64 64
             )
65 65
             use (
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
                                 }
107 107
                             }
108 108
                             if (is_numeric($data)) {
109
-                                $text .= sprintf("%0{$digits}d", (int)$data);
109
+                                $text .= sprintf("%0{$digits}d", (int) $data);
110 110
                             } elseif (is_string($data)) {
111 111
                                 $text .= $data;
112 112
                             }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             };
133 133
 
134 134
         $parseAttributes =
135
-            function (Callable $self, $round, $total, $data)
135
+            function(Callable $self, $round, $total, $data)
136 136
             use (& $tokens, & $tag, $parseText) {
137 137
                 $a = $parseText(
138 138
                     '', $round, $total, $data
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         $parent = $root = new T;
174 174
 
175 175
         $parse =
176
-            function (
176
+            function(
177 177
                 Callable $self, $round = 1, $total = 1
178 178
             )
179 179
             use (
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                                 if (is_string($times)) {
296 296
                                     if (!isset($delimiter[$times])) {
297 297
                                         $data = Util::nestedValue($data, $times)
298
-                                            ? : $data;
298
+                                            ?: $data;
299 299
                                     } else {
300 300
                                         array_unshift($tokens, $times);
301 301
                                         $removeCount = 1;
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
                                 $data = is_array($sourceData)
331 331
                                 && isset($sourceData[$i - 1])
332 332
                                     ? $sourceData[$i - 1]
333
-                                    : @(string)$sourceData;
333
+                                    : @(string) $sourceData;
334 334
                                 $tokens = array_values($remainingTokens);
335 335
                                 $self($self, $i, $times);
336 336
                             }
Please login to merge, or discard this patch.
Braces   +18 added lines, -12 removed lines patch added patch discarded remove patch
@@ -25,8 +25,9 @@  discard block
 block discarded – undo
25 25
      */
26 26
     public static function make($string, $data = null)
27 27
     {
28
-        if (!strlen($string))
29
-            return array();
28
+        if (!strlen($string)) {
29
+                    return array();
30
+        }
30 31
 
31 32
         $implicitTag =
32 33
             function () use (& $tag) {
@@ -66,8 +67,8 @@  discard block
 block discarded – undo
66 67
                 & $tokens, & $tag
67 68
             ) {
68 69
                 $digits = 0;
69
-                if ($delimiter == null)
70
-                    $delimiter = array(
70
+                if ($delimiter == null) {
71
+                                    $delimiter = array(
71 72
                         '.' => true,
72 73
                         '#' => true,
73 74
                         '*' => true,
@@ -78,6 +79,7 @@  discard block
 block discarded – undo
78 79
                         ']' => true,
79 80
                         '=' => true,
80 81
                     );
82
+                }
81 83
                 while (!empty($tokens) &&
82 84
                     !isset($delimiter[$t = array_shift($tokens)])) {
83 85
                     while ('$' === $t) {
@@ -126,8 +128,9 @@  discard block
 block discarded – undo
126 128
                         $text .= $t;
127 129
                     }
128 130
                 }
129
-                if (isset($t))
130
-                    array_unshift($tokens, $t);
131
+                if (isset($t)) {
132
+                                    array_unshift($tokens, $t);
133
+                }
131 134
                 return $text;
132 135
             };
133 136
 
@@ -137,8 +140,9 @@  discard block
 block discarded – undo
137 140
                 $a = $parseText(
138 141
                     '', $round, $total, $data
139 142
                 );
140
-                if (is_null($a))
141
-                    return;
143
+                if (is_null($a)) {
144
+                                    return;
145
+                }
142 146
                 if ('=' == ($v = array_shift($tokens))) {
143 147
                     //value
144 148
                     if ('"' == ($v = array_shift($tokens))) {
@@ -266,11 +270,13 @@  discard block
 block discarded – undo
266 270
                                 break;
267 271
                             }
268 272
                             $tag = $tag->parent;
269
-                            if ($tag->parent)
270
-                                $tag = $tag->parent;
273
+                            if ($tag->parent) {
274
+                                                            $tag = $tag->parent;
275
+                            }
271 276
                             while ('^' == ($t = array_shift($tokens))) {
272
-                                if ($tag->parent)
273
-                                    $tag = $tag->parent;
277
+                                if ($tag->parent) {
278
+                                                                    $tag = $tag->parent;
279
+                                }
274 280
                             }
275 281
                             $child = new T($t);
276 282
                             $tag[] = $child;
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             };
133 133
 
134 134
         $parseAttributes =
135
-            function (Callable $self, $round, $total, $data)
135
+            function (callable $self, $round, $total, $data)
136 136
             use (& $tokens, & $tag, $parseText) {
137 137
                 $a = $parseText(
138 138
                     '', $round, $total, $data
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 
175 175
         $parse =
176 176
             function (
177
-                Callable $self, $round = 1, $total = 1
177
+                callable $self, $round = 1, $total = 1
178 178
             )
179 179
             use (
180 180
                 & $tokens, & $parent, & $tag, & $data,
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/Filter/RateLimit.php 3 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -19,160 +19,160 @@
 block discarded – undo
19 19
  */
20 20
 class RateLimit implements iFilter, iUseAuthentication
21 21
 {
22
-    /**
23
-     * @var \Luracast\Restler\Restler;
24
-     */
25
-    public $restler;
26
-    /**
27
-     * @var int
28
-     */
29
-    public static $usagePerUnit = 1200;
30
-    /**
31
-     * @var int
32
-     */
33
-    public static $authenticatedUsagePerUnit = 5000;
34
-    /**
35
-     * @var string
36
-     */
37
-    public static $unit = 'hour';
38
-    /**
39
-     * @var string group the current api belongs to
40
-     */
41
-    public static $group = 'common';
22
+	/**
23
+	 * @var \Luracast\Restler\Restler;
24
+	 */
25
+	public $restler;
26
+	/**
27
+	 * @var int
28
+	 */
29
+	public static $usagePerUnit = 1200;
30
+	/**
31
+	 * @var int
32
+	 */
33
+	public static $authenticatedUsagePerUnit = 5000;
34
+	/**
35
+	 * @var string
36
+	 */
37
+	public static $unit = 'hour';
38
+	/**
39
+	 * @var string group the current api belongs to
40
+	 */
41
+	public static $group = 'common';
42 42
 
43
-    protected static $units = array(
44
-        'second' => 1,
45
-        'minute' => 60,
46
-        'hour' => 3600, // 60*60 seconds
47
-        'day' => 86400, // 60*60*24 seconds
48
-        'week' => 604800, // 60*60*24*7 seconds
49
-        'month' => 2592000, // 60*60*24*30 seconds
50
-    );
43
+	protected static $units = array(
44
+		'second' => 1,
45
+		'minute' => 60,
46
+		'hour' => 3600, // 60*60 seconds
47
+		'day' => 86400, // 60*60*24 seconds
48
+		'week' => 604800, // 60*60*24*7 seconds
49
+		'month' => 2592000, // 60*60*24*30 seconds
50
+	);
51 51
 
52
-    /**
53
-     * @var array all paths beginning with any of the following will be excluded
54
-     * from documentation
55
-     */
56
-    public static $excludedPaths = array('explorer');
52
+	/**
53
+	 * @var array all paths beginning with any of the following will be excluded
54
+	 * from documentation
55
+	 */
56
+	public static $excludedPaths = array('explorer');
57 57
 
58 58
 
59
-    /**
60
-     * @param string $unit
61
-     * @param int    $usagePerUnit
62
-     * @param int    $authenticatedUsagePerUnit set it to false to give unlimited access
63
-     *
64
-     * @throws \InvalidArgumentException
65
-     * @return void
66
-     */
67
-    public static function setLimit(
68
-        $unit, $usagePerUnit, $authenticatedUsagePerUnit = null
69
-    )
70
-    {
71
-        static::$unit = $unit;
72
-        static::$usagePerUnit = $usagePerUnit;
73
-        static::$authenticatedUsagePerUnit =
74
-            is_null($authenticatedUsagePerUnit) ? $usagePerUnit : $authenticatedUsagePerUnit;
75
-    }
59
+	/**
60
+	 * @param string $unit
61
+	 * @param int    $usagePerUnit
62
+	 * @param int    $authenticatedUsagePerUnit set it to false to give unlimited access
63
+	 *
64
+	 * @throws \InvalidArgumentException
65
+	 * @return void
66
+	 */
67
+	public static function setLimit(
68
+		$unit, $usagePerUnit, $authenticatedUsagePerUnit = null
69
+	)
70
+	{
71
+		static::$unit = $unit;
72
+		static::$usagePerUnit = $usagePerUnit;
73
+		static::$authenticatedUsagePerUnit =
74
+			is_null($authenticatedUsagePerUnit) ? $usagePerUnit : $authenticatedUsagePerUnit;
75
+	}
76 76
 
77
-    public function __isAllowed()
78
-    {
79
-        if (static::$authenticatedUsagePerUnit
80
-            == static::$usagePerUnit
81
-        ) return $this->check();
82
-        return null;
83
-    }
77
+	public function __isAllowed()
78
+	{
79
+		if (static::$authenticatedUsagePerUnit
80
+			== static::$usagePerUnit
81
+		) return $this->check();
82
+		return null;
83
+	}
84 84
 
85
-    public function __setAuthenticationStatus($isAuthenticated = false)
86
-    {
87
-        header('X-Auth-Status: ' . ($isAuthenticated ? 'true' : 'false'));
88
-        $this->check($isAuthenticated);
89
-    }
85
+	public function __setAuthenticationStatus($isAuthenticated = false)
86
+	{
87
+		header('X-Auth-Status: ' . ($isAuthenticated ? 'true' : 'false'));
88
+		$this->check($isAuthenticated);
89
+	}
90 90
 
91
-    private static function validate($unit)
92
-    {
93
-        if (!isset(static::$units[$unit]))
94
-            throw new \InvalidArgumentException(
95
-                'Rate Limit time unit should be '
96
-                . implode('|', array_keys(static::$units)) . '.'
97
-            );
98
-    }
91
+	private static function validate($unit)
92
+	{
93
+		if (!isset(static::$units[$unit]))
94
+			throw new \InvalidArgumentException(
95
+				'Rate Limit time unit should be '
96
+				. implode('|', array_keys(static::$units)) . '.'
97
+			);
98
+	}
99 99
 
100
-    private function check($isAuthenticated = false)
101
-    {
102
-        $path = $this->restler->url;
103
-        foreach (static::$excludedPaths as $exclude) {
104
-            if (empty($exclude) && empty($path)) {
105
-                return true;
106
-            } elseif (0 === strpos($path, $exclude)) {
107
-                return true;
108
-            }
109
-        }
110
-        static::validate(static::$unit);
111
-        $timeUnit = static::$units[static::$unit];
112
-        $maxPerUnit = $isAuthenticated
113
-            ? static::$authenticatedUsagePerUnit
114
-            : static::$usagePerUnit;
115
-        if ($maxPerUnit) {
116
-            $user = Defaults::$userIdentifierClass;
117
-            if (!method_exists($user, 'getUniqueIdentifier')) {
118
-                throw new \UnexpectedValueException('`Defaults::$userIdentifierClass` must implement `iIdentifyUser` interface');
119
-            }
120
-            $id = "RateLimit_" . $maxPerUnit . '_per_' . static::$unit
121
-                . '_for_' . static::$group
122
-                . '_' . $user::getUniqueIdentifier();
123
-            $lastRequest = $this->restler->cache->get($id, true)
124
-                ? : array('time' => 0, 'used' => 0);
125
-            $time = $lastRequest['time'];
126
-            $diff = time() - $time; # in seconds
127
-            $used = $lastRequest['used'];
100
+	private function check($isAuthenticated = false)
101
+	{
102
+		$path = $this->restler->url;
103
+		foreach (static::$excludedPaths as $exclude) {
104
+			if (empty($exclude) && empty($path)) {
105
+				return true;
106
+			} elseif (0 === strpos($path, $exclude)) {
107
+				return true;
108
+			}
109
+		}
110
+		static::validate(static::$unit);
111
+		$timeUnit = static::$units[static::$unit];
112
+		$maxPerUnit = $isAuthenticated
113
+			? static::$authenticatedUsagePerUnit
114
+			: static::$usagePerUnit;
115
+		if ($maxPerUnit) {
116
+			$user = Defaults::$userIdentifierClass;
117
+			if (!method_exists($user, 'getUniqueIdentifier')) {
118
+				throw new \UnexpectedValueException('`Defaults::$userIdentifierClass` must implement `iIdentifyUser` interface');
119
+			}
120
+			$id = "RateLimit_" . $maxPerUnit . '_per_' . static::$unit
121
+				. '_for_' . static::$group
122
+				. '_' . $user::getUniqueIdentifier();
123
+			$lastRequest = $this->restler->cache->get($id, true)
124
+				? : array('time' => 0, 'used' => 0);
125
+			$time = $lastRequest['time'];
126
+			$diff = time() - $time; # in seconds
127
+			$used = $lastRequest['used'];
128 128
 
129
-            header("X-RateLimit-Limit: $maxPerUnit per " . static::$unit);
130
-            if ($diff >= $timeUnit) {
131
-                $used = 1;
132
-                $time = time();
133
-            } elseif ($used >= $maxPerUnit) {
134
-                header("X-RateLimit-Remaining: 0");
135
-                $wait = $timeUnit - $diff;
136
-                sleep(1);
137
-                throw new RestException(429,
138
-                    'Rate limit of ' . $maxPerUnit . ' request' .
139
-                    ($maxPerUnit > 1 ? 's' : '') . ' per '
140
-                    . static::$unit . ' exceeded. Please wait for '
141
-                    . static::duration($wait) . '.'
142
-                );
143
-            } else {
144
-                $used++;
145
-            }
146
-            $remainingPerUnit = $maxPerUnit - $used;
147
-            header("X-RateLimit-Remaining: $remainingPerUnit");
148
-            $this->restler->cache->set($id,
149
-                array('time' => $time, 'used' => $used));
150
-        }
151
-        return true;
152
-    }
129
+			header("X-RateLimit-Limit: $maxPerUnit per " . static::$unit);
130
+			if ($diff >= $timeUnit) {
131
+				$used = 1;
132
+				$time = time();
133
+			} elseif ($used >= $maxPerUnit) {
134
+				header("X-RateLimit-Remaining: 0");
135
+				$wait = $timeUnit - $diff;
136
+				sleep(1);
137
+				throw new RestException(429,
138
+					'Rate limit of ' . $maxPerUnit . ' request' .
139
+					($maxPerUnit > 1 ? 's' : '') . ' per '
140
+					. static::$unit . ' exceeded. Please wait for '
141
+					. static::duration($wait) . '.'
142
+				);
143
+			} else {
144
+				$used++;
145
+			}
146
+			$remainingPerUnit = $maxPerUnit - $used;
147
+			header("X-RateLimit-Remaining: $remainingPerUnit");
148
+			$this->restler->cache->set($id,
149
+				array('time' => $time, 'used' => $used));
150
+		}
151
+		return true;
152
+	}
153 153
 
154
-    private function duration($secs)
155
-    {
156
-        $units = array(
157
-            'week' => (int)($secs / 86400 / 7),
158
-            'day' => $secs / 86400 % 7,
159
-            'hour' => $secs / 3600 % 24,
160
-            'minute' => $secs / 60 % 60,
161
-            'second' => $secs % 60);
154
+	private function duration($secs)
155
+	{
156
+		$units = array(
157
+			'week' => (int)($secs / 86400 / 7),
158
+			'day' => $secs / 86400 % 7,
159
+			'hour' => $secs / 3600 % 24,
160
+			'minute' => $secs / 60 % 60,
161
+			'second' => $secs % 60);
162 162
 
163
-        $ret = array();
163
+		$ret = array();
164 164
 
165
-        //$unit = 'days';
166
-        foreach ($units as $k => $v) {
167
-            if ($v > 0) {
168
-                $ret[] = $v > 1 ? "$v {$k}s" : "$v $k";
169
-                //$unit = $k;
170
-            }
171
-        }
172
-        $i = count($ret) - 1;
173
-        if ($i) {
174
-            $ret[$i] = 'and ' . $ret[$i];
175
-        }
176
-        return implode(' ', $ret); //." $unit.";
177
-    }
165
+		//$unit = 'days';
166
+		foreach ($units as $k => $v) {
167
+			if ($v > 0) {
168
+				$ret[] = $v > 1 ? "$v {$k}s" : "$v $k";
169
+				//$unit = $k;
170
+			}
171
+		}
172
+		$i = count($ret) - 1;
173
+		if ($i) {
174
+			$ret[$i] = 'and ' . $ret[$i];
175
+		}
176
+		return implode(' ', $ret); //." $unit.";
177
+	}
178 178
 }
179 179
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
     public function __setAuthenticationStatus($isAuthenticated = false)
86 86
     {
87
-        header('X-Auth-Status: ' . ($isAuthenticated ? 'true' : 'false'));
87
+        header('X-Auth-Status: '.($isAuthenticated ? 'true' : 'false'));
88 88
         $this->check($isAuthenticated);
89 89
     }
90 90
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         if (!isset(static::$units[$unit]))
94 94
             throw new \InvalidArgumentException(
95 95
                 'Rate Limit time unit should be '
96
-                . implode('|', array_keys(static::$units)) . '.'
96
+                . implode('|', array_keys(static::$units)).'.'
97 97
             );
98 98
     }
99 99
 
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
             if (!method_exists($user, 'getUniqueIdentifier')) {
118 118
                 throw new \UnexpectedValueException('`Defaults::$userIdentifierClass` must implement `iIdentifyUser` interface');
119 119
             }
120
-            $id = "RateLimit_" . $maxPerUnit . '_per_' . static::$unit
121
-                . '_for_' . static::$group
122
-                . '_' . $user::getUniqueIdentifier();
120
+            $id = "RateLimit_".$maxPerUnit.'_per_'.static::$unit
121
+                . '_for_'.static::$group
122
+                . '_'.$user::getUniqueIdentifier();
123 123
             $lastRequest = $this->restler->cache->get($id, true)
124
-                ? : array('time' => 0, 'used' => 0);
124
+                ?: array('time' => 0, 'used' => 0);
125 125
             $time = $lastRequest['time'];
126 126
             $diff = time() - $time; # in seconds
127 127
             $used = $lastRequest['used'];
128 128
 
129
-            header("X-RateLimit-Limit: $maxPerUnit per " . static::$unit);
129
+            header("X-RateLimit-Limit: $maxPerUnit per ".static::$unit);
130 130
             if ($diff >= $timeUnit) {
131 131
                 $used = 1;
132 132
                 $time = time();
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
                 $wait = $timeUnit - $diff;
136 136
                 sleep(1);
137 137
                 throw new RestException(429,
138
-                    'Rate limit of ' . $maxPerUnit . ' request' .
139
-                    ($maxPerUnit > 1 ? 's' : '') . ' per '
140
-                    . static::$unit . ' exceeded. Please wait for '
141
-                    . static::duration($wait) . '.'
138
+                    'Rate limit of '.$maxPerUnit.' request'.
139
+                    ($maxPerUnit > 1 ? 's' : '').' per '
140
+                    . static::$unit.' exceeded. Please wait for '
141
+                    . static::duration($wait).'.'
142 142
                 );
143 143
             } else {
144 144
                 $used++;
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
     private function duration($secs)
155 155
     {
156 156
         $units = array(
157
-            'week' => (int)($secs / 86400 / 7),
157
+            'week' => (int) ($secs / 86400 / 7),
158 158
             'day' => $secs / 86400 % 7,
159 159
             'hour' => $secs / 3600 % 24,
160 160
             'minute' => $secs / 60 % 60,
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         }
172 172
         $i = count($ret) - 1;
173 173
         if ($i) {
174
-            $ret[$i] = 'and ' . $ret[$i];
174
+            $ret[$i] = 'and '.$ret[$i];
175 175
         }
176 176
         return implode(' ', $ret); //." $unit.";
177 177
     }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -78,7 +78,9 @@  discard block
 block discarded – undo
78 78
     {
79 79
         if (static::$authenticatedUsagePerUnit
80 80
             == static::$usagePerUnit
81
-        ) return $this->check();
81
+        ) {
82
+        	return $this->check();
83
+        }
82 84
         return null;
83 85
     }
84 86
 
@@ -90,11 +92,12 @@  discard block
 block discarded – undo
90 92
 
91 93
     private static function validate($unit)
92 94
     {
93
-        if (!isset(static::$units[$unit]))
94
-            throw new \InvalidArgumentException(
95
+        if (!isset(static::$units[$unit])) {
96
+                    throw new \InvalidArgumentException(
95 97
                 'Rate Limit time unit should be '
96 98
                 . implode('|', array_keys(static::$units)) . '.'
97 99
             );
100
+        }
98 101
     }
99 102
 
100 103
     private function check($isAuthenticated = false)
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/Format/AmfFormat.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -21,28 +21,28 @@
 block discarded – undo
21 21
  */
22 22
 class AmfFormat extends DependentFormat
23 23
 {
24
-    const MIME = 'application/x-amf';
25
-    const EXTENSION = 'amf';
24
+	const MIME = 'application/x-amf';
25
+	const EXTENSION = 'amf';
26 26
 
27
-    const PACKAGE_NAME = 'zendframework/zendamf:dev-master';
28
-    const EXTERNAL_CLASS = 'ZendAmf\\Parser\\Amf3\\Deserializer';
27
+	const PACKAGE_NAME = 'zendframework/zendamf:dev-master';
28
+	const EXTERNAL_CLASS = 'ZendAmf\\Parser\\Amf3\\Deserializer';
29 29
 
30
-    public function encode($data, $humanReadable = false)
31
-    {
30
+	public function encode($data, $humanReadable = false)
31
+	{
32 32
 
33
-        $stream = new OutputStream();
34
-        $serializer = new Serializer($stream);
35
-        $serializer->writeTypeMarker($data);
33
+		$stream = new OutputStream();
34
+		$serializer = new Serializer($stream);
35
+		$serializer->writeTypeMarker($data);
36 36
 
37
-        return $stream->getStream();
38
-    }
37
+		return $stream->getStream();
38
+	}
39 39
 
40
-    public function decode($data)
41
-    {
42
-        $stream = new InputStream(substr($data, 1));
43
-        $deserializer = new Deserializer($stream);
40
+	public function decode($data)
41
+	{
42
+		$stream = new InputStream(substr($data, 1));
43
+		$deserializer = new Deserializer($stream);
44 44
 
45
-        return $deserializer->readTypeMarker();
46
-    }
45
+		return $deserializer->readTypeMarker();
46
+	}
47 47
 }
48 48
 
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/Format/Format.php 2 patches
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -14,127 +14,127 @@
 block discarded – undo
14 14
  */
15 15
 abstract class Format implements iFormat
16 16
 {
17
-    /**
18
-     * override in the extending class
19
-     */
20
-    const MIME = 'text/plain';
21
-    /**
22
-     * override in the extending class
23
-     */
24
-    const EXTENSION = 'txt';
17
+	/**
18
+	 * override in the extending class
19
+	 */
20
+	const MIME = 'text/plain';
21
+	/**
22
+	 * override in the extending class
23
+	 */
24
+	const EXTENSION = 'txt';
25 25
 
26
-    /**
27
-     * @var string charset encoding defaults to UTF8
28
-     */
29
-    protected $charset='utf-8';
26
+	/**
27
+	 * @var string charset encoding defaults to UTF8
28
+	 */
29
+	protected $charset='utf-8';
30 30
 
31
-    /**
32
-     * Injected at runtime
33
-     *
34
-     * @var \Luracast\Restler\Restler
35
-     */
36
-    public $restler;
31
+	/**
32
+	 * Injected at runtime
33
+	 *
34
+	 * @var \Luracast\Restler\Restler
35
+	 */
36
+	public $restler;
37 37
 
38
-    /**
39
-     * Get MIME type => Extension mappings as an associative array
40
-     *
41
-     * @return array list of mime strings for the format
42
-     * @example array('application/json'=>'json');
43
-     */
44
-    public function getMIMEMap()
45
-    {
46
-        return array(
47
-            static::MIME =>  static::EXTENSION
48
-        );
49
-    }
38
+	/**
39
+	 * Get MIME type => Extension mappings as an associative array
40
+	 *
41
+	 * @return array list of mime strings for the format
42
+	 * @example array('application/json'=>'json');
43
+	 */
44
+	public function getMIMEMap()
45
+	{
46
+		return array(
47
+			static::MIME =>  static::EXTENSION
48
+		);
49
+	}
50 50
 
51
-    /**
52
-     * Set the selected MIME type
53
-     *
54
-     * @param string $mime
55
-     *            MIME type
56
-     */
57
-    public function setMIME($mime)
58
-    {
59
-        //do nothing
60
-    }
51
+	/**
52
+	 * Set the selected MIME type
53
+	 *
54
+	 * @param string $mime
55
+	 *            MIME type
56
+	 */
57
+	public function setMIME($mime)
58
+	{
59
+		//do nothing
60
+	}
61 61
 
62
-    /**
63
-     * Content-Type field of the HTTP header can send a charset
64
-     * parameter in the HTTP header to specify the character
65
-     * encoding of the document.
66
-     * This information is passed
67
-     * here so that Format class can encode data accordingly
68
-     * Format class may choose to ignore this and use its
69
-     * default character set.
70
-     *
71
-     * @param string $charset
72
-     *            Example utf-8
73
-     */
74
-    public function setCharset($charset)
75
-    {
76
-        $this->charset = $charset;
77
-    }
62
+	/**
63
+	 * Content-Type field of the HTTP header can send a charset
64
+	 * parameter in the HTTP header to specify the character
65
+	 * encoding of the document.
66
+	 * This information is passed
67
+	 * here so that Format class can encode data accordingly
68
+	 * Format class may choose to ignore this and use its
69
+	 * default character set.
70
+	 *
71
+	 * @param string $charset
72
+	 *            Example utf-8
73
+	 */
74
+	public function setCharset($charset)
75
+	{
76
+		$this->charset = $charset;
77
+	}
78 78
 
79
-    /**
80
-     * Content-Type accepted by the Format class
81
-     *
82
-     * @return string $charset Example utf-8
83
-     */
84
-    public function getCharset()
85
-    {
86
-        return $this->charset;
87
-    }
79
+	/**
80
+	 * Content-Type accepted by the Format class
81
+	 *
82
+	 * @return string $charset Example utf-8
83
+	 */
84
+	public function getCharset()
85
+	{
86
+		return $this->charset;
87
+	}
88 88
 
89
-    /**
90
-     * Get selected MIME type
91
-     */
92
-    public function getMIME()
93
-    {
94
-        return static::MIME;
95
-    }
89
+	/**
90
+	 * Get selected MIME type
91
+	 */
92
+	public function getMIME()
93
+	{
94
+		return static::MIME;
95
+	}
96 96
 
97
-    /**
98
-     * Set the selected file extension
99
-     *
100
-     * @param string $extension
101
-     *            file extension
102
-     */
103
-    public function setExtension($extension)
104
-    {
105
-        //do nothing;
106
-    }
97
+	/**
98
+	 * Set the selected file extension
99
+	 *
100
+	 * @param string $extension
101
+	 *            file extension
102
+	 */
103
+	public function setExtension($extension)
104
+	{
105
+		//do nothing;
106
+	}
107 107
 
108
-    /**
109
-     * Get the selected file extension
110
-     *
111
-     * @return string file extension
112
-     */
113
-    public function getExtension()
114
-    {
115
-        return static::EXTENSION;
116
-    }
108
+	/**
109
+	 * Get the selected file extension
110
+	 *
111
+	 * @return string file extension
112
+	 */
113
+	public function getExtension()
114
+	{
115
+		return static::EXTENSION;
116
+	}
117 117
 
118
-    /**
119
-     * @return boolean is parsing the request supported?
120
-     */
121
-    public function isReadable()
122
-    {
123
-        return true;
124
-    }
118
+	/**
119
+	 * @return boolean is parsing the request supported?
120
+	 */
121
+	public function isReadable()
122
+	{
123
+		return true;
124
+	}
125 125
 
126
-    /**
127
-     * @return boolean is composing response supported?
128
-     */
129
-    public function isWritable()
130
-    {
131
-        return true;
132
-    }
126
+	/**
127
+	 * @return boolean is composing response supported?
128
+	 */
129
+	public function isWritable()
130
+	{
131
+		return true;
132
+	}
133 133
 
134
-    public function __toString()
135
-    {
136
-        return $this->getExtension();
137
-    }
134
+	public function __toString()
135
+	{
136
+		return $this->getExtension();
137
+	}
138 138
 
139 139
 }
140 140
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
     /**
27 27
      * @var string charset encoding defaults to UTF8
28 28
      */
29
-    protected $charset='utf-8';
29
+    protected $charset = 'utf-8';
30 30
 
31 31
     /**
32 32
      * Injected at runtime
Please login to merge, or discard this patch.