@@ -106,7 +106,7 @@ |
||
| 106 | 106 | /** |
| 107 | 107 | * get the calculated value of this condition supplied by the subtotal|price |
| 108 | 108 | * |
| 109 | - * @param $totalOrSubTotalOrPrice |
|
| 109 | + * @param double $totalOrSubTotalOrPrice |
|
| 110 | 110 | * @return mixed |
| 111 | 111 | */ |
| 112 | 112 | public function getCalculatedValue($totalOrSubTotalOrPrice) |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | $this->args = $args; |
| 34 | 34 | |
| 35 | - if( Helpers::isMultiArray($args) ) |
|
| 35 | + if (Helpers::isMultiArray($args)) |
|
| 36 | 36 | { |
| 37 | 37 | Throw new InvalidConditionException('Multi dimensional array is not supported.'); |
| 38 | 38 | } |
@@ -130,19 +130,19 @@ discard block |
||
| 130 | 130 | // has a minus or plus sign so we can decide what to do with the |
| 131 | 131 | // percentage, whether to add or subtract it to the total/subtotal/price |
| 132 | 132 | // if we can't find any plus/minus sign, we will assume it as plus sign |
| 133 | - if( $this->valueIsPercentage($conditionValue) ) |
|
| 133 | + if ($this->valueIsPercentage($conditionValue)) |
|
| 134 | 134 | { |
| 135 | - if( $this->valueIsToBeSubtracted($conditionValue) ) |
|
| 135 | + if ($this->valueIsToBeSubtracted($conditionValue)) |
|
| 136 | 136 | { |
| 137 | - $value = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
|
| 137 | + $value = Helpers::normalizePrice($this->cleanValue($conditionValue)); |
|
| 138 | 138 | |
| 139 | 139 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
| 140 | 140 | |
| 141 | 141 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
| 142 | 142 | } |
| 143 | - else if ( $this->valueIsToBeAdded($conditionValue) ) |
|
| 143 | + else if ($this->valueIsToBeAdded($conditionValue)) |
|
| 144 | 144 | { |
| 145 | - $value = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
|
| 145 | + $value = Helpers::normalizePrice($this->cleanValue($conditionValue)); |
|
| 146 | 146 | |
| 147 | 147 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
| 148 | 148 | |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | // next is we will check if it has a minus/plus sign so then we can just deduct it to total/subtotal/price |
| 163 | 163 | else |
| 164 | 164 | { |
| 165 | - if( $this->valueIsToBeSubtracted($conditionValue) ) |
|
| 165 | + if ($this->valueIsToBeSubtracted($conditionValue)) |
|
| 166 | 166 | { |
| 167 | - $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
|
| 167 | + $this->parsedRawValue = Helpers::normalizePrice($this->cleanValue($conditionValue)); |
|
| 168 | 168 | |
| 169 | 169 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
| 170 | 170 | } |
| 171 | - else if ( $this->valueIsToBeAdded($conditionValue) ) |
|
| 171 | + else if ($this->valueIsToBeAdded($conditionValue)) |
|
| 172 | 172 | { |
| 173 | - $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
|
| 173 | + $this->parsedRawValue = Helpers::normalizePrice($this->cleanValue($conditionValue)); |
|
| 174 | 174 | |
| 175 | 175 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
| 176 | 176 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | protected function cleanValue($value) |
| 228 | 228 | { |
| 229 | - return str_replace(array('%','-','+'),'',$value); |
|
| 229 | + return str_replace(array('%', '-', '+'), '', $value); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | $validator = CartConditionValidator::make($args, $rules); |
| 248 | 248 | |
| 249 | - if( $validator->fails() ) |
|
| 249 | + if ($validator->fails()) |
|
| 250 | 250 | { |
| 251 | 251 | throw new InvalidConditionException($validator->messages()->first()); |
| 252 | 252 | } |
@@ -35,8 +35,7 @@ discard block |
||
| 35 | 35 | if( Helpers::isMultiArray($args) ) |
| 36 | 36 | { |
| 37 | 37 | Throw new InvalidConditionException('Multi dimensional array is not supported.'); |
| 38 | - } |
|
| 39 | - else |
|
| 38 | + } else |
|
| 40 | 39 | { |
| 41 | 40 | $this->validate($this->args); |
| 42 | 41 | } |
@@ -139,16 +138,14 @@ discard block |
||
| 139 | 138 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
| 140 | 139 | |
| 141 | 140 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
| 142 | - } |
|
| 143 | - else if ( $this->valueIsToBeAdded($conditionValue) ) |
|
| 141 | + } else if ( $this->valueIsToBeAdded($conditionValue) ) |
|
| 144 | 142 | { |
| 145 | 143 | $value = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
| 146 | 144 | |
| 147 | 145 | $this->parsedRawValue = $totalOrSubTotalOrPrice * ($value / 100); |
| 148 | 146 | |
| 149 | 147 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
| 150 | - } |
|
| 151 | - else |
|
| 148 | + } else |
|
| 152 | 149 | { |
| 153 | 150 | $value = Helpers::normalizePrice($conditionValue); |
| 154 | 151 | |
@@ -167,14 +164,12 @@ discard block |
||
| 167 | 164 | $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
| 168 | 165 | |
| 169 | 166 | $result = floatval($totalOrSubTotalOrPrice - $this->parsedRawValue); |
| 170 | - } |
|
| 171 | - else if ( $this->valueIsToBeAdded($conditionValue) ) |
|
| 167 | + } else if ( $this->valueIsToBeAdded($conditionValue) ) |
|
| 172 | 168 | { |
| 173 | 169 | $this->parsedRawValue = Helpers::normalizePrice( $this->cleanValue($conditionValue) ); |
| 174 | 170 | |
| 175 | 171 | $result = floatval($totalOrSubTotalOrPrice + $this->parsedRawValue); |
| 176 | - } |
|
| 177 | - else |
|
| 172 | + } else |
|
| 178 | 173 | { |
| 179 | 174 | $this->parsedRawValue = Helpers::normalizePrice($conditionValue); |
| 180 | 175 | |
@@ -450,11 +450,6 @@ discard block |
||
| 450 | 450 | /** |
| 451 | 451 | * Create a select year field. |
| 452 | 452 | * |
| 453 | - * @param string $name |
|
| 454 | - * @param string $begin |
|
| 455 | - * @param string $end |
|
| 456 | - * @param string $selected |
|
| 457 | - * @param array $options |
|
| 458 | 453 | * @return string |
| 459 | 454 | */ |
| 460 | 455 | public function selectYear() |
@@ -559,7 +554,7 @@ discard block |
||
| 559 | 554 | * Create a checkbox input field. |
| 560 | 555 | * |
| 561 | 556 | * @param string $name |
| 562 | - * @param mixed $value |
|
| 557 | + * @param integer $value |
|
| 563 | 558 | * @param bool $checked |
| 564 | 559 | * @param array $options |
| 565 | 560 | * @return string |
@@ -6,969 +6,969 @@ |
||
| 6 | 6 | |
| 7 | 7 | class FormBuilder { |
| 8 | 8 | |
| 9 | - use Macroable; |
|
| 10 | - |
|
| 11 | - /** |
|
| 12 | - * The HTML builder instance. |
|
| 13 | - * |
|
| 14 | - * @var \Illuminate\Html\HtmlBuilder |
|
| 15 | - */ |
|
| 16 | - protected $html; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * The URL generator instance. |
|
| 20 | - * |
|
| 21 | - * @var \Illuminate\Routing\UrlGenerator $url |
|
| 22 | - */ |
|
| 23 | - protected $url; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * The CSRF token used by the form builder. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $csrfToken; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * The session store implementation. |
|
| 34 | - * |
|
| 35 | - * @var \Illuminate\Session\Store |
|
| 36 | - */ |
|
| 37 | - protected $session; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * The current model instance for the form. |
|
| 41 | - * |
|
| 42 | - * @var mixed |
|
| 43 | - */ |
|
| 44 | - protected $model; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * An array of label names we've created. |
|
| 48 | - * |
|
| 49 | - * @var array |
|
| 50 | - */ |
|
| 51 | - protected $labels = array(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * The reserved form open attributes. |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - protected $reserved = array('method', 'url', 'route', 'action', 'files'); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The form methods that should be spoofed, in uppercase. |
|
| 62 | - * |
|
| 63 | - * @var array |
|
| 64 | - */ |
|
| 65 | - protected $spoofedMethods = array('DELETE', 'PATCH', 'PUT'); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * The types of inputs to not fill values on by default. |
|
| 69 | - * |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - protected $skipValueTypes = array('file', 'password', 'checkbox', 'radio'); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Create a new form builder instance. |
|
| 76 | - * |
|
| 77 | - * @param \Illuminate\Routing\UrlGenerator $url |
|
| 78 | - * @param \Illuminate\Html\HtmlBuilder $html |
|
| 79 | - * @param string $csrfToken |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - public function __construct(HtmlBuilder $html, UrlGenerator $url, $csrfToken) |
|
| 83 | - { |
|
| 84 | - $this->url = $url; |
|
| 85 | - $this->html = $html; |
|
| 86 | - $this->csrfToken = $csrfToken; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Open up a new HTML form. |
|
| 91 | - * |
|
| 92 | - * @param array $options |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public function open(array $options = array()) |
|
| 96 | - { |
|
| 97 | - $method = array_get($options, 'method', 'post'); |
|
| 98 | - |
|
| 99 | - // We need to extract the proper method from the attributes. If the method is |
|
| 100 | - // something other than GET or POST we'll use POST since we will spoof the |
|
| 101 | - // actual method since forms don't support the reserved methods in HTML. |
|
| 102 | - $attributes['method'] = $this->getMethod($method); |
|
| 103 | - |
|
| 104 | - $attributes['action'] = $this->getAction($options); |
|
| 105 | - |
|
| 106 | - $attributes['accept-charset'] = 'UTF-8'; |
|
| 107 | - |
|
| 108 | - // If the method is PUT, PATCH or DELETE we will need to add a spoofer hidden |
|
| 109 | - // field that will instruct the Symfony request to pretend the method is a |
|
| 110 | - // different method than it actually is, for convenience from the forms. |
|
| 111 | - $append = $this->getAppendage($method); |
|
| 112 | - |
|
| 113 | - if (isset($options['files']) && $options['files']) |
|
| 114 | - { |
|
| 115 | - $options['enctype'] = 'multipart/form-data'; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // Finally we're ready to create the final form HTML field. We will attribute |
|
| 119 | - // format the array of attributes. We will also add on the appendage which |
|
| 120 | - // is used to spoof requests for this PUT, PATCH, etc. methods on forms. |
|
| 121 | - $attributes = array_merge( |
|
| 122 | - |
|
| 123 | - $attributes, array_except($options, $this->reserved) |
|
| 124 | - |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Finally, we will concatenate all of the attributes into a single string so |
|
| 128 | - // we can build out the final form open statement. We'll also append on an |
|
| 129 | - // extra value for the hidden _method field if it's needed for the form. |
|
| 130 | - $attributes = $this->html->attributes($attributes); |
|
| 131 | - |
|
| 132 | - return '<form'.$attributes.'>'.$append; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Create a new model based form builder. |
|
| 137 | - * |
|
| 138 | - * @param mixed $model |
|
| 139 | - * @param array $options |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function model($model, array $options = array()) |
|
| 143 | - { |
|
| 144 | - $this->model = $model; |
|
| 145 | - |
|
| 146 | - return $this->open($options); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Set the model instance on the form builder. |
|
| 151 | - * |
|
| 152 | - * @param mixed $model |
|
| 153 | - * @return void |
|
| 154 | - */ |
|
| 155 | - public function setModel($model) |
|
| 156 | - { |
|
| 157 | - $this->model = $model; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Close the current form. |
|
| 162 | - * |
|
| 163 | - * @return string |
|
| 164 | - */ |
|
| 165 | - public function close() |
|
| 166 | - { |
|
| 167 | - $this->labels = array(); |
|
| 168 | - |
|
| 169 | - $this->model = null; |
|
| 170 | - |
|
| 171 | - return '</form>'; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Generate a hidden field with the current CSRF token. |
|
| 176 | - * |
|
| 177 | - * @return string |
|
| 178 | - */ |
|
| 179 | - public function token() |
|
| 180 | - { |
|
| 181 | - $token = ! empty($this->csrfToken) ? $this->csrfToken : $this->session->getToken(); |
|
| 182 | - |
|
| 183 | - return $this->hidden('_token', $token); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Create a form label element. |
|
| 188 | - * |
|
| 189 | - * @param string $name |
|
| 190 | - * @param string $value |
|
| 191 | - * @param array $options |
|
| 192 | - * @return string |
|
| 193 | - */ |
|
| 194 | - public function label($name, $value = null, $options = array()) |
|
| 195 | - { |
|
| 196 | - $this->labels[] = $name; |
|
| 197 | - |
|
| 198 | - $options = $this->html->attributes($options); |
|
| 199 | - |
|
| 200 | - $value = e($this->formatLabel($name, $value)); |
|
| 201 | - |
|
| 202 | - return '<label for="'.$name.'"'.$options.'>'.$value.'</label>'; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Format the label value. |
|
| 207 | - * |
|
| 208 | - * @param string $name |
|
| 209 | - * @param string|null $value |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - protected function formatLabel($name, $value) |
|
| 213 | - { |
|
| 214 | - return $value ?: ucwords(str_replace('_', ' ', $name)); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Create a form input field. |
|
| 219 | - * |
|
| 220 | - * @param string $type |
|
| 221 | - * @param string $name |
|
| 222 | - * @param string $value |
|
| 223 | - * @param array $options |
|
| 224 | - * @return string |
|
| 225 | - */ |
|
| 226 | - public function input($type, $name, $value = null, $options = array()) |
|
| 227 | - { |
|
| 228 | - if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 229 | - |
|
| 230 | - // We will get the appropriate value for the given field. We will look for the |
|
| 231 | - // value in the session for the value in the old input data then we'll look |
|
| 232 | - // in the model instance if one is set. Otherwise we will just use empty. |
|
| 233 | - $id = $this->getIdAttribute($name, $options); |
|
| 234 | - |
|
| 235 | - if ( ! in_array($type, $this->skipValueTypes)) |
|
| 236 | - { |
|
| 237 | - $value = $this->getValueAttribute($name, $value); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // Once we have the type, value, and ID we can merge them into the rest of the |
|
| 241 | - // attributes array so we can convert them into their HTML attribute format |
|
| 242 | - // when creating the HTML element. Then, we will return the entire input. |
|
| 243 | - $merge = compact('type', 'value', 'id'); |
|
| 244 | - |
|
| 245 | - $options = array_merge($options, $merge); |
|
| 246 | - |
|
| 247 | - return '<input'.$this->html->attributes($options).'>'; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Create a text input field. |
|
| 252 | - * |
|
| 253 | - * @param string $name |
|
| 254 | - * @param string $value |
|
| 255 | - * @param array $options |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function text($name, $value = null, $options = array()) |
|
| 259 | - { |
|
| 260 | - return $this->input('text', $name, $value, $options); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Create a password input field. |
|
| 265 | - * |
|
| 266 | - * @param string $name |
|
| 267 | - * @param array $options |
|
| 268 | - * @return string |
|
| 269 | - */ |
|
| 270 | - public function password($name, $options = array()) |
|
| 271 | - { |
|
| 272 | - return $this->input('password', $name, '', $options); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Create a hidden input field. |
|
| 277 | - * |
|
| 278 | - * @param string $name |
|
| 279 | - * @param string $value |
|
| 280 | - * @param array $options |
|
| 281 | - * @return string |
|
| 282 | - */ |
|
| 283 | - public function hidden($name, $value = null, $options = array()) |
|
| 284 | - { |
|
| 285 | - return $this->input('hidden', $name, $value, $options); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Create an e-mail input field. |
|
| 290 | - * |
|
| 291 | - * @param string $name |
|
| 292 | - * @param string $value |
|
| 293 | - * @param array $options |
|
| 294 | - * @return string |
|
| 295 | - */ |
|
| 296 | - public function email($name, $value = null, $options = array()) |
|
| 297 | - { |
|
| 298 | - return $this->input('email', $name, $value, $options); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Create a url input field. |
|
| 303 | - * |
|
| 304 | - * @param string $name |
|
| 305 | - * @param string $value |
|
| 306 | - * @param array $options |
|
| 307 | - * @return string |
|
| 308 | - */ |
|
| 309 | - public function url($name, $value = null, $options = array()) |
|
| 310 | - { |
|
| 311 | - return $this->input('url', $name, $value, $options); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Create a file input field. |
|
| 316 | - * |
|
| 317 | - * @param string $name |
|
| 318 | - * @param array $options |
|
| 319 | - * @return string |
|
| 320 | - */ |
|
| 321 | - public function file($name, $options = array()) |
|
| 322 | - { |
|
| 323 | - return $this->input('file', $name, null, $options); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Create a textarea input field. |
|
| 328 | - * |
|
| 329 | - * @param string $name |
|
| 330 | - * @param string $value |
|
| 331 | - * @param array $options |
|
| 332 | - * @return string |
|
| 333 | - */ |
|
| 334 | - public function textarea($name, $value = null, $options = array()) |
|
| 335 | - { |
|
| 336 | - if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 337 | - |
|
| 338 | - // Next we will look for the rows and cols attributes, as each of these are put |
|
| 339 | - // on the textarea element definition. If they are not present, we will just |
|
| 340 | - // assume some sane default values for these attributes for the developer. |
|
| 341 | - $options = $this->setTextAreaSize($options); |
|
| 342 | - |
|
| 343 | - $options['id'] = $this->getIdAttribute($name, $options); |
|
| 344 | - |
|
| 345 | - $value = (string) $this->getValueAttribute($name, $value); |
|
| 346 | - |
|
| 347 | - unset($options['size']); |
|
| 348 | - |
|
| 349 | - // Next we will convert the attributes into a string form. Also we have removed |
|
| 350 | - // the size attribute, as it was merely a short-cut for the rows and cols on |
|
| 351 | - // the element. Then we'll create the final textarea elements HTML for us. |
|
| 352 | - $options = $this->html->attributes($options); |
|
| 353 | - |
|
| 354 | - return '<textarea'.$options.'>'.e($value).'</textarea>'; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Set the text area size on the attributes. |
|
| 359 | - * |
|
| 360 | - * @param array $options |
|
| 361 | - * @return array |
|
| 362 | - */ |
|
| 363 | - protected function setTextAreaSize($options) |
|
| 364 | - { |
|
| 365 | - if (isset($options['size'])) |
|
| 366 | - { |
|
| 367 | - return $this->setQuickTextAreaSize($options); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // If the "size" attribute was not specified, we will just look for the regular |
|
| 371 | - // columns and rows attributes, using sane defaults if these do not exist on |
|
| 372 | - // the attributes array. We'll then return this entire options array back. |
|
| 373 | - $cols = array_get($options, 'cols', 50); |
|
| 374 | - |
|
| 375 | - $rows = array_get($options, 'rows', 10); |
|
| 376 | - |
|
| 377 | - return array_merge($options, compact('cols', 'rows')); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Set the text area size using the quick "size" attribute. |
|
| 382 | - * |
|
| 383 | - * @param array $options |
|
| 384 | - * @return array |
|
| 385 | - */ |
|
| 386 | - protected function setQuickTextAreaSize($options) |
|
| 387 | - { |
|
| 388 | - $segments = explode('x', $options['size']); |
|
| 389 | - |
|
| 390 | - return array_merge($options, array('cols' => $segments[0], 'rows' => $segments[1])); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Create a select box field. |
|
| 395 | - * |
|
| 396 | - * @param string $name |
|
| 397 | - * @param array $list |
|
| 398 | - * @param string $selected |
|
| 399 | - * @param array $options |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function select($name, $list = array(), $selected = null, $options = array()) |
|
| 403 | - { |
|
| 404 | - // When building a select box the "value" attribute is really the selected one |
|
| 405 | - // so we will use that when checking the model or session for a value which |
|
| 406 | - // should provide a convenient method of re-populating the forms on post. |
|
| 407 | - $selected = $this->getValueAttribute($name, $selected); |
|
| 408 | - |
|
| 409 | - $options['id'] = $this->getIdAttribute($name, $options); |
|
| 410 | - |
|
| 411 | - if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 412 | - |
|
| 413 | - // We will simply loop through the options and build an HTML value for each of |
|
| 414 | - // them until we have an array of HTML declarations. Then we will join them |
|
| 415 | - // all together into one single HTML element that can be put on the form. |
|
| 416 | - $html = array(); |
|
| 417 | - |
|
| 418 | - foreach ($list as $value => $display) |
|
| 419 | - { |
|
| 420 | - $html[] = $this->getSelectOption($display, $value, $selected); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - // Once we have all of this HTML, we can join this into a single element after |
|
| 424 | - // formatting the attributes into an HTML "attributes" string, then we will |
|
| 425 | - // build out a final select statement, which will contain all the values. |
|
| 426 | - $options = $this->html->attributes($options); |
|
| 427 | - |
|
| 428 | - $list = implode('', $html); |
|
| 429 | - |
|
| 430 | - return "<select{$options}>{$list}</select>"; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Create a select range field. |
|
| 435 | - * |
|
| 436 | - * @param string $name |
|
| 437 | - * @param string $begin |
|
| 438 | - * @param string $end |
|
| 439 | - * @param string $selected |
|
| 440 | - * @param array $options |
|
| 441 | - * @return string |
|
| 442 | - */ |
|
| 443 | - public function selectRange($name, $begin, $end, $selected = null, $options = array()) |
|
| 444 | - { |
|
| 445 | - $range = array_combine($range = range($begin, $end), $range); |
|
| 446 | - |
|
| 447 | - return $this->select($name, $range, $selected, $options); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Create a select year field. |
|
| 452 | - * |
|
| 453 | - * @param string $name |
|
| 454 | - * @param string $begin |
|
| 455 | - * @param string $end |
|
| 456 | - * @param string $selected |
|
| 457 | - * @param array $options |
|
| 458 | - * @return string |
|
| 459 | - */ |
|
| 460 | - public function selectYear() |
|
| 461 | - { |
|
| 462 | - return call_user_func_array(array($this, 'selectRange'), func_get_args()); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Create a select month field. |
|
| 467 | - * |
|
| 468 | - * @param string $name |
|
| 469 | - * @param string $selected |
|
| 470 | - * @param array $options |
|
| 471 | - * @param string $format |
|
| 472 | - * @return string |
|
| 473 | - */ |
|
| 474 | - public function selectMonth($name, $selected = null, $options = array(), $format = '%B') |
|
| 475 | - { |
|
| 476 | - $months = array(); |
|
| 477 | - |
|
| 478 | - foreach (range(1, 12) as $month) |
|
| 479 | - { |
|
| 480 | - $months[$month] = strftime($format, mktime(0, 0, 0, $month, 1)); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - return $this->select($name, $months, $selected, $options); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Get the select option for the given value. |
|
| 488 | - * |
|
| 489 | - * @param string $display |
|
| 490 | - * @param string $value |
|
| 491 | - * @param string $selected |
|
| 492 | - * @return string |
|
| 493 | - */ |
|
| 494 | - public function getSelectOption($display, $value, $selected) |
|
| 495 | - { |
|
| 496 | - if (is_array($display)) |
|
| 497 | - { |
|
| 498 | - return $this->optionGroup($display, $value, $selected); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - return $this->option($display, $value, $selected); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * Create an option group form element. |
|
| 506 | - * |
|
| 507 | - * @param array $list |
|
| 508 | - * @param string $label |
|
| 509 | - * @param string $selected |
|
| 510 | - * @return string |
|
| 511 | - */ |
|
| 512 | - protected function optionGroup($list, $label, $selected) |
|
| 513 | - { |
|
| 514 | - $html = array(); |
|
| 515 | - |
|
| 516 | - foreach ($list as $value => $display) |
|
| 517 | - { |
|
| 518 | - $html[] = $this->option($display, $value, $selected); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - return '<optgroup label="'.e($label).'">'.implode('', $html).'</optgroup>'; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Create a select element option. |
|
| 526 | - * |
|
| 527 | - * @param string $display |
|
| 528 | - * @param string $value |
|
| 529 | - * @param string $selected |
|
| 530 | - * @return string |
|
| 531 | - */ |
|
| 532 | - protected function option($display, $value, $selected) |
|
| 533 | - { |
|
| 534 | - $selected = $this->getSelectedValue($value, $selected); |
|
| 535 | - |
|
| 536 | - $options = array('value' => e($value), 'selected' => $selected); |
|
| 537 | - |
|
| 538 | - return '<option'.$this->html->attributes($options).'>'.e($display).'</option>'; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Determine if the value is selected. |
|
| 543 | - * |
|
| 544 | - * @param string $value |
|
| 545 | - * @param string $selected |
|
| 546 | - * @return string |
|
| 547 | - */ |
|
| 548 | - protected function getSelectedValue($value, $selected) |
|
| 549 | - { |
|
| 550 | - if (is_array($selected)) |
|
| 551 | - { |
|
| 552 | - return in_array($value, $selected) ? 'selected' : null; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - return ((string) $value == (string) $selected) ? 'selected' : null; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Create a checkbox input field. |
|
| 560 | - * |
|
| 561 | - * @param string $name |
|
| 562 | - * @param mixed $value |
|
| 563 | - * @param bool $checked |
|
| 564 | - * @param array $options |
|
| 565 | - * @return string |
|
| 566 | - */ |
|
| 567 | - public function checkbox($name, $value = 1, $checked = null, $options = array()) |
|
| 568 | - { |
|
| 569 | - return $this->checkable('checkbox', $name, $value, $checked, $options); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Create a radio button input field. |
|
| 574 | - * |
|
| 575 | - * @param string $name |
|
| 576 | - * @param mixed $value |
|
| 577 | - * @param bool $checked |
|
| 578 | - * @param array $options |
|
| 579 | - * @return string |
|
| 580 | - */ |
|
| 581 | - public function radio($name, $value = null, $checked = null, $options = array()) |
|
| 582 | - { |
|
| 583 | - if (is_null($value)) $value = $name; |
|
| 584 | - |
|
| 585 | - return $this->checkable('radio', $name, $value, $checked, $options); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Create a checkable input field. |
|
| 590 | - * |
|
| 591 | - * @param string $type |
|
| 592 | - * @param string $name |
|
| 593 | - * @param mixed $value |
|
| 594 | - * @param bool $checked |
|
| 595 | - * @param array $options |
|
| 596 | - * @return string |
|
| 597 | - */ |
|
| 598 | - protected function checkable($type, $name, $value, $checked, $options) |
|
| 599 | - { |
|
| 600 | - $checked = $this->getCheckedState($type, $name, $value, $checked); |
|
| 601 | - |
|
| 602 | - if ($checked) $options['checked'] = 'checked'; |
|
| 603 | - |
|
| 604 | - return $this->input($type, $name, $value, $options); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Get the check state for a checkable input. |
|
| 609 | - * |
|
| 610 | - * @param string $type |
|
| 611 | - * @param string $name |
|
| 612 | - * @param mixed $value |
|
| 613 | - * @param bool $checked |
|
| 614 | - * @return bool |
|
| 615 | - */ |
|
| 616 | - protected function getCheckedState($type, $name, $value, $checked) |
|
| 617 | - { |
|
| 618 | - switch ($type) |
|
| 619 | - { |
|
| 620 | - case 'checkbox': |
|
| 621 | - return $this->getCheckboxCheckedState($name, $value, $checked); |
|
| 622 | - |
|
| 623 | - case 'radio': |
|
| 624 | - return $this->getRadioCheckedState($name, $value, $checked); |
|
| 625 | - |
|
| 626 | - default: |
|
| 627 | - return $this->getValueAttribute($name) == $value; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * Get the check state for a checkbox input. |
|
| 633 | - * |
|
| 634 | - * @param string $name |
|
| 635 | - * @param mixed $value |
|
| 636 | - * @param bool $checked |
|
| 637 | - * @return bool |
|
| 638 | - */ |
|
| 639 | - protected function getCheckboxCheckedState($name, $value, $checked) |
|
| 640 | - { |
|
| 641 | - if (isset($this->session) && ! $this->oldInputIsEmpty() && is_null($this->old($name))) return false; |
|
| 642 | - |
|
| 643 | - if ($this->missingOldAndModel($name)) return $checked; |
|
| 644 | - |
|
| 645 | - $posted = $this->getValueAttribute($name); |
|
| 646 | - |
|
| 647 | - return is_array($posted) ? in_array($value, $posted) : (bool) $posted; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * Get the check state for a radio input. |
|
| 652 | - * |
|
| 653 | - * @param string $name |
|
| 654 | - * @param mixed $value |
|
| 655 | - * @param bool $checked |
|
| 656 | - * @return bool |
|
| 657 | - */ |
|
| 658 | - protected function getRadioCheckedState($name, $value, $checked) |
|
| 659 | - { |
|
| 660 | - if ($this->missingOldAndModel($name)) return $checked; |
|
| 661 | - |
|
| 662 | - return $this->getValueAttribute($name) == $value; |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * Determine if old input or model input exists for a key. |
|
| 667 | - * |
|
| 668 | - * @param string $name |
|
| 669 | - * @return bool |
|
| 670 | - */ |
|
| 671 | - protected function missingOldAndModel($name) |
|
| 672 | - { |
|
| 673 | - return (is_null($this->old($name)) && is_null($this->getModelValueAttribute($name))); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * Create a HTML reset input element. |
|
| 678 | - * |
|
| 679 | - * @param string $value |
|
| 680 | - * @param array $attributes |
|
| 681 | - * @return string |
|
| 682 | - */ |
|
| 683 | - public function reset($value, $attributes = array()) |
|
| 684 | - { |
|
| 685 | - return $this->input('reset', null, $value, $attributes); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Create a HTML image input element. |
|
| 690 | - * |
|
| 691 | - * @param string $url |
|
| 692 | - * @param string $name |
|
| 693 | - * @param array $attributes |
|
| 694 | - * @return string |
|
| 695 | - */ |
|
| 696 | - public function image($url, $name = null, $attributes = array()) |
|
| 697 | - { |
|
| 698 | - $attributes['src'] = $this->url->asset($url); |
|
| 699 | - |
|
| 700 | - return $this->input('image', $name, null, $attributes); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Create a submit button element. |
|
| 705 | - * |
|
| 706 | - * @param string $value |
|
| 707 | - * @param array $options |
|
| 708 | - * @return string |
|
| 709 | - */ |
|
| 710 | - public function submit($value = null, $options = array()) |
|
| 711 | - { |
|
| 712 | - return $this->input('submit', null, $value, $options); |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * Create a button element. |
|
| 717 | - * |
|
| 718 | - * @param string $value |
|
| 719 | - * @param array $options |
|
| 720 | - * @return string |
|
| 721 | - */ |
|
| 722 | - public function button($value = null, $options = array()) |
|
| 723 | - { |
|
| 724 | - if ( ! array_key_exists('type', $options)) |
|
| 725 | - { |
|
| 726 | - $options['type'] = 'button'; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - return '<button'.$this->html->attributes($options).'>'.$value.'</button>'; |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * Parse the form action method. |
|
| 734 | - * |
|
| 735 | - * @param string $method |
|
| 736 | - * @return string |
|
| 737 | - */ |
|
| 738 | - protected function getMethod($method) |
|
| 739 | - { |
|
| 740 | - $method = strtoupper($method); |
|
| 741 | - |
|
| 742 | - return $method != 'GET' ? 'POST' : $method; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - /** |
|
| 746 | - * Get the form action from the options. |
|
| 747 | - * |
|
| 748 | - * @param array $options |
|
| 749 | - * @return string |
|
| 750 | - */ |
|
| 751 | - protected function getAction(array $options) |
|
| 752 | - { |
|
| 753 | - // We will also check for a "route" or "action" parameter on the array so that |
|
| 754 | - // developers can easily specify a route or controller action when creating |
|
| 755 | - // a form providing a convenient interface for creating the form actions. |
|
| 756 | - if (isset($options['url'])) |
|
| 757 | - { |
|
| 758 | - return $this->getUrlAction($options['url']); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - if (isset($options['route'])) |
|
| 762 | - { |
|
| 763 | - return $this->getRouteAction($options['route']); |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - // If an action is available, we are attempting to open a form to a controller |
|
| 767 | - // action route. So, we will use the URL generator to get the path to these |
|
| 768 | - // actions and return them from the method. Otherwise, we'll use current. |
|
| 769 | - elseif (isset($options['action'])) |
|
| 770 | - { |
|
| 771 | - return $this->getControllerAction($options['action']); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - return $this->url->current(); |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * Get the action for a "url" option. |
|
| 779 | - * |
|
| 780 | - * @param array|string $options |
|
| 781 | - * @return string |
|
| 782 | - */ |
|
| 783 | - protected function getUrlAction($options) |
|
| 784 | - { |
|
| 785 | - if (is_array($options)) |
|
| 786 | - { |
|
| 787 | - return $this->url->to($options[0], array_slice($options, 1)); |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - return $this->url->to($options); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * Get the action for a "route" option. |
|
| 795 | - * |
|
| 796 | - * @param array|string $options |
|
| 797 | - * @return string |
|
| 798 | - */ |
|
| 799 | - protected function getRouteAction($options) |
|
| 800 | - { |
|
| 801 | - if (is_array($options)) |
|
| 802 | - { |
|
| 803 | - return $this->url->route($options[0], array_slice($options, 1)); |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - return $this->url->route($options); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * Get the action for an "action" option. |
|
| 811 | - * |
|
| 812 | - * @param array|string $options |
|
| 813 | - * @return string |
|
| 814 | - */ |
|
| 815 | - protected function getControllerAction($options) |
|
| 816 | - { |
|
| 817 | - if (is_array($options)) |
|
| 818 | - { |
|
| 819 | - return $this->url->action($options[0], array_slice($options, 1)); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - return $this->url->action($options); |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * Get the form appendage for the given method. |
|
| 827 | - * |
|
| 828 | - * @param string $method |
|
| 829 | - * @return string |
|
| 830 | - */ |
|
| 831 | - protected function getAppendage($method) |
|
| 832 | - { |
|
| 833 | - list($method, $appendage) = array(strtoupper($method), ''); |
|
| 834 | - |
|
| 835 | - // If the HTTP method is in this list of spoofed methods, we will attach the |
|
| 836 | - // method spoofer hidden input to the form. This allows us to use regular |
|
| 837 | - // form to initiate PUT and DELETE requests in addition to the typical. |
|
| 838 | - if (in_array($method, $this->spoofedMethods)) |
|
| 839 | - { |
|
| 840 | - $appendage .= $this->hidden('_method', $method); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - // If the method is something other than GET we will go ahead and attach the |
|
| 844 | - // CSRF token to the form, as this can't hurt and is convenient to simply |
|
| 845 | - // always have available on every form the developers creates for them. |
|
| 846 | - if ($method != 'GET') |
|
| 847 | - { |
|
| 848 | - $appendage .= $this->token(); |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - return $appendage; |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * Get the ID attribute for a field name. |
|
| 856 | - * |
|
| 857 | - * @param string $name |
|
| 858 | - * @param array $attributes |
|
| 859 | - * @return string |
|
| 860 | - */ |
|
| 861 | - public function getIdAttribute($name, $attributes) |
|
| 862 | - { |
|
| 863 | - if (array_key_exists('id', $attributes)) |
|
| 864 | - { |
|
| 865 | - return $attributes['id']; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - if (in_array($name, $this->labels)) |
|
| 869 | - { |
|
| 870 | - return $name; |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * Get the value that should be assigned to the field. |
|
| 876 | - * |
|
| 877 | - * @param string $name |
|
| 878 | - * @param string $value |
|
| 879 | - * @return string |
|
| 880 | - */ |
|
| 881 | - public function getValueAttribute($name, $value = null) |
|
| 882 | - { |
|
| 883 | - if (is_null($name)) return $value; |
|
| 884 | - |
|
| 885 | - if ( ! is_null($this->old($name))) |
|
| 886 | - { |
|
| 887 | - return $this->old($name); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - if ( ! is_null($value)) return $value; |
|
| 891 | - |
|
| 892 | - if (isset($this->model)) |
|
| 893 | - { |
|
| 894 | - return $this->getModelValueAttribute($name); |
|
| 895 | - } |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * Get the model value that should be assigned to the field. |
|
| 900 | - * |
|
| 901 | - * @param string $name |
|
| 902 | - * @return string |
|
| 903 | - */ |
|
| 904 | - protected function getModelValueAttribute($name) |
|
| 905 | - { |
|
| 906 | - if (is_object($this->model)) |
|
| 907 | - { |
|
| 908 | - return object_get($this->model, $this->transformKey($name)); |
|
| 909 | - } |
|
| 910 | - elseif (is_array($this->model)) |
|
| 911 | - { |
|
| 912 | - return array_get($this->model, $this->transformKey($name)); |
|
| 913 | - } |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * Get a value from the session's old input. |
|
| 918 | - * |
|
| 919 | - * @param string $name |
|
| 920 | - * @return string |
|
| 921 | - */ |
|
| 922 | - public function old($name) |
|
| 923 | - { |
|
| 924 | - if (isset($this->session)) |
|
| 925 | - { |
|
| 926 | - return $this->session->getOldInput($this->transformKey($name)); |
|
| 927 | - } |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * Determine if the old input is empty. |
|
| 932 | - * |
|
| 933 | - * @return bool |
|
| 934 | - */ |
|
| 935 | - public function oldInputIsEmpty() |
|
| 936 | - { |
|
| 937 | - return (isset($this->session) && count($this->session->getOldInput()) == 0); |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - /** |
|
| 941 | - * Transform key from array to dot syntax. |
|
| 942 | - * |
|
| 943 | - * @param string $key |
|
| 944 | - * @return string |
|
| 945 | - */ |
|
| 946 | - protected function transformKey($key) |
|
| 947 | - { |
|
| 948 | - return str_replace(array('.', '[]', '[', ']'), array('_', '', '.', ''), $key); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - /** |
|
| 952 | - * Get the session store implementation. |
|
| 953 | - * |
|
| 954 | - * @return \Illuminate\Session\Store $session |
|
| 955 | - */ |
|
| 956 | - public function getSessionStore() |
|
| 957 | - { |
|
| 958 | - return $this->session; |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - /** |
|
| 962 | - * Set the session store implementation. |
|
| 963 | - * |
|
| 964 | - * @param \Illuminate\Session\Store $session |
|
| 965 | - * @return $this |
|
| 966 | - */ |
|
| 967 | - public function setSessionStore(Session $session) |
|
| 968 | - { |
|
| 969 | - $this->session = $session; |
|
| 970 | - |
|
| 971 | - return $this; |
|
| 972 | - } |
|
| 9 | + use Macroable; |
|
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * The HTML builder instance. |
|
| 13 | + * |
|
| 14 | + * @var \Illuminate\Html\HtmlBuilder |
|
| 15 | + */ |
|
| 16 | + protected $html; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * The URL generator instance. |
|
| 20 | + * |
|
| 21 | + * @var \Illuminate\Routing\UrlGenerator $url |
|
| 22 | + */ |
|
| 23 | + protected $url; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * The CSRF token used by the form builder. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $csrfToken; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * The session store implementation. |
|
| 34 | + * |
|
| 35 | + * @var \Illuminate\Session\Store |
|
| 36 | + */ |
|
| 37 | + protected $session; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * The current model instance for the form. |
|
| 41 | + * |
|
| 42 | + * @var mixed |
|
| 43 | + */ |
|
| 44 | + protected $model; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * An array of label names we've created. |
|
| 48 | + * |
|
| 49 | + * @var array |
|
| 50 | + */ |
|
| 51 | + protected $labels = array(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * The reserved form open attributes. |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + protected $reserved = array('method', 'url', 'route', 'action', 'files'); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The form methods that should be spoofed, in uppercase. |
|
| 62 | + * |
|
| 63 | + * @var array |
|
| 64 | + */ |
|
| 65 | + protected $spoofedMethods = array('DELETE', 'PATCH', 'PUT'); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * The types of inputs to not fill values on by default. |
|
| 69 | + * |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + protected $skipValueTypes = array('file', 'password', 'checkbox', 'radio'); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Create a new form builder instance. |
|
| 76 | + * |
|
| 77 | + * @param \Illuminate\Routing\UrlGenerator $url |
|
| 78 | + * @param \Illuminate\Html\HtmlBuilder $html |
|
| 79 | + * @param string $csrfToken |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + public function __construct(HtmlBuilder $html, UrlGenerator $url, $csrfToken) |
|
| 83 | + { |
|
| 84 | + $this->url = $url; |
|
| 85 | + $this->html = $html; |
|
| 86 | + $this->csrfToken = $csrfToken; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Open up a new HTML form. |
|
| 91 | + * |
|
| 92 | + * @param array $options |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public function open(array $options = array()) |
|
| 96 | + { |
|
| 97 | + $method = array_get($options, 'method', 'post'); |
|
| 98 | + |
|
| 99 | + // We need to extract the proper method from the attributes. If the method is |
|
| 100 | + // something other than GET or POST we'll use POST since we will spoof the |
|
| 101 | + // actual method since forms don't support the reserved methods in HTML. |
|
| 102 | + $attributes['method'] = $this->getMethod($method); |
|
| 103 | + |
|
| 104 | + $attributes['action'] = $this->getAction($options); |
|
| 105 | + |
|
| 106 | + $attributes['accept-charset'] = 'UTF-8'; |
|
| 107 | + |
|
| 108 | + // If the method is PUT, PATCH or DELETE we will need to add a spoofer hidden |
|
| 109 | + // field that will instruct the Symfony request to pretend the method is a |
|
| 110 | + // different method than it actually is, for convenience from the forms. |
|
| 111 | + $append = $this->getAppendage($method); |
|
| 112 | + |
|
| 113 | + if (isset($options['files']) && $options['files']) |
|
| 114 | + { |
|
| 115 | + $options['enctype'] = 'multipart/form-data'; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // Finally we're ready to create the final form HTML field. We will attribute |
|
| 119 | + // format the array of attributes. We will also add on the appendage which |
|
| 120 | + // is used to spoof requests for this PUT, PATCH, etc. methods on forms. |
|
| 121 | + $attributes = array_merge( |
|
| 122 | + |
|
| 123 | + $attributes, array_except($options, $this->reserved) |
|
| 124 | + |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Finally, we will concatenate all of the attributes into a single string so |
|
| 128 | + // we can build out the final form open statement. We'll also append on an |
|
| 129 | + // extra value for the hidden _method field if it's needed for the form. |
|
| 130 | + $attributes = $this->html->attributes($attributes); |
|
| 131 | + |
|
| 132 | + return '<form'.$attributes.'>'.$append; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Create a new model based form builder. |
|
| 137 | + * |
|
| 138 | + * @param mixed $model |
|
| 139 | + * @param array $options |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function model($model, array $options = array()) |
|
| 143 | + { |
|
| 144 | + $this->model = $model; |
|
| 145 | + |
|
| 146 | + return $this->open($options); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Set the model instance on the form builder. |
|
| 151 | + * |
|
| 152 | + * @param mixed $model |
|
| 153 | + * @return void |
|
| 154 | + */ |
|
| 155 | + public function setModel($model) |
|
| 156 | + { |
|
| 157 | + $this->model = $model; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Close the current form. |
|
| 162 | + * |
|
| 163 | + * @return string |
|
| 164 | + */ |
|
| 165 | + public function close() |
|
| 166 | + { |
|
| 167 | + $this->labels = array(); |
|
| 168 | + |
|
| 169 | + $this->model = null; |
|
| 170 | + |
|
| 171 | + return '</form>'; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Generate a hidden field with the current CSRF token. |
|
| 176 | + * |
|
| 177 | + * @return string |
|
| 178 | + */ |
|
| 179 | + public function token() |
|
| 180 | + { |
|
| 181 | + $token = ! empty($this->csrfToken) ? $this->csrfToken : $this->session->getToken(); |
|
| 182 | + |
|
| 183 | + return $this->hidden('_token', $token); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Create a form label element. |
|
| 188 | + * |
|
| 189 | + * @param string $name |
|
| 190 | + * @param string $value |
|
| 191 | + * @param array $options |
|
| 192 | + * @return string |
|
| 193 | + */ |
|
| 194 | + public function label($name, $value = null, $options = array()) |
|
| 195 | + { |
|
| 196 | + $this->labels[] = $name; |
|
| 197 | + |
|
| 198 | + $options = $this->html->attributes($options); |
|
| 199 | + |
|
| 200 | + $value = e($this->formatLabel($name, $value)); |
|
| 201 | + |
|
| 202 | + return '<label for="'.$name.'"'.$options.'>'.$value.'</label>'; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Format the label value. |
|
| 207 | + * |
|
| 208 | + * @param string $name |
|
| 209 | + * @param string|null $value |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | + protected function formatLabel($name, $value) |
|
| 213 | + { |
|
| 214 | + return $value ?: ucwords(str_replace('_', ' ', $name)); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Create a form input field. |
|
| 219 | + * |
|
| 220 | + * @param string $type |
|
| 221 | + * @param string $name |
|
| 222 | + * @param string $value |
|
| 223 | + * @param array $options |
|
| 224 | + * @return string |
|
| 225 | + */ |
|
| 226 | + public function input($type, $name, $value = null, $options = array()) |
|
| 227 | + { |
|
| 228 | + if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 229 | + |
|
| 230 | + // We will get the appropriate value for the given field. We will look for the |
|
| 231 | + // value in the session for the value in the old input data then we'll look |
|
| 232 | + // in the model instance if one is set. Otherwise we will just use empty. |
|
| 233 | + $id = $this->getIdAttribute($name, $options); |
|
| 234 | + |
|
| 235 | + if ( ! in_array($type, $this->skipValueTypes)) |
|
| 236 | + { |
|
| 237 | + $value = $this->getValueAttribute($name, $value); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // Once we have the type, value, and ID we can merge them into the rest of the |
|
| 241 | + // attributes array so we can convert them into their HTML attribute format |
|
| 242 | + // when creating the HTML element. Then, we will return the entire input. |
|
| 243 | + $merge = compact('type', 'value', 'id'); |
|
| 244 | + |
|
| 245 | + $options = array_merge($options, $merge); |
|
| 246 | + |
|
| 247 | + return '<input'.$this->html->attributes($options).'>'; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Create a text input field. |
|
| 252 | + * |
|
| 253 | + * @param string $name |
|
| 254 | + * @param string $value |
|
| 255 | + * @param array $options |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function text($name, $value = null, $options = array()) |
|
| 259 | + { |
|
| 260 | + return $this->input('text', $name, $value, $options); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Create a password input field. |
|
| 265 | + * |
|
| 266 | + * @param string $name |
|
| 267 | + * @param array $options |
|
| 268 | + * @return string |
|
| 269 | + */ |
|
| 270 | + public function password($name, $options = array()) |
|
| 271 | + { |
|
| 272 | + return $this->input('password', $name, '', $options); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Create a hidden input field. |
|
| 277 | + * |
|
| 278 | + * @param string $name |
|
| 279 | + * @param string $value |
|
| 280 | + * @param array $options |
|
| 281 | + * @return string |
|
| 282 | + */ |
|
| 283 | + public function hidden($name, $value = null, $options = array()) |
|
| 284 | + { |
|
| 285 | + return $this->input('hidden', $name, $value, $options); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Create an e-mail input field. |
|
| 290 | + * |
|
| 291 | + * @param string $name |
|
| 292 | + * @param string $value |
|
| 293 | + * @param array $options |
|
| 294 | + * @return string |
|
| 295 | + */ |
|
| 296 | + public function email($name, $value = null, $options = array()) |
|
| 297 | + { |
|
| 298 | + return $this->input('email', $name, $value, $options); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Create a url input field. |
|
| 303 | + * |
|
| 304 | + * @param string $name |
|
| 305 | + * @param string $value |
|
| 306 | + * @param array $options |
|
| 307 | + * @return string |
|
| 308 | + */ |
|
| 309 | + public function url($name, $value = null, $options = array()) |
|
| 310 | + { |
|
| 311 | + return $this->input('url', $name, $value, $options); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Create a file input field. |
|
| 316 | + * |
|
| 317 | + * @param string $name |
|
| 318 | + * @param array $options |
|
| 319 | + * @return string |
|
| 320 | + */ |
|
| 321 | + public function file($name, $options = array()) |
|
| 322 | + { |
|
| 323 | + return $this->input('file', $name, null, $options); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Create a textarea input field. |
|
| 328 | + * |
|
| 329 | + * @param string $name |
|
| 330 | + * @param string $value |
|
| 331 | + * @param array $options |
|
| 332 | + * @return string |
|
| 333 | + */ |
|
| 334 | + public function textarea($name, $value = null, $options = array()) |
|
| 335 | + { |
|
| 336 | + if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 337 | + |
|
| 338 | + // Next we will look for the rows and cols attributes, as each of these are put |
|
| 339 | + // on the textarea element definition. If they are not present, we will just |
|
| 340 | + // assume some sane default values for these attributes for the developer. |
|
| 341 | + $options = $this->setTextAreaSize($options); |
|
| 342 | + |
|
| 343 | + $options['id'] = $this->getIdAttribute($name, $options); |
|
| 344 | + |
|
| 345 | + $value = (string) $this->getValueAttribute($name, $value); |
|
| 346 | + |
|
| 347 | + unset($options['size']); |
|
| 348 | + |
|
| 349 | + // Next we will convert the attributes into a string form. Also we have removed |
|
| 350 | + // the size attribute, as it was merely a short-cut for the rows and cols on |
|
| 351 | + // the element. Then we'll create the final textarea elements HTML for us. |
|
| 352 | + $options = $this->html->attributes($options); |
|
| 353 | + |
|
| 354 | + return '<textarea'.$options.'>'.e($value).'</textarea>'; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Set the text area size on the attributes. |
|
| 359 | + * |
|
| 360 | + * @param array $options |
|
| 361 | + * @return array |
|
| 362 | + */ |
|
| 363 | + protected function setTextAreaSize($options) |
|
| 364 | + { |
|
| 365 | + if (isset($options['size'])) |
|
| 366 | + { |
|
| 367 | + return $this->setQuickTextAreaSize($options); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // If the "size" attribute was not specified, we will just look for the regular |
|
| 371 | + // columns and rows attributes, using sane defaults if these do not exist on |
|
| 372 | + // the attributes array. We'll then return this entire options array back. |
|
| 373 | + $cols = array_get($options, 'cols', 50); |
|
| 374 | + |
|
| 375 | + $rows = array_get($options, 'rows', 10); |
|
| 376 | + |
|
| 377 | + return array_merge($options, compact('cols', 'rows')); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Set the text area size using the quick "size" attribute. |
|
| 382 | + * |
|
| 383 | + * @param array $options |
|
| 384 | + * @return array |
|
| 385 | + */ |
|
| 386 | + protected function setQuickTextAreaSize($options) |
|
| 387 | + { |
|
| 388 | + $segments = explode('x', $options['size']); |
|
| 389 | + |
|
| 390 | + return array_merge($options, array('cols' => $segments[0], 'rows' => $segments[1])); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Create a select box field. |
|
| 395 | + * |
|
| 396 | + * @param string $name |
|
| 397 | + * @param array $list |
|
| 398 | + * @param string $selected |
|
| 399 | + * @param array $options |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function select($name, $list = array(), $selected = null, $options = array()) |
|
| 403 | + { |
|
| 404 | + // When building a select box the "value" attribute is really the selected one |
|
| 405 | + // so we will use that when checking the model or session for a value which |
|
| 406 | + // should provide a convenient method of re-populating the forms on post. |
|
| 407 | + $selected = $this->getValueAttribute($name, $selected); |
|
| 408 | + |
|
| 409 | + $options['id'] = $this->getIdAttribute($name, $options); |
|
| 410 | + |
|
| 411 | + if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 412 | + |
|
| 413 | + // We will simply loop through the options and build an HTML value for each of |
|
| 414 | + // them until we have an array of HTML declarations. Then we will join them |
|
| 415 | + // all together into one single HTML element that can be put on the form. |
|
| 416 | + $html = array(); |
|
| 417 | + |
|
| 418 | + foreach ($list as $value => $display) |
|
| 419 | + { |
|
| 420 | + $html[] = $this->getSelectOption($display, $value, $selected); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + // Once we have all of this HTML, we can join this into a single element after |
|
| 424 | + // formatting the attributes into an HTML "attributes" string, then we will |
|
| 425 | + // build out a final select statement, which will contain all the values. |
|
| 426 | + $options = $this->html->attributes($options); |
|
| 427 | + |
|
| 428 | + $list = implode('', $html); |
|
| 429 | + |
|
| 430 | + return "<select{$options}>{$list}</select>"; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Create a select range field. |
|
| 435 | + * |
|
| 436 | + * @param string $name |
|
| 437 | + * @param string $begin |
|
| 438 | + * @param string $end |
|
| 439 | + * @param string $selected |
|
| 440 | + * @param array $options |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + public function selectRange($name, $begin, $end, $selected = null, $options = array()) |
|
| 444 | + { |
|
| 445 | + $range = array_combine($range = range($begin, $end), $range); |
|
| 446 | + |
|
| 447 | + return $this->select($name, $range, $selected, $options); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Create a select year field. |
|
| 452 | + * |
|
| 453 | + * @param string $name |
|
| 454 | + * @param string $begin |
|
| 455 | + * @param string $end |
|
| 456 | + * @param string $selected |
|
| 457 | + * @param array $options |
|
| 458 | + * @return string |
|
| 459 | + */ |
|
| 460 | + public function selectYear() |
|
| 461 | + { |
|
| 462 | + return call_user_func_array(array($this, 'selectRange'), func_get_args()); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Create a select month field. |
|
| 467 | + * |
|
| 468 | + * @param string $name |
|
| 469 | + * @param string $selected |
|
| 470 | + * @param array $options |
|
| 471 | + * @param string $format |
|
| 472 | + * @return string |
|
| 473 | + */ |
|
| 474 | + public function selectMonth($name, $selected = null, $options = array(), $format = '%B') |
|
| 475 | + { |
|
| 476 | + $months = array(); |
|
| 477 | + |
|
| 478 | + foreach (range(1, 12) as $month) |
|
| 479 | + { |
|
| 480 | + $months[$month] = strftime($format, mktime(0, 0, 0, $month, 1)); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + return $this->select($name, $months, $selected, $options); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Get the select option for the given value. |
|
| 488 | + * |
|
| 489 | + * @param string $display |
|
| 490 | + * @param string $value |
|
| 491 | + * @param string $selected |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 494 | + public function getSelectOption($display, $value, $selected) |
|
| 495 | + { |
|
| 496 | + if (is_array($display)) |
|
| 497 | + { |
|
| 498 | + return $this->optionGroup($display, $value, $selected); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + return $this->option($display, $value, $selected); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Create an option group form element. |
|
| 506 | + * |
|
| 507 | + * @param array $list |
|
| 508 | + * @param string $label |
|
| 509 | + * @param string $selected |
|
| 510 | + * @return string |
|
| 511 | + */ |
|
| 512 | + protected function optionGroup($list, $label, $selected) |
|
| 513 | + { |
|
| 514 | + $html = array(); |
|
| 515 | + |
|
| 516 | + foreach ($list as $value => $display) |
|
| 517 | + { |
|
| 518 | + $html[] = $this->option($display, $value, $selected); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + return '<optgroup label="'.e($label).'">'.implode('', $html).'</optgroup>'; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Create a select element option. |
|
| 526 | + * |
|
| 527 | + * @param string $display |
|
| 528 | + * @param string $value |
|
| 529 | + * @param string $selected |
|
| 530 | + * @return string |
|
| 531 | + */ |
|
| 532 | + protected function option($display, $value, $selected) |
|
| 533 | + { |
|
| 534 | + $selected = $this->getSelectedValue($value, $selected); |
|
| 535 | + |
|
| 536 | + $options = array('value' => e($value), 'selected' => $selected); |
|
| 537 | + |
|
| 538 | + return '<option'.$this->html->attributes($options).'>'.e($display).'</option>'; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Determine if the value is selected. |
|
| 543 | + * |
|
| 544 | + * @param string $value |
|
| 545 | + * @param string $selected |
|
| 546 | + * @return string |
|
| 547 | + */ |
|
| 548 | + protected function getSelectedValue($value, $selected) |
|
| 549 | + { |
|
| 550 | + if (is_array($selected)) |
|
| 551 | + { |
|
| 552 | + return in_array($value, $selected) ? 'selected' : null; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + return ((string) $value == (string) $selected) ? 'selected' : null; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Create a checkbox input field. |
|
| 560 | + * |
|
| 561 | + * @param string $name |
|
| 562 | + * @param mixed $value |
|
| 563 | + * @param bool $checked |
|
| 564 | + * @param array $options |
|
| 565 | + * @return string |
|
| 566 | + */ |
|
| 567 | + public function checkbox($name, $value = 1, $checked = null, $options = array()) |
|
| 568 | + { |
|
| 569 | + return $this->checkable('checkbox', $name, $value, $checked, $options); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Create a radio button input field. |
|
| 574 | + * |
|
| 575 | + * @param string $name |
|
| 576 | + * @param mixed $value |
|
| 577 | + * @param bool $checked |
|
| 578 | + * @param array $options |
|
| 579 | + * @return string |
|
| 580 | + */ |
|
| 581 | + public function radio($name, $value = null, $checked = null, $options = array()) |
|
| 582 | + { |
|
| 583 | + if (is_null($value)) $value = $name; |
|
| 584 | + |
|
| 585 | + return $this->checkable('radio', $name, $value, $checked, $options); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Create a checkable input field. |
|
| 590 | + * |
|
| 591 | + * @param string $type |
|
| 592 | + * @param string $name |
|
| 593 | + * @param mixed $value |
|
| 594 | + * @param bool $checked |
|
| 595 | + * @param array $options |
|
| 596 | + * @return string |
|
| 597 | + */ |
|
| 598 | + protected function checkable($type, $name, $value, $checked, $options) |
|
| 599 | + { |
|
| 600 | + $checked = $this->getCheckedState($type, $name, $value, $checked); |
|
| 601 | + |
|
| 602 | + if ($checked) $options['checked'] = 'checked'; |
|
| 603 | + |
|
| 604 | + return $this->input($type, $name, $value, $options); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Get the check state for a checkable input. |
|
| 609 | + * |
|
| 610 | + * @param string $type |
|
| 611 | + * @param string $name |
|
| 612 | + * @param mixed $value |
|
| 613 | + * @param bool $checked |
|
| 614 | + * @return bool |
|
| 615 | + */ |
|
| 616 | + protected function getCheckedState($type, $name, $value, $checked) |
|
| 617 | + { |
|
| 618 | + switch ($type) |
|
| 619 | + { |
|
| 620 | + case 'checkbox': |
|
| 621 | + return $this->getCheckboxCheckedState($name, $value, $checked); |
|
| 622 | + |
|
| 623 | + case 'radio': |
|
| 624 | + return $this->getRadioCheckedState($name, $value, $checked); |
|
| 625 | + |
|
| 626 | + default: |
|
| 627 | + return $this->getValueAttribute($name) == $value; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * Get the check state for a checkbox input. |
|
| 633 | + * |
|
| 634 | + * @param string $name |
|
| 635 | + * @param mixed $value |
|
| 636 | + * @param bool $checked |
|
| 637 | + * @return bool |
|
| 638 | + */ |
|
| 639 | + protected function getCheckboxCheckedState($name, $value, $checked) |
|
| 640 | + { |
|
| 641 | + if (isset($this->session) && ! $this->oldInputIsEmpty() && is_null($this->old($name))) return false; |
|
| 642 | + |
|
| 643 | + if ($this->missingOldAndModel($name)) return $checked; |
|
| 644 | + |
|
| 645 | + $posted = $this->getValueAttribute($name); |
|
| 646 | + |
|
| 647 | + return is_array($posted) ? in_array($value, $posted) : (bool) $posted; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * Get the check state for a radio input. |
|
| 652 | + * |
|
| 653 | + * @param string $name |
|
| 654 | + * @param mixed $value |
|
| 655 | + * @param bool $checked |
|
| 656 | + * @return bool |
|
| 657 | + */ |
|
| 658 | + protected function getRadioCheckedState($name, $value, $checked) |
|
| 659 | + { |
|
| 660 | + if ($this->missingOldAndModel($name)) return $checked; |
|
| 661 | + |
|
| 662 | + return $this->getValueAttribute($name) == $value; |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * Determine if old input or model input exists for a key. |
|
| 667 | + * |
|
| 668 | + * @param string $name |
|
| 669 | + * @return bool |
|
| 670 | + */ |
|
| 671 | + protected function missingOldAndModel($name) |
|
| 672 | + { |
|
| 673 | + return (is_null($this->old($name)) && is_null($this->getModelValueAttribute($name))); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * Create a HTML reset input element. |
|
| 678 | + * |
|
| 679 | + * @param string $value |
|
| 680 | + * @param array $attributes |
|
| 681 | + * @return string |
|
| 682 | + */ |
|
| 683 | + public function reset($value, $attributes = array()) |
|
| 684 | + { |
|
| 685 | + return $this->input('reset', null, $value, $attributes); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Create a HTML image input element. |
|
| 690 | + * |
|
| 691 | + * @param string $url |
|
| 692 | + * @param string $name |
|
| 693 | + * @param array $attributes |
|
| 694 | + * @return string |
|
| 695 | + */ |
|
| 696 | + public function image($url, $name = null, $attributes = array()) |
|
| 697 | + { |
|
| 698 | + $attributes['src'] = $this->url->asset($url); |
|
| 699 | + |
|
| 700 | + return $this->input('image', $name, null, $attributes); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Create a submit button element. |
|
| 705 | + * |
|
| 706 | + * @param string $value |
|
| 707 | + * @param array $options |
|
| 708 | + * @return string |
|
| 709 | + */ |
|
| 710 | + public function submit($value = null, $options = array()) |
|
| 711 | + { |
|
| 712 | + return $this->input('submit', null, $value, $options); |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * Create a button element. |
|
| 717 | + * |
|
| 718 | + * @param string $value |
|
| 719 | + * @param array $options |
|
| 720 | + * @return string |
|
| 721 | + */ |
|
| 722 | + public function button($value = null, $options = array()) |
|
| 723 | + { |
|
| 724 | + if ( ! array_key_exists('type', $options)) |
|
| 725 | + { |
|
| 726 | + $options['type'] = 'button'; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + return '<button'.$this->html->attributes($options).'>'.$value.'</button>'; |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * Parse the form action method. |
|
| 734 | + * |
|
| 735 | + * @param string $method |
|
| 736 | + * @return string |
|
| 737 | + */ |
|
| 738 | + protected function getMethod($method) |
|
| 739 | + { |
|
| 740 | + $method = strtoupper($method); |
|
| 741 | + |
|
| 742 | + return $method != 'GET' ? 'POST' : $method; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + /** |
|
| 746 | + * Get the form action from the options. |
|
| 747 | + * |
|
| 748 | + * @param array $options |
|
| 749 | + * @return string |
|
| 750 | + */ |
|
| 751 | + protected function getAction(array $options) |
|
| 752 | + { |
|
| 753 | + // We will also check for a "route" or "action" parameter on the array so that |
|
| 754 | + // developers can easily specify a route or controller action when creating |
|
| 755 | + // a form providing a convenient interface for creating the form actions. |
|
| 756 | + if (isset($options['url'])) |
|
| 757 | + { |
|
| 758 | + return $this->getUrlAction($options['url']); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + if (isset($options['route'])) |
|
| 762 | + { |
|
| 763 | + return $this->getRouteAction($options['route']); |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + // If an action is available, we are attempting to open a form to a controller |
|
| 767 | + // action route. So, we will use the URL generator to get the path to these |
|
| 768 | + // actions and return them from the method. Otherwise, we'll use current. |
|
| 769 | + elseif (isset($options['action'])) |
|
| 770 | + { |
|
| 771 | + return $this->getControllerAction($options['action']); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + return $this->url->current(); |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * Get the action for a "url" option. |
|
| 779 | + * |
|
| 780 | + * @param array|string $options |
|
| 781 | + * @return string |
|
| 782 | + */ |
|
| 783 | + protected function getUrlAction($options) |
|
| 784 | + { |
|
| 785 | + if (is_array($options)) |
|
| 786 | + { |
|
| 787 | + return $this->url->to($options[0], array_slice($options, 1)); |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + return $this->url->to($options); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * Get the action for a "route" option. |
|
| 795 | + * |
|
| 796 | + * @param array|string $options |
|
| 797 | + * @return string |
|
| 798 | + */ |
|
| 799 | + protected function getRouteAction($options) |
|
| 800 | + { |
|
| 801 | + if (is_array($options)) |
|
| 802 | + { |
|
| 803 | + return $this->url->route($options[0], array_slice($options, 1)); |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + return $this->url->route($options); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * Get the action for an "action" option. |
|
| 811 | + * |
|
| 812 | + * @param array|string $options |
|
| 813 | + * @return string |
|
| 814 | + */ |
|
| 815 | + protected function getControllerAction($options) |
|
| 816 | + { |
|
| 817 | + if (is_array($options)) |
|
| 818 | + { |
|
| 819 | + return $this->url->action($options[0], array_slice($options, 1)); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + return $this->url->action($options); |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * Get the form appendage for the given method. |
|
| 827 | + * |
|
| 828 | + * @param string $method |
|
| 829 | + * @return string |
|
| 830 | + */ |
|
| 831 | + protected function getAppendage($method) |
|
| 832 | + { |
|
| 833 | + list($method, $appendage) = array(strtoupper($method), ''); |
|
| 834 | + |
|
| 835 | + // If the HTTP method is in this list of spoofed methods, we will attach the |
|
| 836 | + // method spoofer hidden input to the form. This allows us to use regular |
|
| 837 | + // form to initiate PUT and DELETE requests in addition to the typical. |
|
| 838 | + if (in_array($method, $this->spoofedMethods)) |
|
| 839 | + { |
|
| 840 | + $appendage .= $this->hidden('_method', $method); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + // If the method is something other than GET we will go ahead and attach the |
|
| 844 | + // CSRF token to the form, as this can't hurt and is convenient to simply |
|
| 845 | + // always have available on every form the developers creates for them. |
|
| 846 | + if ($method != 'GET') |
|
| 847 | + { |
|
| 848 | + $appendage .= $this->token(); |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + return $appendage; |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * Get the ID attribute for a field name. |
|
| 856 | + * |
|
| 857 | + * @param string $name |
|
| 858 | + * @param array $attributes |
|
| 859 | + * @return string |
|
| 860 | + */ |
|
| 861 | + public function getIdAttribute($name, $attributes) |
|
| 862 | + { |
|
| 863 | + if (array_key_exists('id', $attributes)) |
|
| 864 | + { |
|
| 865 | + return $attributes['id']; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + if (in_array($name, $this->labels)) |
|
| 869 | + { |
|
| 870 | + return $name; |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * Get the value that should be assigned to the field. |
|
| 876 | + * |
|
| 877 | + * @param string $name |
|
| 878 | + * @param string $value |
|
| 879 | + * @return string |
|
| 880 | + */ |
|
| 881 | + public function getValueAttribute($name, $value = null) |
|
| 882 | + { |
|
| 883 | + if (is_null($name)) return $value; |
|
| 884 | + |
|
| 885 | + if ( ! is_null($this->old($name))) |
|
| 886 | + { |
|
| 887 | + return $this->old($name); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + if ( ! is_null($value)) return $value; |
|
| 891 | + |
|
| 892 | + if (isset($this->model)) |
|
| 893 | + { |
|
| 894 | + return $this->getModelValueAttribute($name); |
|
| 895 | + } |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * Get the model value that should be assigned to the field. |
|
| 900 | + * |
|
| 901 | + * @param string $name |
|
| 902 | + * @return string |
|
| 903 | + */ |
|
| 904 | + protected function getModelValueAttribute($name) |
|
| 905 | + { |
|
| 906 | + if (is_object($this->model)) |
|
| 907 | + { |
|
| 908 | + return object_get($this->model, $this->transformKey($name)); |
|
| 909 | + } |
|
| 910 | + elseif (is_array($this->model)) |
|
| 911 | + { |
|
| 912 | + return array_get($this->model, $this->transformKey($name)); |
|
| 913 | + } |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * Get a value from the session's old input. |
|
| 918 | + * |
|
| 919 | + * @param string $name |
|
| 920 | + * @return string |
|
| 921 | + */ |
|
| 922 | + public function old($name) |
|
| 923 | + { |
|
| 924 | + if (isset($this->session)) |
|
| 925 | + { |
|
| 926 | + return $this->session->getOldInput($this->transformKey($name)); |
|
| 927 | + } |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * Determine if the old input is empty. |
|
| 932 | + * |
|
| 933 | + * @return bool |
|
| 934 | + */ |
|
| 935 | + public function oldInputIsEmpty() |
|
| 936 | + { |
|
| 937 | + return (isset($this->session) && count($this->session->getOldInput()) == 0); |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + /** |
|
| 941 | + * Transform key from array to dot syntax. |
|
| 942 | + * |
|
| 943 | + * @param string $key |
|
| 944 | + * @return string |
|
| 945 | + */ |
|
| 946 | + protected function transformKey($key) |
|
| 947 | + { |
|
| 948 | + return str_replace(array('.', '[]', '[', ']'), array('_', '', '.', ''), $key); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + /** |
|
| 952 | + * Get the session store implementation. |
|
| 953 | + * |
|
| 954 | + * @return \Illuminate\Session\Store $session |
|
| 955 | + */ |
|
| 956 | + public function getSessionStore() |
|
| 957 | + { |
|
| 958 | + return $this->session; |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + /** |
|
| 962 | + * Set the session store implementation. |
|
| 963 | + * |
|
| 964 | + * @param \Illuminate\Session\Store $session |
|
| 965 | + * @return $this |
|
| 966 | + */ |
|
| 967 | + public function setSessionStore(Session $session) |
|
| 968 | + { |
|
| 969 | + $this->session = $session; |
|
| 970 | + |
|
| 971 | + return $this; |
|
| 972 | + } |
|
| 973 | 973 | |
| 974 | 974 | } |
@@ -225,7 +225,9 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public function input($type, $name, $value = null, $options = array()) |
| 227 | 227 | { |
| 228 | - if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 228 | + if ( ! isset($options['name'])) { |
|
| 229 | + $options['name'] = $name; |
|
| 230 | + } |
|
| 229 | 231 | |
| 230 | 232 | // We will get the appropriate value for the given field. We will look for the |
| 231 | 233 | // value in the session for the value in the old input data then we'll look |
@@ -333,7 +335,9 @@ discard block |
||
| 333 | 335 | */ |
| 334 | 336 | public function textarea($name, $value = null, $options = array()) |
| 335 | 337 | { |
| 336 | - if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 338 | + if ( ! isset($options['name'])) { |
|
| 339 | + $options['name'] = $name; |
|
| 340 | + } |
|
| 337 | 341 | |
| 338 | 342 | // Next we will look for the rows and cols attributes, as each of these are put |
| 339 | 343 | // on the textarea element definition. If they are not present, we will just |
@@ -408,7 +412,9 @@ discard block |
||
| 408 | 412 | |
| 409 | 413 | $options['id'] = $this->getIdAttribute($name, $options); |
| 410 | 414 | |
| 411 | - if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 415 | + if ( ! isset($options['name'])) { |
|
| 416 | + $options['name'] = $name; |
|
| 417 | + } |
|
| 412 | 418 | |
| 413 | 419 | // We will simply loop through the options and build an HTML value for each of |
| 414 | 420 | // them until we have an array of HTML declarations. Then we will join them |
@@ -580,7 +586,9 @@ discard block |
||
| 580 | 586 | */ |
| 581 | 587 | public function radio($name, $value = null, $checked = null, $options = array()) |
| 582 | 588 | { |
| 583 | - if (is_null($value)) $value = $name; |
|
| 589 | + if (is_null($value)) { |
|
| 590 | + $value = $name; |
|
| 591 | + } |
|
| 584 | 592 | |
| 585 | 593 | return $this->checkable('radio', $name, $value, $checked, $options); |
| 586 | 594 | } |
@@ -599,7 +607,9 @@ discard block |
||
| 599 | 607 | { |
| 600 | 608 | $checked = $this->getCheckedState($type, $name, $value, $checked); |
| 601 | 609 | |
| 602 | - if ($checked) $options['checked'] = 'checked'; |
|
| 610 | + if ($checked) { |
|
| 611 | + $options['checked'] = 'checked'; |
|
| 612 | + } |
|
| 603 | 613 | |
| 604 | 614 | return $this->input($type, $name, $value, $options); |
| 605 | 615 | } |
@@ -638,9 +648,13 @@ discard block |
||
| 638 | 648 | */ |
| 639 | 649 | protected function getCheckboxCheckedState($name, $value, $checked) |
| 640 | 650 | { |
| 641 | - if (isset($this->session) && ! $this->oldInputIsEmpty() && is_null($this->old($name))) return false; |
|
| 651 | + if (isset($this->session) && ! $this->oldInputIsEmpty() && is_null($this->old($name))) { |
|
| 652 | + return false; |
|
| 653 | + } |
|
| 642 | 654 | |
| 643 | - if ($this->missingOldAndModel($name)) return $checked; |
|
| 655 | + if ($this->missingOldAndModel($name)) { |
|
| 656 | + return $checked; |
|
| 657 | + } |
|
| 644 | 658 | |
| 645 | 659 | $posted = $this->getValueAttribute($name); |
| 646 | 660 | |
@@ -657,7 +671,9 @@ discard block |
||
| 657 | 671 | */ |
| 658 | 672 | protected function getRadioCheckedState($name, $value, $checked) |
| 659 | 673 | { |
| 660 | - if ($this->missingOldAndModel($name)) return $checked; |
|
| 674 | + if ($this->missingOldAndModel($name)) { |
|
| 675 | + return $checked; |
|
| 676 | + } |
|
| 661 | 677 | |
| 662 | 678 | return $this->getValueAttribute($name) == $value; |
| 663 | 679 | } |
@@ -880,14 +896,18 @@ discard block |
||
| 880 | 896 | */ |
| 881 | 897 | public function getValueAttribute($name, $value = null) |
| 882 | 898 | { |
| 883 | - if (is_null($name)) return $value; |
|
| 899 | + if (is_null($name)) { |
|
| 900 | + return $value; |
|
| 901 | + } |
|
| 884 | 902 | |
| 885 | 903 | if ( ! is_null($this->old($name))) |
| 886 | 904 | { |
| 887 | 905 | return $this->old($name); |
| 888 | 906 | } |
| 889 | 907 | |
| 890 | - if ( ! is_null($value)) return $value; |
|
| 908 | + if ( ! is_null($value)) { |
|
| 909 | + return $value; |
|
| 910 | + } |
|
| 891 | 911 | |
| 892 | 912 | if (isset($this->model)) |
| 893 | 913 | { |
@@ -906,8 +926,7 @@ discard block |
||
| 906 | 926 | if (is_object($this->model)) |
| 907 | 927 | { |
| 908 | 928 | return object_get($this->model, $this->transformKey($name)); |
| 909 | - } |
|
| 910 | - elseif (is_array($this->model)) |
|
| 929 | + } elseif (is_array($this->model)) |
|
| 911 | 930 | { |
| 912 | 931 | return array_get($this->model, $this->transformKey($name)); |
| 913 | 932 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function token() |
| 180 | 180 | { |
| 181 | - $token = ! empty($this->csrfToken) ? $this->csrfToken : $this->session->getToken(); |
|
| 181 | + $token = !empty($this->csrfToken) ? $this->csrfToken : $this->session->getToken(); |
|
| 182 | 182 | |
| 183 | 183 | return $this->hidden('_token', $token); |
| 184 | 184 | } |
@@ -225,14 +225,14 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public function input($type, $name, $value = null, $options = array()) |
| 227 | 227 | { |
| 228 | - if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 228 | + if (!isset($options['name'])) $options['name'] = $name; |
|
| 229 | 229 | |
| 230 | 230 | // We will get the appropriate value for the given field. We will look for the |
| 231 | 231 | // value in the session for the value in the old input data then we'll look |
| 232 | 232 | // in the model instance if one is set. Otherwise we will just use empty. |
| 233 | 233 | $id = $this->getIdAttribute($name, $options); |
| 234 | 234 | |
| 235 | - if ( ! in_array($type, $this->skipValueTypes)) |
|
| 235 | + if (!in_array($type, $this->skipValueTypes)) |
|
| 236 | 236 | { |
| 237 | 237 | $value = $this->getValueAttribute($name, $value); |
| 238 | 238 | } |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | */ |
| 334 | 334 | public function textarea($name, $value = null, $options = array()) |
| 335 | 335 | { |
| 336 | - if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 336 | + if (!isset($options['name'])) $options['name'] = $name; |
|
| 337 | 337 | |
| 338 | 338 | // Next we will look for the rows and cols attributes, as each of these are put |
| 339 | 339 | // on the textarea element definition. If they are not present, we will just |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | |
| 409 | 409 | $options['id'] = $this->getIdAttribute($name, $options); |
| 410 | 410 | |
| 411 | - if ( ! isset($options['name'])) $options['name'] = $name; |
|
| 411 | + if (!isset($options['name'])) $options['name'] = $name; |
|
| 412 | 412 | |
| 413 | 413 | // We will simply loop through the options and build an HTML value for each of |
| 414 | 414 | // them until we have an array of HTML declarations. Then we will join them |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | */ |
| 639 | 639 | protected function getCheckboxCheckedState($name, $value, $checked) |
| 640 | 640 | { |
| 641 | - if (isset($this->session) && ! $this->oldInputIsEmpty() && is_null($this->old($name))) return false; |
|
| 641 | + if (isset($this->session) && !$this->oldInputIsEmpty() && is_null($this->old($name))) return false; |
|
| 642 | 642 | |
| 643 | 643 | if ($this->missingOldAndModel($name)) return $checked; |
| 644 | 644 | |
@@ -721,7 +721,7 @@ discard block |
||
| 721 | 721 | */ |
| 722 | 722 | public function button($value = null, $options = array()) |
| 723 | 723 | { |
| 724 | - if ( ! array_key_exists('type', $options)) |
|
| 724 | + if (!array_key_exists('type', $options)) |
|
| 725 | 725 | { |
| 726 | 726 | $options['type'] = 'button'; |
| 727 | 727 | } |
@@ -882,12 +882,12 @@ discard block |
||
| 882 | 882 | { |
| 883 | 883 | if (is_null($name)) return $value; |
| 884 | 884 | |
| 885 | - if ( ! is_null($this->old($name))) |
|
| 885 | + if (!is_null($this->old($name))) |
|
| 886 | 886 | { |
| 887 | 887 | return $this->old($name); |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | - if ( ! is_null($value)) return $value; |
|
| 890 | + if (!is_null($value)) return $value; |
|
| 891 | 891 | |
| 892 | 892 | if (isset($this->model)) |
| 893 | 893 | { |
@@ -7,6 +7,9 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | private $are256ColorsSupportedForce = true; |
| 9 | 9 | |
| 10 | + /** |
|
| 11 | + * @param boolean $isSupported |
|
| 12 | + */ |
|
| 10 | 13 | public function setIsSupported($isSupported) |
| 11 | 14 | { |
| 12 | 15 | $this->isSupportedForce = $isSupported; |
@@ -17,6 +20,9 @@ discard block |
||
| 17 | 20 | return $this->isSupportedForce; |
| 18 | 21 | } |
| 19 | 22 | |
| 23 | + /** |
|
| 24 | + * @param boolean $are256ColorsSupported |
|
| 25 | + */ |
|
| 20 | 26 | public function setAre256ColorsSupported($are256ColorsSupported) |
| 21 | 27 | { |
| 22 | 28 | $this->are256ColorsSupportedForce = $are256ColorsSupported; |
@@ -352,7 +352,7 @@ |
||
| 352 | 352 | * @param \Illuminate\Contracts\Auth\Authenticatable $user |
| 353 | 353 | * @param string $ability |
| 354 | 354 | * @param array $arguments |
| 355 | - * @return callable |
|
| 355 | + * @return \Closure |
|
| 356 | 356 | */ |
| 357 | 357 | protected function resolvePolicyCallback($user, $ability, array $arguments) |
| 358 | 358 | { |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | protected function buildAbilityCallback($callback) |
| 117 | 117 | { |
| 118 | - return function () use ($callback) { |
|
| 118 | + return function() use ($callback) { |
|
| 119 | 119 | list($class, $method) = explode('@', $callback); |
| 120 | 120 | |
| 121 | 121 | return call_user_func_array([$this->resolvePolicy($class), $method], func_get_args()); |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | public function denies($ability, $arguments = []) |
| 185 | 185 | { |
| 186 | - return ! $this->allows($ability, $arguments); |
|
| 186 | + return !$this->allows($ability, $arguments); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | protected function raw($ability, $arguments = []) |
| 235 | 235 | { |
| 236 | - if (! $user = $this->resolveUser()) { |
|
| 236 | + if (!$user = $this->resolveUser()) { |
|
| 237 | 237 | return false; |
| 238 | 238 | } |
| 239 | 239 | |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | $arguments = array_merge([$user, $ability], [$arguments]); |
| 283 | 283 | |
| 284 | 284 | foreach ($this->beforeCallbacks as $before) { |
| 285 | - if (! is_null($result = call_user_func_array($before, $arguments))) { |
|
| 285 | + if (!is_null($result = call_user_func_array($before, $arguments))) { |
|
| 286 | 286 | return $result; |
| 287 | 287 | } |
| 288 | 288 | } |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | } elseif (isset($this->abilities[$ability])) { |
| 322 | 322 | return $this->abilities[$ability]; |
| 323 | 323 | } else { |
| 324 | - return function () { |
|
| 324 | + return function() { |
|
| 325 | 325 | return false; |
| 326 | 326 | }; |
| 327 | 327 | } |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | protected function firstArgumentCorrespondsToPolicy(array $arguments) |
| 337 | 337 | { |
| 338 | - if (! isset($arguments[0])) { |
|
| 338 | + if (!isset($arguments[0])) { |
|
| 339 | 339 | return false; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | protected function resolvePolicyCallback($user, $ability, array $arguments) |
| 358 | 358 | { |
| 359 | - return function () use ($user, $ability, $arguments) { |
|
| 359 | + return function() use ($user, $ability, $arguments) { |
|
| 360 | 360 | $instance = $this->getPolicyFor($arguments[0]); |
| 361 | 361 | |
| 362 | 362 | if (method_exists($instance, 'before')) { |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | // If we received a non-null result from the before method, we will return it |
| 373 | 373 | // as the result of a check. This allows developers to override the checks |
| 374 | 374 | // in the policy and return a result for all rules defined in the class. |
| 375 | - if (! is_null($result)) { |
|
| 375 | + if (!is_null($result)) { |
|
| 376 | 376 | return $result; |
| 377 | 377 | } |
| 378 | 378 | } |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | $ability = Str::camel($ability); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - if (! is_callable([$instance, $ability])) { |
|
| 384 | + if (!is_callable([$instance, $ability])) { |
|
| 385 | 385 | return false; |
| 386 | 386 | } |
| 387 | 387 | |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | $class = get_class($class); |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | - if (! isset($this->policies[$class])) { |
|
| 408 | + if (!isset($this->policies[$class])) { |
|
| 409 | 409 | throw new InvalidArgumentException("Policy not defined for [{$class}]."); |
| 410 | 410 | } |
| 411 | 411 | |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | public function forUser($user) |
| 433 | 433 | { |
| 434 | - $callback = function () use ($user) { |
|
| 434 | + $callback = function() use ($user) { |
|
| 435 | 435 | return $user; |
| 436 | 436 | }; |
| 437 | 437 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * Retrieve a user by their unique identifier. |
| 51 | 51 | * |
| 52 | 52 | * @param mixed $identifier |
| 53 | - * @return \Illuminate\Contracts\Auth\Authenticatable|null |
|
| 53 | + * @return GenericUser|null |
|
| 54 | 54 | */ |
| 55 | 55 | public function retrieveById($identifier) |
| 56 | 56 | { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @param mixed $identifier |
| 66 | 66 | * @param string $token |
| 67 | - * @return \Illuminate\Contracts\Auth\Authenticatable|null |
|
| 67 | + * @return GenericUser|null |
|
| 68 | 68 | */ |
| 69 | 69 | public function retrieveByToken($identifier, $token) |
| 70 | 70 | { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * Retrieve a user by the given credentials. |
| 95 | 95 | * |
| 96 | 96 | * @param array $credentials |
| 97 | - * @return \Illuminate\Contracts\Auth\Authenticatable|null |
|
| 97 | + * @return GenericUser|null |
|
| 98 | 98 | */ |
| 99 | 99 | public function retrieveByCredentials(array $credentials) |
| 100 | 100 | { |
@@ -104,7 +104,7 @@ |
||
| 104 | 104 | $query = $this->conn->table($this->table); |
| 105 | 105 | |
| 106 | 106 | foreach ($credentials as $key => $value) { |
| 107 | - if (! Str::contains($key, 'password')) { |
|
| 107 | + if (!Str::contains($key, 'password')) { |
|
| 108 | 108 | $query->where($key, $value); |
| 109 | 109 | } |
| 110 | 110 | } |
@@ -224,7 +224,7 @@ |
||
| 224 | 224 | * Get the user for the given credentials. |
| 225 | 225 | * |
| 226 | 226 | * @param array $credentials |
| 227 | - * @return \Illuminate\Contracts\Auth\CanResetPassword |
|
| 227 | + * @return \Illuminate\Contracts\Auth\Authenticatable|null |
|
| 228 | 228 | * |
| 229 | 229 | * @throws \UnexpectedValueException |
| 230 | 230 | */ |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | // so that it may be displayed for an user to click for password reset. |
| 111 | 111 | $view = $this->emailView; |
| 112 | 112 | |
| 113 | - return $this->mailer->send($view, compact('token', 'user'), function ($m) use ($user, $token, $callback) { |
|
| 113 | + return $this->mailer->send($view, compact('token', 'user'), function($m) use ($user, $token, $callback) { |
|
| 114 | 114 | $m->to($user->getEmailForPasswordReset()); |
| 115 | 115 | |
| 116 | - if (! is_null($callback)) { |
|
| 116 | + if (!is_null($callback)) { |
|
| 117 | 117 | call_user_func($callback, $m, $user, $token); |
| 118 | 118 | } |
| 119 | 119 | }); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | // the user is properly redirected having an error message on the post. |
| 134 | 134 | $user = $this->validateReset($credentials); |
| 135 | 135 | |
| 136 | - if (! $user instanceof CanResetPasswordContract) { |
|
| 136 | + if (!$user instanceof CanResetPasswordContract) { |
|
| 137 | 137 | return $user; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -161,11 +161,11 @@ discard block |
||
| 161 | 161 | return PasswordBrokerContract::INVALID_USER; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if (! $this->validateNewPassword($credentials)) { |
|
| 164 | + if (!$this->validateNewPassword($credentials)) { |
|
| 165 | 165 | return PasswordBrokerContract::INVALID_PASSWORD; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if (! $this->tokens->exists($user, $credentials['token'])) { |
|
| 168 | + if (!$this->tokens->exists($user, $credentials['token'])) { |
|
| 169 | 169 | return PasswordBrokerContract::INVALID_TOKEN; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | $user = $this->users->retrieveByCredentials($credentials); |
| 236 | 236 | |
| 237 | - if ($user && ! $user instanceof CanResetPasswordContract) { |
|
| 237 | + if ($user && !$user instanceof CanResetPasswordContract) { |
|
| 238 | 238 | throw new UnexpectedValueException('User must implement CanResetPassword interface.'); |
| 239 | 239 | } |
| 240 | 240 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * Get a driver instance. |
| 50 | 50 | * |
| 51 | 51 | * @param string $driver |
| 52 | - * @return mixed |
|
| 52 | + * @return \Illuminate\Contracts\Broadcasting\Broadcaster |
|
| 53 | 53 | */ |
| 54 | 54 | public function connection($driver = null) |
| 55 | 55 | { |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * Get a driver instance. |
| 61 | 61 | * |
| 62 | 62 | * @param string $name |
| 63 | - * @return mixed |
|
| 63 | + * @return \Illuminate\Contracts\Broadcasting\Broadcaster |
|
| 64 | 64 | */ |
| 65 | 65 | public function driver($name = null) |
| 66 | 66 | { |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * |
| 28 | 28 | * @param \Illuminate\Cache\ApcWrapper $apc |
| 29 | 29 | * @param string $prefix |
| 30 | - * @return void |
|
| 30 | + * @return Store |
|
| 31 | 31 | */ |
| 32 | 32 | public function __construct(ApcWrapper $apc, $prefix = '') |
| 33 | 33 | { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * Increment the value of an item in the cache. |
| 68 | 68 | * |
| 69 | 69 | * @param string $key |
| 70 | - * @param mixed $value |
|
| 70 | + * @param integer $value |
|
| 71 | 71 | * @return int|bool |
| 72 | 72 | */ |
| 73 | 73 | public function increment($key, $value = 1) |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * Decrement the value of an item in the cache. |
| 80 | 80 | * |
| 81 | 81 | * @param string $key |
| 82 | - * @param mixed $value |
|
| 82 | + * @param integer $value |
|
| 83 | 83 | * @return int|bool |
| 84 | 84 | */ |
| 85 | 85 | public function decrement($key, $value = 1) |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * Create a new APC wrapper instance. |
| 16 | 16 | * |
| 17 | - * @return void |
|
| 17 | + * @return ApcWrapper |
|
| 18 | 18 | */ |
| 19 | 19 | public function __construct() |
| 20 | 20 | { |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * Increment the value of an item in the cache. |
| 50 | 50 | * |
| 51 | 51 | * @param string $key |
| 52 | - * @param mixed $value |
|
| 52 | + * @param integer $value |
|
| 53 | 53 | * @return int|bool |
| 54 | 54 | */ |
| 55 | 55 | public function increment($key, $value) |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * Decrement the value of an item in the cache. |
| 62 | 62 | * |
| 63 | 63 | * @param string $key |
| 64 | - * @param mixed $value |
|
| 64 | + * @param integer $value |
|
| 65 | 65 | * @return int|bool |
| 66 | 66 | */ |
| 67 | 67 | public function decrement($key, $value) |