Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99342cc225 | ||
|
|
e8b6bb0ff9 | ||
|
|
b788835612 | ||
|
|
d24e18156f | ||
|
|
3dd594748c | ||
|
|
f620ae4b9c | ||
|
|
2b67d708ce | ||
|
|
bdc56f0239 | ||
|
|
6b68b0856c | ||
|
|
466aabedbd | ||
|
|
ef11b7dd2f | ||
|
|
f8cd022c4f | ||
|
|
bca8b11d67 | ||
|
|
db665c9f0f | ||
|
|
f62269629b | ||
|
|
2516472b3f | ||
|
|
828da38dcd | ||
|
|
292a4787a4 | ||
|
|
b6b3693586 | ||
|
|
5ad8377968 | ||
|
|
cea1f619b3 | ||
|
|
acb21a9364 | ||
|
|
b5d6fdedb6 | ||
|
|
9ab4568241 | ||
|
|
575d891b64 | ||
|
|
a4acc4a0ad | ||
|
|
a28c3dc94c | ||
|
|
bfb0ed2487 | ||
|
|
ef5befed96 | ||
|
|
36922db2bc | ||
|
|
017d60144f | ||
|
|
8b7c357e78 | ||
|
|
7ea28eea5e | ||
|
|
3ff2b89ea4 | ||
|
|
7c02a4f0fd | ||
|
|
3617dac0c4 | ||
|
|
de73798e3e | ||
|
|
59f124084c | ||
|
|
0f4473f9a0 | ||
|
|
af7663294a | ||
|
|
fb7693cf4b | ||
|
|
9c4fea1f04 | ||
|
|
f6d0f1c5c4 | ||
|
|
ebe5123467 |
No files matched your search
+1
-1
@@ -3,7 +3,7 @@ language: php
|
|||||||
php:
|
php:
|
||||||
- 5.5
|
- 5.5
|
||||||
- 5.6
|
- 5.6
|
||||||
- hhvm
|
- 7.0
|
||||||
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
|
|||||||
+241
-111
@@ -1,12 +1,15 @@
|
|||||||
<?php namespace Collective\Html;
|
<?php
|
||||||
|
|
||||||
|
namespace Collective\Html;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Illuminate\Routing\UrlGenerator;
|
use Illuminate\Contracts\Routing\UrlGenerator;
|
||||||
use Illuminate\Session\Store as Session;
|
use Illuminate\Session\SessionInterface;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Traits\Macroable;
|
use Illuminate\Support\Traits\Macroable;
|
||||||
|
|
||||||
class FormBuilder {
|
class FormBuilder
|
||||||
|
{
|
||||||
use Macroable;
|
use Macroable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,7 +22,7 @@ class FormBuilder {
|
|||||||
/**
|
/**
|
||||||
* The URL generator instance.
|
* The URL generator instance.
|
||||||
*
|
*
|
||||||
* @var \Illuminate\Routing\UrlGenerator $url
|
* @var \Illuminate\Contracts\Routing\UrlGenerator
|
||||||
*/
|
*/
|
||||||
protected $url;
|
protected $url;
|
||||||
|
|
||||||
@@ -33,7 +36,7 @@ class FormBuilder {
|
|||||||
/**
|
/**
|
||||||
* The session store implementation.
|
* The session store implementation.
|
||||||
*
|
*
|
||||||
* @var \Illuminate\Session\Store
|
* @var \Illuminate\Session\SessionInterface
|
||||||
*/
|
*/
|
||||||
protected $session;
|
protected $session;
|
||||||
|
|
||||||
@@ -49,35 +52,36 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $labels = array();
|
protected $labels = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reserved form open attributes.
|
* The reserved form open attributes.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $reserved = array('method', 'url', 'route', 'action', 'files');
|
protected $reserved = ['method', 'url', 'route', 'action', 'files'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The form methods that should be spoofed, in uppercase.
|
* The form methods that should be spoofed, in uppercase.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $spoofedMethods = array('DELETE', 'PATCH', 'PUT');
|
protected $spoofedMethods = ['DELETE', 'PATCH', 'PUT'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The types of inputs to not fill values on by default.
|
* The types of inputs to not fill values on by default.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $skipValueTypes = array('file', 'password', 'checkbox', 'radio');
|
protected $skipValueTypes = ['file', 'password', 'checkbox', 'radio'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new form builder instance.
|
* Create a new form builder instance.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Routing\UrlGenerator $url
|
* @param \Illuminate\Contracts\Routing\UrlGenerator $url
|
||||||
* @param \Collective\Html\HtmlBuilder $html
|
* @param \Collective\Html\HtmlBuilder $html
|
||||||
* @param string $csrfToken
|
* @param string $csrfToken
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(HtmlBuilder $html, UrlGenerator $url, $csrfToken)
|
public function __construct(HtmlBuilder $html, UrlGenerator $url, $csrfToken)
|
||||||
@@ -91,9 +95,10 @@ class FormBuilder {
|
|||||||
* Open up a new HTML form.
|
* Open up a new HTML form.
|
||||||
*
|
*
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function open(array $options = array())
|
public function open(array $options = [])
|
||||||
{
|
{
|
||||||
$method = array_get($options, 'method', 'post');
|
$method = array_get($options, 'method', 'post');
|
||||||
|
|
||||||
@@ -111,8 +116,7 @@ class FormBuilder {
|
|||||||
// different method than it actually is, for convenience from the forms.
|
// different method than it actually is, for convenience from the forms.
|
||||||
$append = $this->getAppendage($method);
|
$append = $this->getAppendage($method);
|
||||||
|
|
||||||
if (isset($options['files']) && $options['files'])
|
if (isset($options['files']) && $options['files']) {
|
||||||
{
|
|
||||||
$options['enctype'] = 'multipart/form-data';
|
$options['enctype'] = 'multipart/form-data';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,9 +142,10 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @param mixed $model
|
* @param mixed $model
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function model($model, array $options = array())
|
public function model($model, array $options = [])
|
||||||
{
|
{
|
||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
|
|
||||||
@@ -151,6 +156,7 @@ class FormBuilder {
|
|||||||
* Set the model instance on the form builder.
|
* Set the model instance on the form builder.
|
||||||
*
|
*
|
||||||
* @param mixed $model
|
* @param mixed $model
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setModel($model)
|
public function setModel($model)
|
||||||
@@ -165,7 +171,7 @@ class FormBuilder {
|
|||||||
*/
|
*/
|
||||||
public function close()
|
public function close()
|
||||||
{
|
{
|
||||||
$this->labels = array();
|
$this->labels = [];
|
||||||
|
|
||||||
$this->model = null;
|
$this->model = null;
|
||||||
|
|
||||||
@@ -179,7 +185,7 @@ class FormBuilder {
|
|||||||
*/
|
*/
|
||||||
public function token()
|
public function token()
|
||||||
{
|
{
|
||||||
$token = ! empty($this->csrfToken) ? $this->csrfToken : $this->session->getToken();
|
$token = !empty($this->csrfToken) ? $this->csrfToken : $this->session->getToken();
|
||||||
|
|
||||||
return $this->hidden('_token', $token);
|
return $this->hidden('_token', $token);
|
||||||
}
|
}
|
||||||
@@ -190,9 +196,10 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function label($name, $value = null, $options = array())
|
public function label($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
$this->labels[] = $name;
|
$this->labels[] = $name;
|
||||||
|
|
||||||
@@ -208,6 +215,7 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string|null $value
|
* @param string|null $value
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function formatLabel($name, $value)
|
protected function formatLabel($name, $value)
|
||||||
@@ -222,19 +230,21 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function input($type, $name, $value = null, $options = array())
|
public function input($type, $name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
if ( ! isset($options['name'])) $options['name'] = $name;
|
if (!isset($options['name'])) {
|
||||||
|
$options['name'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
// We will get the appropriate value for the given field. We will look for the
|
// We will get the appropriate value for the given field. We will look for the
|
||||||
// value in the session for the value in the old input data then we'll look
|
// value in the session for the value in the old input data then we'll look
|
||||||
// in the model instance if one is set. Otherwise we will just use empty.
|
// in the model instance if one is set. Otherwise we will just use empty.
|
||||||
$id = $this->getIdAttribute($name, $options);
|
$id = $this->getIdAttribute($name, $options);
|
||||||
|
|
||||||
if ( ! in_array($type, $this->skipValueTypes))
|
if (!in_array($type, $this->skipValueTypes)) {
|
||||||
{
|
|
||||||
$value = $this->getValueAttribute($name, $value);
|
$value = $this->getValueAttribute($name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,9 +264,10 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function text($name, $value = null, $options = array())
|
public function text($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('text', $name, $value, $options);
|
return $this->input('text', $name, $value, $options);
|
||||||
}
|
}
|
||||||
@@ -266,9 +277,10 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function password($name, $options = array())
|
public function password($name, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('password', $name, '', $options);
|
return $this->input('password', $name, '', $options);
|
||||||
}
|
}
|
||||||
@@ -279,9 +291,10 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function hidden($name, $value = null, $options = array())
|
public function hidden($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('hidden', $name, $value, $options);
|
return $this->input('hidden', $name, $value, $options);
|
||||||
}
|
}
|
||||||
@@ -292,9 +305,10 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function email($name, $value = null, $options = array())
|
public function email($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('email', $name, $value, $options);
|
return $this->input('email', $name, $value, $options);
|
||||||
}
|
}
|
||||||
@@ -305,9 +319,10 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function tel($name, $value = null, $options = array())
|
public function tel($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('tel', $name, $value, $options);
|
return $this->input('tel', $name, $value, $options);
|
||||||
}
|
}
|
||||||
@@ -318,9 +333,10 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function number($name, $value = null, $options = array())
|
public function number($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('number', $name, $value, $options);
|
return $this->input('number', $name, $value, $options);
|
||||||
}
|
}
|
||||||
@@ -331,27 +347,64 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function date($name, $value = null, $options = array())
|
public function date($name, $value = null, $options = [])
|
||||||
{
|
|
||||||
if ($value instanceof DateTime)
|
|
||||||
{
|
{
|
||||||
|
if ($value instanceof DateTime) {
|
||||||
$value = $value->format('Y-m-d');
|
$value = $value->format('Y-m-d');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->input('date', $name, $value, $options);
|
return $this->input('date', $name, $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a datetime input field.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function datetime($name, $value = null, $options = [])
|
||||||
|
{
|
||||||
|
if ($value instanceof DateTime) {
|
||||||
|
$value = $value->format(DateTime::RFC3339);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->input('datetime', $name, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a datetime-local input field.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function datetimeLocal($name, $value = null, $options = [])
|
||||||
|
{
|
||||||
|
if ($value instanceof DateTime) {
|
||||||
|
$value = $value->format('Y-m-d\TH:i');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->input('datetime-local', $name, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a time input field.
|
* Create a time input field.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function time($name, $value = null, $options = array())
|
public function time($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('time', $name, $value, $options);
|
return $this->input('time', $name, $value, $options);
|
||||||
}
|
}
|
||||||
@@ -362,9 +415,10 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function url($name, $value = null, $options = array())
|
public function url($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('url', $name, $value, $options);
|
return $this->input('url', $name, $value, $options);
|
||||||
}
|
}
|
||||||
@@ -374,9 +428,10 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function file($name, $options = array())
|
public function file($name, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('file', $name, null, $options);
|
return $this->input('file', $name, null, $options);
|
||||||
}
|
}
|
||||||
@@ -387,11 +442,14 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function textarea($name, $value = null, $options = array())
|
public function textarea($name, $value = null, $options = [])
|
||||||
{
|
{
|
||||||
if ( ! isset($options['name'])) $options['name'] = $name;
|
if (!isset($options['name'])) {
|
||||||
|
$options['name'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
// Next we will look for the rows and cols attributes, as each of these are put
|
// Next we will look for the rows and cols attributes, as each of these are put
|
||||||
// on the textarea element definition. If they are not present, we will just
|
// on the textarea element definition. If they are not present, we will just
|
||||||
@@ -416,12 +474,12 @@ class FormBuilder {
|
|||||||
* Set the text area size on the attributes.
|
* Set the text area size on the attributes.
|
||||||
*
|
*
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function setTextAreaSize($options)
|
protected function setTextAreaSize($options)
|
||||||
{
|
{
|
||||||
if (isset($options['size']))
|
if (isset($options['size'])) {
|
||||||
{
|
|
||||||
return $this->setQuickTextAreaSize($options);
|
return $this->setQuickTextAreaSize($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,13 +497,14 @@ class FormBuilder {
|
|||||||
* Set the text area size using the quick "size" attribute.
|
* Set the text area size using the quick "size" attribute.
|
||||||
*
|
*
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function setQuickTextAreaSize($options)
|
protected function setQuickTextAreaSize($options)
|
||||||
{
|
{
|
||||||
$segments = explode('x', $options['size']);
|
$segments = explode('x', $options['size']);
|
||||||
|
|
||||||
return array_merge($options, array('cols' => $segments[0], 'rows' => $segments[1]));
|
return array_merge($options, ['cols' => $segments[0], 'rows' => $segments[1]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -455,9 +514,10 @@ class FormBuilder {
|
|||||||
* @param array $list
|
* @param array $list
|
||||||
* @param string $selected
|
* @param string $selected
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function select($name, $list = array(), $selected = null, $options = array())
|
public function select($name, $list = [], $selected = null, $options = [])
|
||||||
{
|
{
|
||||||
// When building a select box the "value" attribute is really the selected one
|
// When building a select box the "value" attribute is really the selected one
|
||||||
// so we will use that when checking the model or session for a value which
|
// so we will use that when checking the model or session for a value which
|
||||||
@@ -466,15 +526,21 @@ class FormBuilder {
|
|||||||
|
|
||||||
$options['id'] = $this->getIdAttribute($name, $options);
|
$options['id'] = $this->getIdAttribute($name, $options);
|
||||||
|
|
||||||
if ( ! isset($options['name'])) $options['name'] = $name;
|
if (!isset($options['name'])) {
|
||||||
|
$options['name'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
// We will simply loop through the options and build an HTML value for each of
|
// We will simply loop through the options and build an HTML value for each of
|
||||||
// them until we have an array of HTML declarations. Then we will join them
|
// them until we have an array of HTML declarations. Then we will join them
|
||||||
// all together into one single HTML element that can be put on the form.
|
// all together into one single HTML element that can be put on the form.
|
||||||
$html = array();
|
$html = [];
|
||||||
|
|
||||||
foreach ($list as $value => $display)
|
if (isset($options['placeholder'])) {
|
||||||
{
|
$html[] = $this->placeholderOption($options['placeholder'], $selected);
|
||||||
|
unset($options['placeholder']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($list as $value => $display) {
|
||||||
$html[] = $this->getSelectOption($display, $value, $selected);
|
$html[] = $this->getSelectOption($display, $value, $selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,9 +562,10 @@ class FormBuilder {
|
|||||||
* @param string $end
|
* @param string $end
|
||||||
* @param string $selected
|
* @param string $selected
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function selectRange($name, $begin, $end, $selected = null, $options = array())
|
public function selectRange($name, $begin, $end, $selected = null, $options = [])
|
||||||
{
|
{
|
||||||
$range = array_combine($range = range($begin, $end), $range);
|
$range = array_combine($range = range($begin, $end), $range);
|
||||||
|
|
||||||
@@ -513,11 +580,12 @@ class FormBuilder {
|
|||||||
* @param string $end
|
* @param string $end
|
||||||
* @param string $selected
|
* @param string $selected
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function selectYear()
|
public function selectYear()
|
||||||
{
|
{
|
||||||
return call_user_func_array(array($this, 'selectRange'), func_get_args());
|
return call_user_func_array([$this, 'selectRange'], func_get_args());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -527,14 +595,14 @@ class FormBuilder {
|
|||||||
* @param string $selected
|
* @param string $selected
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @param string $format
|
* @param string $format
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function selectMonth($name, $selected = null, $options = array(), $format = '%B')
|
public function selectMonth($name, $selected = null, $options = [], $format = '%B')
|
||||||
{
|
{
|
||||||
$months = array();
|
$months = [];
|
||||||
|
|
||||||
foreach (range(1, 12) as $month)
|
foreach (range(1, 12) as $month) {
|
||||||
{
|
|
||||||
$months[$month] = strftime($format, mktime(0, 0, 0, $month, 1));
|
$months[$month] = strftime($format, mktime(0, 0, 0, $month, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,12 +615,12 @@ class FormBuilder {
|
|||||||
* @param string $display
|
* @param string $display
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param string $selected
|
* @param string $selected
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getSelectOption($display, $value, $selected)
|
public function getSelectOption($display, $value, $selected)
|
||||||
{
|
{
|
||||||
if (is_array($display))
|
if (is_array($display)) {
|
||||||
{
|
|
||||||
return $this->optionGroup($display, $value, $selected);
|
return $this->optionGroup($display, $value, $selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,14 +633,14 @@ class FormBuilder {
|
|||||||
* @param array $list
|
* @param array $list
|
||||||
* @param string $label
|
* @param string $label
|
||||||
* @param string $selected
|
* @param string $selected
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function optionGroup($list, $label, $selected)
|
protected function optionGroup($list, $label, $selected)
|
||||||
{
|
{
|
||||||
$html = array();
|
$html = [];
|
||||||
|
|
||||||
foreach ($list as $value => $display)
|
foreach ($list as $value => $display) {
|
||||||
{
|
|
||||||
$html[] = $this->option($display, $value, $selected);
|
$html[] = $this->option($display, $value, $selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,13 +653,32 @@ class FormBuilder {
|
|||||||
* @param string $display
|
* @param string $display
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param string $selected
|
* @param string $selected
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function option($display, $value, $selected)
|
protected function option($display, $value, $selected)
|
||||||
{
|
{
|
||||||
$selected = $this->getSelectedValue($value, $selected);
|
$selected = $this->getSelectedValue($value, $selected);
|
||||||
|
|
||||||
$options = array('value' => e($value), 'selected' => $selected);
|
$options = ['value' => $value, 'selected' => $selected];
|
||||||
|
|
||||||
|
return '<option'.$this->html->attributes($options).'>'.e($display).'</option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a placeholder select element option.
|
||||||
|
*
|
||||||
|
* @param $display
|
||||||
|
* @param $selected
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function placeholderOption($display, $selected)
|
||||||
|
{
|
||||||
|
$selected = $this->getSelectedValue(null, $selected);
|
||||||
|
|
||||||
|
$options = compact('selected');
|
||||||
|
$options['value'] = '';
|
||||||
|
|
||||||
return '<option'.$this->html->attributes($options).'>'.e($display).'</option>';
|
return '<option'.$this->html->attributes($options).'>'.e($display).'</option>';
|
||||||
}
|
}
|
||||||
@@ -601,13 +688,15 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param string $selected
|
* @param string $selected
|
||||||
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
protected function getSelectedValue($value, $selected)
|
protected function getSelectedValue($value, $selected)
|
||||||
{
|
{
|
||||||
if (is_array($selected))
|
if (is_array($selected)) {
|
||||||
{
|
return in_array($value, $selected, true) || in_array((string) $value, $selected, true)
|
||||||
return in_array($value, $selected) ? 'selected' : null;
|
? 'selected'
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((string) $value == (string) $selected) ? 'selected' : null;
|
return ((string) $value == (string) $selected) ? 'selected' : null;
|
||||||
@@ -620,9 +709,10 @@ class FormBuilder {
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param bool $checked
|
* @param bool $checked
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function checkbox($name, $value = 1, $checked = null, $options = array())
|
public function checkbox($name, $value = 1, $checked = null, $options = [])
|
||||||
{
|
{
|
||||||
return $this->checkable('checkbox', $name, $value, $checked, $options);
|
return $this->checkable('checkbox', $name, $value, $checked, $options);
|
||||||
}
|
}
|
||||||
@@ -634,11 +724,14 @@ class FormBuilder {
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param bool $checked
|
* @param bool $checked
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function radio($name, $value = null, $checked = null, $options = array())
|
public function radio($name, $value = null, $checked = null, $options = [])
|
||||||
{
|
{
|
||||||
if (is_null($value)) $value = $name;
|
if (is_null($value)) {
|
||||||
|
$value = $name;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->checkable('radio', $name, $value, $checked, $options);
|
return $this->checkable('radio', $name, $value, $checked, $options);
|
||||||
}
|
}
|
||||||
@@ -651,13 +744,16 @@ class FormBuilder {
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param bool $checked
|
* @param bool $checked
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function checkable($type, $name, $value, $checked, $options)
|
protected function checkable($type, $name, $value, $checked, $options)
|
||||||
{
|
{
|
||||||
$checked = $this->getCheckedState($type, $name, $value, $checked);
|
$checked = $this->getCheckedState($type, $name, $value, $checked);
|
||||||
|
|
||||||
if ($checked) $options['checked'] = 'checked';
|
if ($checked) {
|
||||||
|
$options['checked'] = 'checked';
|
||||||
|
}
|
||||||
|
|
||||||
return $this->input($type, $name, $value, $options);
|
return $this->input($type, $name, $value, $options);
|
||||||
}
|
}
|
||||||
@@ -669,12 +765,12 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param bool $checked
|
* @param bool $checked
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function getCheckedState($type, $name, $value, $checked)
|
protected function getCheckedState($type, $name, $value, $checked)
|
||||||
{
|
{
|
||||||
switch ($type)
|
switch ($type) {
|
||||||
{
|
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
return $this->getCheckboxCheckedState($name, $value, $checked);
|
return $this->getCheckboxCheckedState($name, $value, $checked);
|
||||||
|
|
||||||
@@ -692,17 +788,28 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param bool $checked
|
* @param bool $checked
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function getCheckboxCheckedState($name, $value, $checked)
|
protected function getCheckboxCheckedState($name, $value, $checked)
|
||||||
{
|
{
|
||||||
if (isset($this->session) && ! $this->oldInputIsEmpty() && is_null($this->old($name))) return false;
|
if (isset($this->session) && !$this->oldInputIsEmpty() && is_null($this->old($name))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->missingOldAndModel($name)) return $checked;
|
if ($this->missingOldAndModel($name)) {
|
||||||
|
return $checked;
|
||||||
|
}
|
||||||
|
|
||||||
$posted = $this->getValueAttribute($name);
|
$posted = $this->getValueAttribute($name, $checked);
|
||||||
|
|
||||||
return is_array($posted) ? in_array($value, $posted) : (bool) $posted;
|
if (is_array($posted)) {
|
||||||
|
return in_array($value, $posted);
|
||||||
|
} elseif ($posted instanceof Collection) {
|
||||||
|
return $posted->contains('id', $value);
|
||||||
|
} else {
|
||||||
|
return (bool) $posted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -711,11 +818,14 @@ class FormBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param bool $checked
|
* @param bool $checked
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function getRadioCheckedState($name, $value, $checked)
|
protected function getRadioCheckedState($name, $value, $checked)
|
||||||
{
|
{
|
||||||
if ($this->missingOldAndModel($name)) return $checked;
|
if ($this->missingOldAndModel($name)) {
|
||||||
|
return $checked;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->getValueAttribute($name) == $value;
|
return $this->getValueAttribute($name) == $value;
|
||||||
}
|
}
|
||||||
@@ -724,6 +834,7 @@ class FormBuilder {
|
|||||||
* Determine if old input or model input exists for a key.
|
* Determine if old input or model input exists for a key.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function missingOldAndModel($name)
|
protected function missingOldAndModel($name)
|
||||||
@@ -736,9 +847,10 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function reset($value, $attributes = array())
|
public function reset($value, $attributes = [])
|
||||||
{
|
{
|
||||||
return $this->input('reset', null, $value, $attributes);
|
return $this->input('reset', null, $value, $attributes);
|
||||||
}
|
}
|
||||||
@@ -749,23 +861,39 @@ class FormBuilder {
|
|||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function image($url, $name = null, $attributes = array())
|
public function image($url, $name = null, $attributes = [])
|
||||||
{
|
{
|
||||||
$attributes['src'] = $this->url->asset($url);
|
$attributes['src'] = $this->url->asset($url);
|
||||||
|
|
||||||
return $this->input('image', $name, null, $attributes);
|
return $this->input('image', $name, null, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a color input field.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function color($name, $value = null, $options = [])
|
||||||
|
{
|
||||||
|
return $this->input('color', $name, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a submit button element.
|
* Create a submit button element.
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function submit($value = null, $options = array())
|
public function submit($value = null, $options = [])
|
||||||
{
|
{
|
||||||
return $this->input('submit', null, $value, $options);
|
return $this->input('submit', null, $value, $options);
|
||||||
}
|
}
|
||||||
@@ -775,12 +903,12 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function button($value = null, $options = array())
|
public function button($value = null, $options = [])
|
||||||
{
|
|
||||||
if ( ! array_key_exists('type', $options))
|
|
||||||
{
|
{
|
||||||
|
if (!array_key_exists('type', $options)) {
|
||||||
$options['type'] = 'button';
|
$options['type'] = 'button';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -791,6 +919,7 @@ class FormBuilder {
|
|||||||
* Parse the form action method.
|
* Parse the form action method.
|
||||||
*
|
*
|
||||||
* @param string $method
|
* @param string $method
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getMethod($method)
|
protected function getMethod($method)
|
||||||
@@ -804,6 +933,7 @@ class FormBuilder {
|
|||||||
* Get the form action from the options.
|
* Get the form action from the options.
|
||||||
*
|
*
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getAction(array $options)
|
protected function getAction(array $options)
|
||||||
@@ -811,21 +941,18 @@ class FormBuilder {
|
|||||||
// We will also check for a "route" or "action" parameter on the array so that
|
// We will also check for a "route" or "action" parameter on the array so that
|
||||||
// developers can easily specify a route or controller action when creating
|
// developers can easily specify a route or controller action when creating
|
||||||
// a form providing a convenient interface for creating the form actions.
|
// a form providing a convenient interface for creating the form actions.
|
||||||
if (isset($options['url']))
|
if (isset($options['url'])) {
|
||||||
{
|
|
||||||
return $this->getUrlAction($options['url']);
|
return $this->getUrlAction($options['url']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['route']))
|
if (isset($options['route'])) {
|
||||||
{
|
|
||||||
return $this->getRouteAction($options['route']);
|
return $this->getRouteAction($options['route']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an action is available, we are attempting to open a form to a controller
|
// If an action is available, we are attempting to open a form to a controller
|
||||||
// action route. So, we will use the URL generator to get the path to these
|
// action route. So, we will use the URL generator to get the path to these
|
||||||
// actions and return them from the method. Otherwise, we'll use current.
|
// actions and return them from the method. Otherwise, we'll use current.
|
||||||
elseif (isset($options['action']))
|
elseif (isset($options['action'])) {
|
||||||
{
|
|
||||||
return $this->getControllerAction($options['action']);
|
return $this->getControllerAction($options['action']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,12 +963,12 @@ class FormBuilder {
|
|||||||
* Get the action for a "url" option.
|
* Get the action for a "url" option.
|
||||||
*
|
*
|
||||||
* @param array|string $options
|
* @param array|string $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getUrlAction($options)
|
protected function getUrlAction($options)
|
||||||
{
|
{
|
||||||
if (is_array($options))
|
if (is_array($options)) {
|
||||||
{
|
|
||||||
return $this->url->to($options[0], array_slice($options, 1));
|
return $this->url->to($options[0], array_slice($options, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -852,12 +979,12 @@ class FormBuilder {
|
|||||||
* Get the action for a "route" option.
|
* Get the action for a "route" option.
|
||||||
*
|
*
|
||||||
* @param array|string $options
|
* @param array|string $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getRouteAction($options)
|
protected function getRouteAction($options)
|
||||||
{
|
{
|
||||||
if (is_array($options))
|
if (is_array($options)) {
|
||||||
{
|
|
||||||
return $this->url->route($options[0], array_slice($options, 1));
|
return $this->url->route($options[0], array_slice($options, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,12 +995,12 @@ class FormBuilder {
|
|||||||
* Get the action for an "action" option.
|
* Get the action for an "action" option.
|
||||||
*
|
*
|
||||||
* @param array|string $options
|
* @param array|string $options
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getControllerAction($options)
|
protected function getControllerAction($options)
|
||||||
{
|
{
|
||||||
if (is_array($options))
|
if (is_array($options)) {
|
||||||
{
|
|
||||||
return $this->url->action($options[0], array_slice($options, 1));
|
return $this->url->action($options[0], array_slice($options, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -884,25 +1011,24 @@ class FormBuilder {
|
|||||||
* Get the form appendage for the given method.
|
* Get the form appendage for the given method.
|
||||||
*
|
*
|
||||||
* @param string $method
|
* @param string $method
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getAppendage($method)
|
protected function getAppendage($method)
|
||||||
{
|
{
|
||||||
list($method, $appendage) = array(strtoupper($method), '');
|
list($method, $appendage) = [strtoupper($method), ''];
|
||||||
|
|
||||||
// If the HTTP method is in this list of spoofed methods, we will attach the
|
// If the HTTP method is in this list of spoofed methods, we will attach the
|
||||||
// method spoofer hidden input to the form. This allows us to use regular
|
// method spoofer hidden input to the form. This allows us to use regular
|
||||||
// form to initiate PUT and DELETE requests in addition to the typical.
|
// form to initiate PUT and DELETE requests in addition to the typical.
|
||||||
if (in_array($method, $this->spoofedMethods))
|
if (in_array($method, $this->spoofedMethods)) {
|
||||||
{
|
|
||||||
$appendage .= $this->hidden('_method', $method);
|
$appendage .= $this->hidden('_method', $method);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the method is something other than GET we will go ahead and attach the
|
// If the method is something other than GET we will go ahead and attach the
|
||||||
// CSRF token to the form, as this can't hurt and is convenient to simply
|
// CSRF token to the form, as this can't hurt and is convenient to simply
|
||||||
// always have available on every form the developers creates for them.
|
// always have available on every form the developers creates for them.
|
||||||
if ($method != 'GET')
|
if ($method != 'GET') {
|
||||||
{
|
|
||||||
$appendage .= $this->token();
|
$appendage .= $this->token();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -914,17 +1040,16 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getIdAttribute($name, $attributes)
|
public function getIdAttribute($name, $attributes)
|
||||||
{
|
{
|
||||||
if (array_key_exists('id', $attributes))
|
if (array_key_exists('id', $attributes)) {
|
||||||
{
|
|
||||||
return $attributes['id'];
|
return $attributes['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($name, $this->labels))
|
if (in_array($name, $this->labels)) {
|
||||||
{
|
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -934,21 +1059,24 @@ class FormBuilder {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getValueAttribute($name, $value = null)
|
public function getValueAttribute($name, $value = null)
|
||||||
{
|
{
|
||||||
if (is_null($name)) return $value;
|
if (is_null($name)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! is_null($this->old($name)))
|
if (!is_null($this->old($name))) {
|
||||||
{
|
|
||||||
return $this->old($name);
|
return $this->old($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! is_null($value)) return $value;
|
if (!is_null($value)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($this->model))
|
if (isset($this->model)) {
|
||||||
{
|
|
||||||
return $this->getModelValueAttribute($name);
|
return $this->getModelValueAttribute($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -957,6 +1085,7 @@ class FormBuilder {
|
|||||||
* Get the model value that should be assigned to the field.
|
* Get the model value that should be assigned to the field.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function getModelValueAttribute($name)
|
protected function getModelValueAttribute($name)
|
||||||
@@ -968,12 +1097,12 @@ class FormBuilder {
|
|||||||
* Get a value from the session's old input.
|
* Get a value from the session's old input.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function old($name)
|
public function old($name)
|
||||||
{
|
{
|
||||||
if (isset($this->session))
|
if (isset($this->session)) {
|
||||||
{
|
|
||||||
return $this->session->getOldInput($this->transformKey($name));
|
return $this->session->getOldInput($this->transformKey($name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -992,17 +1121,18 @@ class FormBuilder {
|
|||||||
* Transform key from array to dot syntax.
|
* Transform key from array to dot syntax.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function transformKey($key)
|
protected function transformKey($key)
|
||||||
{
|
{
|
||||||
return str_replace(array('.', '[]', '[', ']'), array('_', '', '.', ''), $key);
|
return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the session store implementation.
|
* Get the session store implementation.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Session\Store $session
|
* @return \Illuminate\Session\SessionInterface $session
|
||||||
*/
|
*/
|
||||||
public function getSessionStore()
|
public function getSessionStore()
|
||||||
{
|
{
|
||||||
@@ -1012,14 +1142,14 @@ class FormBuilder {
|
|||||||
/**
|
/**
|
||||||
* Set the session store implementation.
|
* Set the session store implementation.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Session\Store $session
|
* @param \Illuminate\Session\SessionInterface $session
|
||||||
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setSessionStore(Session $session)
|
public function setSessionStore(SessionInterface $session)
|
||||||
{
|
{
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+9
-5
@@ -1,17 +1,21 @@
|
|||||||
<?php namespace Collective\Html;
|
<?php
|
||||||
|
|
||||||
|
namespace Collective\Html;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \Collective\Html\FormBuilder
|
* @see \Collective\Html\FormBuilder
|
||||||
*/
|
*/
|
||||||
class FormFacade extends Facade {
|
class FormFacade extends Facade
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Get the registered name of the component.
|
* Get the registered name of the component.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected static function getFacadeAccessor() { return 'form'; }
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'form';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+88
-55
@@ -1,23 +1,26 @@
|
|||||||
<?php namespace Collective\Html;
|
<?php
|
||||||
|
|
||||||
use Illuminate\Routing\UrlGenerator;
|
namespace Collective\Html;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Routing\UrlGenerator;
|
||||||
use Illuminate\Support\Traits\Macroable;
|
use Illuminate\Support\Traits\Macroable;
|
||||||
|
|
||||||
class HtmlBuilder {
|
class HtmlBuilder
|
||||||
|
{
|
||||||
use Macroable;
|
use Macroable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL generator instance.
|
* The URL generator instance.
|
||||||
*
|
*
|
||||||
* @var \Illuminate\Routing\UrlGenerator
|
* @var \Illuminate\Contracts\Routing\UrlGenerator
|
||||||
*/
|
*/
|
||||||
protected $url;
|
protected $url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new HTML builder instance.
|
* Create a new HTML builder instance.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Routing\UrlGenerator $url
|
* @param \Illuminate\Contracts\Routing\UrlGenerator $url
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(UrlGenerator $url = null)
|
public function __construct(UrlGenerator $url = null)
|
||||||
@@ -29,6 +32,7 @@ class HtmlBuilder {
|
|||||||
* Convert an HTML string to entities.
|
* Convert an HTML string to entities.
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function entities($value)
|
public function entities($value)
|
||||||
@@ -40,6 +44,7 @@ class HtmlBuilder {
|
|||||||
* Convert entities to HTML characters.
|
* Convert entities to HTML characters.
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function decode($value)
|
public function decode($value)
|
||||||
@@ -53,9 +58,10 @@ class HtmlBuilder {
|
|||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @param bool $secure
|
* @param bool $secure
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function script($url, $attributes = array(), $secure = null)
|
public function script($url, $attributes = [], $secure = null)
|
||||||
{
|
{
|
||||||
$attributes['src'] = $this->url->asset($url, $secure);
|
$attributes['src'] = $this->url->asset($url, $secure);
|
||||||
|
|
||||||
@@ -68,11 +74,12 @@ class HtmlBuilder {
|
|||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @param bool $secure
|
* @param bool $secure
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function style($url, $attributes = array(), $secure = null)
|
public function style($url, $attributes = [], $secure = null)
|
||||||
{
|
{
|
||||||
$defaults = array('media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet');
|
$defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet'];
|
||||||
|
|
||||||
$attributes = $attributes + $defaults;
|
$attributes = $attributes + $defaults;
|
||||||
|
|
||||||
@@ -88,9 +95,10 @@ class HtmlBuilder {
|
|||||||
* @param string $alt
|
* @param string $alt
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @param bool $secure
|
* @param bool $secure
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function image($url, $alt = null, $attributes = array(), $secure = null)
|
public function image($url, $alt = null, $attributes = [], $secure = null)
|
||||||
{
|
{
|
||||||
$attributes['alt'] = $alt;
|
$attributes['alt'] = $alt;
|
||||||
|
|
||||||
@@ -103,11 +111,12 @@ class HtmlBuilder {
|
|||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @param bool $secure
|
* @param bool $secure
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function favicon($url, $attributes = array(), $secure = null)
|
public function favicon($url, $attributes = [], $secure = null)
|
||||||
{
|
{
|
||||||
$defaults = array('rel' => 'shortcut icon', 'type' => 'image/x-icon');
|
$defaults = ['rel' => 'shortcut icon', 'type' => 'image/x-icon'];
|
||||||
|
|
||||||
$attributes = $attributes + $defaults;
|
$attributes = $attributes + $defaults;
|
||||||
|
|
||||||
@@ -123,13 +132,16 @@ class HtmlBuilder {
|
|||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @param bool $secure
|
* @param bool $secure
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function link($url, $title = null, $attributes = array(), $secure = null)
|
public function link($url, $title = null, $attributes = [], $secure = null)
|
||||||
{
|
{
|
||||||
$url = $this->url->to($url, array(), $secure);
|
$url = $this->url->to($url, [], $secure);
|
||||||
|
|
||||||
if (is_null($title) || $title === false) $title = $url;
|
if (is_null($title) || $title === false) {
|
||||||
|
$title = $url;
|
||||||
|
}
|
||||||
|
|
||||||
return '<a href="'.$url.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
|
return '<a href="'.$url.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
|
||||||
}
|
}
|
||||||
@@ -140,9 +152,10 @@ class HtmlBuilder {
|
|||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function secureLink($url, $title = null, $attributes = array())
|
public function secureLink($url, $title = null, $attributes = [])
|
||||||
{
|
{
|
||||||
return $this->link($url, $title, $attributes, true);
|
return $this->link($url, $title, $attributes, true);
|
||||||
}
|
}
|
||||||
@@ -154,9 +167,10 @@ class HtmlBuilder {
|
|||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @param bool $secure
|
* @param bool $secure
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function linkAsset($url, $title = null, $attributes = array(), $secure = null)
|
public function linkAsset($url, $title = null, $attributes = [], $secure = null)
|
||||||
{
|
{
|
||||||
$url = $this->url->asset($url, $secure);
|
$url = $this->url->asset($url, $secure);
|
||||||
|
|
||||||
@@ -169,9 +183,10 @@ class HtmlBuilder {
|
|||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function linkSecureAsset($url, $title = null, $attributes = array())
|
public function linkSecureAsset($url, $title = null, $attributes = [])
|
||||||
{
|
{
|
||||||
return $this->linkAsset($url, $title, $attributes, true);
|
return $this->linkAsset($url, $title, $attributes, true);
|
||||||
}
|
}
|
||||||
@@ -183,9 +198,10 @@ class HtmlBuilder {
|
|||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function linkRoute($name, $title = null, $parameters = array(), $attributes = array())
|
public function linkRoute($name, $title = null, $parameters = [], $attributes = [])
|
||||||
{
|
{
|
||||||
return $this->link($this->url->route($name, $parameters), $title, $attributes);
|
return $this->link($this->url->route($name, $parameters), $title, $attributes);
|
||||||
}
|
}
|
||||||
@@ -197,9 +213,10 @@ class HtmlBuilder {
|
|||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function linkAction($action, $title = null, $parameters = array(), $attributes = array())
|
public function linkAction($action, $title = null, $parameters = [], $attributes = [])
|
||||||
{
|
{
|
||||||
return $this->link($this->url->action($action, $parameters), $title, $attributes);
|
return $this->link($this->url->action($action, $parameters), $title, $attributes);
|
||||||
}
|
}
|
||||||
@@ -210,15 +227,16 @@ class HtmlBuilder {
|
|||||||
* @param string $email
|
* @param string $email
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function mailto($email, $title = null, $attributes = array())
|
public function mailto($email, $title = null, $attributes = [])
|
||||||
{
|
{
|
||||||
$email = $this->email($email);
|
$email = $this->email($email);
|
||||||
|
|
||||||
$title = $title ?: $email;
|
$title = $title ?: $email;
|
||||||
|
|
||||||
$email = $this->obfuscate('mailto:') . $email;
|
$email = $this->obfuscate('mailto:').$email;
|
||||||
|
|
||||||
return '<a href="'.$email.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
|
return '<a href="'.$email.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
|
||||||
}
|
}
|
||||||
@@ -227,6 +245,7 @@ class HtmlBuilder {
|
|||||||
* Obfuscate an e-mail address to prevent spam-bots from sniffing it.
|
* Obfuscate an e-mail address to prevent spam-bots from sniffing it.
|
||||||
*
|
*
|
||||||
* @param string $email
|
* @param string $email
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function email($email)
|
public function email($email)
|
||||||
@@ -239,9 +258,10 @@ class HtmlBuilder {
|
|||||||
*
|
*
|
||||||
* @param array $list
|
* @param array $list
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function ol($list, $attributes = array())
|
public function ol($list, $attributes = [])
|
||||||
{
|
{
|
||||||
return $this->listing('ol', $list, $attributes);
|
return $this->listing('ol', $list, $attributes);
|
||||||
}
|
}
|
||||||
@@ -251,9 +271,10 @@ class HtmlBuilder {
|
|||||||
*
|
*
|
||||||
* @param array $list
|
* @param array $list
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function ul($list, $attributes = array())
|
public function ul($list, $attributes = [])
|
||||||
{
|
{
|
||||||
return $this->listing('ul', $list, $attributes);
|
return $this->listing('ul', $list, $attributes);
|
||||||
}
|
}
|
||||||
@@ -263,6 +284,7 @@ class HtmlBuilder {
|
|||||||
*
|
*
|
||||||
* @param array $list
|
* @param array $list
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function dl(array $list, array $attributes = [])
|
public function dl(array $list, array $attributes = [])
|
||||||
@@ -271,9 +293,14 @@ class HtmlBuilder {
|
|||||||
|
|
||||||
$html = "<dl{$attributes}>";
|
$html = "<dl{$attributes}>";
|
||||||
|
|
||||||
foreach ($list as $key => $value)
|
foreach ($list as $key => $value) {
|
||||||
{
|
$value = (array) $value;
|
||||||
$html .= "<dt>$key</dt><dd>$value</dd>";
|
|
||||||
|
$html .= "<dt>$key</dt>";
|
||||||
|
|
||||||
|
foreach ($value as $v_key => $v_value) {
|
||||||
|
$html .= "<dd>$v_value</dd>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= '</dl>';
|
$html .= '</dl>';
|
||||||
@@ -287,19 +314,21 @@ class HtmlBuilder {
|
|||||||
* @param string $type
|
* @param string $type
|
||||||
* @param array $list
|
* @param array $list
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function listing($type, $list, $attributes = array())
|
protected function listing($type, $list, $attributes = [])
|
||||||
{
|
{
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
if (count($list) == 0) return $html;
|
if (count($list) == 0) {
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
// Essentially we will just spin through the list and build the list of the HTML
|
// Essentially we will just spin through the list and build the list of the HTML
|
||||||
// elements from the array. We will also handled nested lists in case that is
|
// elements from the array. We will also handled nested lists in case that is
|
||||||
// present in the array. Then we will build out the final listing elements.
|
// present in the array. Then we will build out the final listing elements.
|
||||||
foreach ($list as $key => $value)
|
foreach ($list as $key => $value) {
|
||||||
{
|
|
||||||
$html .= $this->listingElement($key, $type, $value);
|
$html .= $this->listingElement($key, $type, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,17 +342,15 @@ class HtmlBuilder {
|
|||||||
*
|
*
|
||||||
* @param mixed $key
|
* @param mixed $key
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $value
|
* @param mixed $value
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function listingElement($key, $type, $value)
|
protected function listingElement($key, $type, $value)
|
||||||
{
|
{
|
||||||
if (is_array($value))
|
if (is_array($value)) {
|
||||||
{
|
|
||||||
return $this->nestedListing($key, $type, $value);
|
return $this->nestedListing($key, $type, $value);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return '<li>'.e($value).'</li>';
|
return '<li>'.e($value).'</li>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,17 +360,15 @@ class HtmlBuilder {
|
|||||||
*
|
*
|
||||||
* @param mixed $key
|
* @param mixed $key
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $value
|
* @param mixed $value
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function nestedListing($key, $type, $value)
|
protected function nestedListing($key, $type, $value)
|
||||||
{
|
{
|
||||||
if (is_int($key))
|
if (is_int($key)) {
|
||||||
{
|
|
||||||
return $this->listing($type, $value);
|
return $this->listing($type, $value);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return '<li>'.$key.$this->listing($type, $value).'</li>';
|
return '<li>'.$key.$this->listing($type, $value).'</li>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,17 +377,19 @@ class HtmlBuilder {
|
|||||||
* Build an HTML attribute string from an array.
|
* Build an HTML attribute string from an array.
|
||||||
*
|
*
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function attributes($attributes)
|
public function attributes($attributes)
|
||||||
{
|
{
|
||||||
$html = array();
|
$html = [];
|
||||||
|
|
||||||
foreach ((array) $attributes as $key => $value)
|
foreach ((array) $attributes as $key => $value) {
|
||||||
{
|
|
||||||
$element = $this->attributeElement($key, $value);
|
$element = $this->attributeElement($key, $value);
|
||||||
|
|
||||||
if ( ! is_null($element)) $html[] = $element;
|
if (!is_null($element)) {
|
||||||
|
$html[] = $element;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return count($html) > 0 ? ' '.implode(' ', $html) : '';
|
return count($html) > 0 ? ' '.implode(' ', $html) : '';
|
||||||
@@ -373,6 +400,7 @@ class HtmlBuilder {
|
|||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function attributeElement($key, $value)
|
protected function attributeElement($key, $value)
|
||||||
@@ -380,30 +408,35 @@ class HtmlBuilder {
|
|||||||
// For numeric keys we will assume that the key and the value are the same
|
// For numeric keys we will assume that the key and the value are the same
|
||||||
// as this will convert HTML attributes such as "required" to a correct
|
// as this will convert HTML attributes such as "required" to a correct
|
||||||
// form like required="required" instead of using incorrect numerics.
|
// form like required="required" instead of using incorrect numerics.
|
||||||
if (is_numeric($key)) $key = $value;
|
if (is_numeric($key)) {
|
||||||
|
$key = $value;
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! is_null($value)) return $key.'="'.e($value).'"';
|
if (!is_null($value)) {
|
||||||
|
return $key.'="'.e($value).'"';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obfuscate a string to prevent spam-bots from sniffing it.
|
* Obfuscate a string to prevent spam-bots from sniffing it.
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function obfuscate($value)
|
public function obfuscate($value)
|
||||||
{
|
{
|
||||||
$safe = '';
|
$safe = '';
|
||||||
|
|
||||||
foreach (str_split($value) as $letter)
|
foreach (str_split($value) as $letter) {
|
||||||
{
|
if (ord($letter) > 128) {
|
||||||
if (ord($letter) > 128) return $letter;
|
return $letter;
|
||||||
|
}
|
||||||
|
|
||||||
// To properly obfuscate the value, we will randomly convert each letter to
|
// To properly obfuscate the value, we will randomly convert each letter to
|
||||||
// its entity or hexadecimal representation, keeping a bot from sniffing
|
// its entity or hexadecimal representation, keeping a bot from sniffing
|
||||||
// the randomly obfuscated letters out of the string on the responses.
|
// the randomly obfuscated letters out of the string on the responses.
|
||||||
switch (rand(1, 3))
|
switch (rand(1, 3)) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
$safe .= '&#'.ord($letter).';'; break;
|
$safe .= '&#'.ord($letter).';'; break;
|
||||||
|
|
||||||
@@ -424,6 +457,7 @@ class HtmlBuilder {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $content
|
* @param string $content
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function meta($name, $content, array $attributes = [])
|
public function meta($name, $content, array $attributes = [])
|
||||||
@@ -434,5 +468,4 @@ class HtmlBuilder {
|
|||||||
|
|
||||||
return '<meta'.$this->attributes($attributes).'>'.PHP_EOL;
|
return '<meta'.$this->attributes($attributes).'>'.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+9
-5
@@ -1,17 +1,21 @@
|
|||||||
<?php namespace Collective\Html;
|
<?php
|
||||||
|
|
||||||
|
namespace Collective\Html;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \Collective\Html\HtmlBuilder
|
* @see \Collective\Html\HtmlBuilder
|
||||||
*/
|
*/
|
||||||
class HtmlFacade extends Facade {
|
class HtmlFacade extends Facade
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Get the registered name of the component.
|
* Get the registered name of the component.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected static function getFacadeAccessor() { return 'html'; }
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'html';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
<?php namespace Collective\Html;
|
<?php
|
||||||
|
|
||||||
|
namespace Collective\Html;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class HtmlServiceProvider extends ServiceProvider {
|
class HtmlServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Indicates if loading of the provider is deferred.
|
* Indicates if loading of the provider is deferred.
|
||||||
*
|
*
|
||||||
@@ -33,8 +35,7 @@ class HtmlServiceProvider extends ServiceProvider {
|
|||||||
*/
|
*/
|
||||||
protected function registerHtmlBuilder()
|
protected function registerHtmlBuilder()
|
||||||
{
|
{
|
||||||
$this->app->bindShared('html', function($app)
|
$this->app->singleton('html', function ($app) {
|
||||||
{
|
|
||||||
return new HtmlBuilder($app['url']);
|
return new HtmlBuilder($app['url']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -46,8 +47,7 @@ class HtmlServiceProvider extends ServiceProvider {
|
|||||||
*/
|
*/
|
||||||
protected function registerFormBuilder()
|
protected function registerFormBuilder()
|
||||||
{
|
{
|
||||||
$this->app->bindShared('form', function($app)
|
$this->app->singleton('form', function ($app) {
|
||||||
{
|
|
||||||
$form = new FormBuilder($app['html'], $app['url'], $app['session.store']->getToken());
|
$form = new FormBuilder($app['html'], $app['url'], $app['session.store']->getToken());
|
||||||
|
|
||||||
return $form->setSessionStore($app['session.store']);
|
return $form->setSessionStore($app['session.store']);
|
||||||
@@ -61,7 +61,6 @@ class HtmlServiceProvider extends ServiceProvider {
|
|||||||
*/
|
*/
|
||||||
public function provides()
|
public function provides()
|
||||||
{
|
{
|
||||||
return array('html', 'form', 'Collective\Html\HtmlBuilder', 'Collective\Html\FormBuilder');
|
return ['html', 'form', 'Collective\Html\HtmlBuilder', 'Collective\Html\FormBuilder'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+12
-12
@@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! function_exists('link_to'))
|
if (!function_exists('link_to')) {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Generate a HTML link.
|
* Generate a HTML link.
|
||||||
*
|
*
|
||||||
@@ -9,16 +8,16 @@ if ( ! function_exists('link_to'))
|
|||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @param bool $secure
|
* @param bool $secure
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function link_to($url, $title = null, $attributes = array(), $secure = null)
|
function link_to($url, $title = null, $attributes = [], $secure = null)
|
||||||
{
|
{
|
||||||
return app('html')->link($url, $title, $attributes, $secure);
|
return app('html')->link($url, $title, $attributes, $secure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! function_exists('link_to_asset'))
|
if (!function_exists('link_to_asset')) {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Generate a HTML link to an asset.
|
* Generate a HTML link to an asset.
|
||||||
*
|
*
|
||||||
@@ -26,16 +25,16 @@ if ( ! function_exists('link_to_asset'))
|
|||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @param bool $secure
|
* @param bool $secure
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function link_to_asset($url, $title = null, $attributes = array(), $secure = null)
|
function link_to_asset($url, $title = null, $attributes = [], $secure = null)
|
||||||
{
|
{
|
||||||
return app('html')->linkAsset($url, $title, $attributes, $secure);
|
return app('html')->linkAsset($url, $title, $attributes, $secure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! function_exists('link_to_route'))
|
if (!function_exists('link_to_route')) {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Generate a HTML link to a named route.
|
* Generate a HTML link to a named route.
|
||||||
*
|
*
|
||||||
@@ -43,16 +42,16 @@ if ( ! function_exists('link_to_route'))
|
|||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function link_to_route($name, $title = null, $parameters = array(), $attributes = array())
|
function link_to_route($name, $title = null, $parameters = [], $attributes = [])
|
||||||
{
|
{
|
||||||
return app('html')->linkRoute($name, $title, $parameters, $attributes);
|
return app('html')->linkRoute($name, $title, $parameters, $attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! function_exists('link_to_action'))
|
if (!function_exists('link_to_action')) {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Generate a HTML link to a controller action.
|
* Generate a HTML link to a controller action.
|
||||||
*
|
*
|
||||||
@@ -60,9 +59,10 @@ if ( ! function_exists('link_to_action'))
|
|||||||
* @param string $title
|
* @param string $title
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function link_to_action($action, $title = null, $parameters = array(), $attributes = array())
|
function link_to_action($action, $title = null, $parameters = [], $attributes = [])
|
||||||
{
|
{
|
||||||
return app('html')->linkAction($action, $title, $parameters, $attributes);
|
return app('html')->linkAction($action, $title, $parameters, $attributes);
|
||||||
}
|
}
|
||||||
|
|||||||
+93
-56
@@ -1,26 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Session\Store;
|
|
||||||
use Mockery as m;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Collective\Html\FormBuilder;
|
use Collective\Html\FormBuilder;
|
||||||
use Collective\Html\HtmlBuilder;
|
use Collective\Html\HtmlBuilder;
|
||||||
use Illuminate\Routing\UrlGenerator;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\RouteCollection;
|
use Illuminate\Routing\RouteCollection;
|
||||||
|
use Illuminate\Routing\UrlGenerator;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Mockery as m;
|
||||||
|
|
||||||
class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
class FormBuilderTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Setup the test environment.
|
* Setup the test environment.
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET'));
|
$this->urlGenerator = new UrlGenerator(new RouteCollection(), Request::create('/foo', 'GET'));
|
||||||
$this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
|
$this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
|
||||||
$this->formBuilder = new FormBuilder($this->htmlBuilder, $this->urlGenerator, 'abc');
|
$this->formBuilder = new FormBuilder($this->htmlBuilder, $this->urlGenerator, 'abc');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the test environment.
|
* Destroy the test environment.
|
||||||
*/
|
*/
|
||||||
@@ -29,7 +28,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
m::close();
|
m::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testOpeningForm()
|
public function testOpeningForm()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->open(['method' => 'GET']);
|
$form1 = $this->formBuilder->open(['method' => 'GET']);
|
||||||
@@ -38,7 +36,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$form4 = $this->formBuilder->open(['method' => 'GET', 'accept-charset' => 'UTF-16', 'files' => true]);
|
$form4 = $this->formBuilder->open(['method' => 'GET', 'accept-charset' => 'UTF-16', 'files' => true]);
|
||||||
$form5 = $this->formBuilder->open(['method' => 'PUT']);
|
$form5 = $this->formBuilder->open(['method' => 'PUT']);
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals('<form method="GET" action="http://localhost/foo" accept-charset="UTF-8">', $form1);
|
$this->assertEquals('<form method="GET" action="http://localhost/foo" accept-charset="UTF-8">', $form1);
|
||||||
$this->assertEquals('<form method="POST" action="http://localhost/foo" accept-charset="UTF-8" class="form" id="id-form"><input name="_token" type="hidden" value="abc">', $form2);
|
$this->assertEquals('<form method="POST" action="http://localhost/foo" accept-charset="UTF-8" class="form" id="id-form"><input name="_token" type="hidden" value="abc">', $form2);
|
||||||
$this->assertEquals('<form method="GET" action="http://localhost/foo" accept-charset="UTF-16">', $form3);
|
$this->assertEquals('<form method="GET" action="http://localhost/foo" accept-charset="UTF-16">', $form3);
|
||||||
@@ -46,13 +43,11 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<form method="POST" action="http://localhost/foo" accept-charset="UTF-8"><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="abc">', $form5);
|
$this->assertEquals('<form method="POST" action="http://localhost/foo" accept-charset="UTF-8"><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="abc">', $form5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testClosingForm()
|
public function testClosingForm()
|
||||||
{
|
{
|
||||||
$this->assertEquals('</form>', $this->formBuilder->close());
|
$this->assertEquals('</form>', $this->formBuilder->close());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormLabel()
|
public function testFormLabel()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->label('foo', 'Foobar');
|
$form1 = $this->formBuilder->label('foo', 'Foobar');
|
||||||
@@ -62,7 +57,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<label for="foo" class="control-label">Foobar</label>', $form2);
|
$this->assertEquals('<label for="foo" class="control-label">Foobar</label>', $form2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormInput()
|
public function testFormInput()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->input('text', 'foo');
|
$form1 = $this->formBuilder->input('text', 'foo');
|
||||||
@@ -74,7 +68,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" name="foobar" type="date">', $form3);
|
$this->assertEquals('<input class="span2" name="foobar" type="date">', $form3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testPasswordsNotFilled()
|
public function testPasswordsNotFilled()
|
||||||
{
|
{
|
||||||
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
@@ -86,7 +79,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input name="password" type="password" value="">', $form1);
|
$this->assertEquals('<input name="password" type="password" value="">', $form1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFilesNotFilled()
|
public function testFilesNotFilled()
|
||||||
{
|
{
|
||||||
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
@@ -98,7 +90,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input name="img" type="file">', $form);
|
$this->assertEquals('<input name="img" type="file">', $form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormText()
|
public function testFormText()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->input('text', 'foo');
|
$form1 = $this->formBuilder->input('text', 'foo');
|
||||||
@@ -112,7 +103,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="text">', $form4);
|
$this->assertEquals('<input class="span2" name="foo" type="text">', $form4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormTextRepopulation()
|
public function testFormTextRepopulation()
|
||||||
{
|
{
|
||||||
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
@@ -136,19 +126,17 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals($input1, $input2);
|
$this->assertEquals($input1, $input2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormRepopulationWithMixOfArraysAndObjects()
|
public function testFormRepopulationWithMixOfArraysAndObjects()
|
||||||
{
|
{
|
||||||
$this->formBuilder->model(['user' => (object)['password' => 'apple']]);
|
$this->formBuilder->model(['user' => (object) ['password' => 'apple']]);
|
||||||
$input = $this->formBuilder->text('user[password]');
|
$input = $this->formBuilder->text('user[password]');
|
||||||
$this->assertEquals('<input name="user[password]" type="text" value="apple">', $input);
|
$this->assertEquals('<input name="user[password]" type="text" value="apple">', $input);
|
||||||
|
|
||||||
$this->formBuilder->model((object)['letters' => ['a', 'b', 'c']]);
|
$this->formBuilder->model((object) ['letters' => ['a', 'b', 'c']]);
|
||||||
$input = $this->formBuilder->text('letters[1]');
|
$input = $this->formBuilder->text('letters[1]');
|
||||||
$this->assertEquals('<input name="letters[1]" type="text" value="b">', $input);
|
$this->assertEquals('<input name="letters[1]" type="text" value="b">', $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormPassword()
|
public function testFormPassword()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->password('foo');
|
$form1 = $this->formBuilder->password('foo');
|
||||||
@@ -158,7 +146,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="password" value="">', $form2);
|
$this->assertEquals('<input class="span2" name="foo" type="password" value="">', $form2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormHidden()
|
public function testFormHidden()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->hidden('foo');
|
$form1 = $this->formBuilder->hidden('foo');
|
||||||
@@ -170,7 +157,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="hidden">', $form3);
|
$this->assertEquals('<input class="span2" name="foo" type="hidden">', $form3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormEmail()
|
public function testFormEmail()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->email('foo');
|
$form1 = $this->formBuilder->email('foo');
|
||||||
@@ -182,7 +168,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="email">', $form3);
|
$this->assertEquals('<input class="span2" name="foo" type="email">', $form3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormTel()
|
public function testFormTel()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->tel('foo');
|
$form1 = $this->formBuilder->tel('foo');
|
||||||
@@ -194,7 +179,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="tel">', $form3);
|
$this->assertEquals('<input class="span2" name="foo" type="tel">', $form3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormNumber()
|
public function testFormNumber()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->number('foo');
|
$form1 = $this->formBuilder->number('foo');
|
||||||
@@ -215,7 +199,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
$this->assertEquals('<input name="foo" type="date">', $form1);
|
$this->assertEquals('<input name="foo" type="date">', $form1);
|
||||||
$this->assertEquals('<input name="foo" type="date" value="2015-02-20">', $form2);
|
$this->assertEquals('<input name="foo" type="date" value="2015-02-20">', $form2);
|
||||||
$this->assertEquals('<input name="foo" type="date" value="' . \Carbon\Carbon::now()->format('Y-m-d') . '">', $form3);
|
$this->assertEquals('<input name="foo" type="date" value="'.\Carbon\Carbon::now()->format('Y-m-d').'">', $form3);
|
||||||
$this->assertEquals('<input class="span2" name="foo" type="date">', $form4);
|
$this->assertEquals('<input class="span2" name="foo" type="date">', $form4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,11 +210,10 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$form3 = $this->formBuilder->time('foo', null, ['class' => 'span2']);
|
$form3 = $this->formBuilder->time('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
$this->assertEquals('<input name="foo" type="time">', $form1);
|
$this->assertEquals('<input name="foo" type="time">', $form1);
|
||||||
$this->assertEquals('<input name="foo" type="time" value="' . \Carbon\Carbon::now()->format('H:i') . '">', $form2);
|
$this->assertEquals('<input name="foo" type="time" value="'.\Carbon\Carbon::now()->format('H:i').'">', $form2);
|
||||||
$this->assertEquals('<input class="span2" name="foo" type="time">', $form3);
|
$this->assertEquals('<input class="span2" name="foo" type="time">', $form3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormFile()
|
public function testFormFile()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->file('foo');
|
$form1 = $this->formBuilder->file('foo');
|
||||||
@@ -240,7 +223,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="file">', $form2);
|
$this->assertEquals('<input class="span2" name="foo" type="file">', $form2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormTextarea()
|
public function testFormTextarea()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->textarea('foo');
|
$form1 = $this->formBuilder->textarea('foo');
|
||||||
@@ -254,7 +236,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<textarea name="foo" cols="60" rows="15"></textarea>', $form4);
|
$this->assertEquals('<textarea name="foo" cols="60" rows="15"></textarea>', $form4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testSelect()
|
public function testSelect()
|
||||||
{
|
{
|
||||||
$select = $this->formBuilder->select(
|
$select = $this->formBuilder->select(
|
||||||
@@ -263,8 +244,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
);
|
);
|
||||||
$this->assertEquals($select, '<select name="size"><option value="L">Large</option><option value="S">Small</option></select>');
|
$this->assertEquals($select, '<select name="size"><option value="L">Large</option><option value="S">Small</option></select>');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$select = $this->formBuilder->select(
|
$select = $this->formBuilder->select(
|
||||||
'size',
|
'size',
|
||||||
['L' => 'Large', 'S' => 'Small'],
|
['L' => 'Large', 'S' => 'Small'],
|
||||||
@@ -272,8 +251,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
);
|
);
|
||||||
$this->assertEquals($select, '<select name="size"><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
|
$this->assertEquals($select, '<select name="size"><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$select = $this->formBuilder->select(
|
$select = $this->formBuilder->select(
|
||||||
'size',
|
'size',
|
||||||
['L' => 'Large', 'S' => 'Small'],
|
['L' => 'Large', 'S' => 'Small'],
|
||||||
@@ -282,8 +259,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
);
|
);
|
||||||
$this->assertEquals($select, '<select class="class-name" id="select-id" name="size"><option value="L">Large</option><option value="S">Small</option></select>');
|
$this->assertEquals($select, '<select class="class-name" id="select-id" name="size"><option value="L">Large</option><option value="S">Small</option></select>');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->formBuilder->label('select-name-id');
|
$this->formBuilder->label('select-name-id');
|
||||||
$select = $this->formBuilder->select(
|
$select = $this->formBuilder->select(
|
||||||
'select-name-id',
|
'select-name-id',
|
||||||
@@ -292,8 +267,28 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
['name' => 'select-name']
|
['name' => 'select-name']
|
||||||
);
|
);
|
||||||
$this->assertEquals($select, '<select name="select-name" id="select-name-id"></select>');
|
$this->assertEquals($select, '<select name="select-name" id="select-name-id"></select>');
|
||||||
}
|
|
||||||
|
|
||||||
|
$select = $this->formBuilder->select(
|
||||||
|
'size',
|
||||||
|
[
|
||||||
|
'Large sizes' => [
|
||||||
|
'L' => 'Large',
|
||||||
|
'XL' => 'Extra Large',
|
||||||
|
],
|
||||||
|
'S' => 'Small',
|
||||||
|
],
|
||||||
|
null,
|
||||||
|
[
|
||||||
|
'class' => 'class-name',
|
||||||
|
'id' => 'select-id',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$select,
|
||||||
|
'<select class="class-name" id="select-id" name="size"><optgroup label="Large sizes"><option value="L">Large</option><option value="XL">Extra Large</option></optgroup><option value="S">Small</option></select>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormSelectRepopulation()
|
public function testFormSelectRepopulation()
|
||||||
{
|
{
|
||||||
@@ -314,6 +309,24 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals($select, '<select name="size[key]"><option value="L">Large</option><option value="M">Medium</option><option value="S" selected="selected">Small</option></select>');
|
$this->assertEquals($select, '<select name="size[key]"><option value="L">Large</option><option value="M">Medium</option><option value="S" selected="selected">Small</option></select>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormWithOptionalPlaceholder()
|
||||||
|
{
|
||||||
|
$select = $this->formBuilder->select(
|
||||||
|
'size',
|
||||||
|
['L' => 'Large', 'S' => 'Small'],
|
||||||
|
null,
|
||||||
|
['placeholder' => 'Select One...']
|
||||||
|
);
|
||||||
|
$this->assertEquals($select, '<select name="size"><option selected="selected" value="">Select One...</option><option value="L">Large</option><option value="S">Small</option></select>');
|
||||||
|
|
||||||
|
$select = $this->formBuilder->select(
|
||||||
|
'size',
|
||||||
|
['L' => 'Large', 'S' => 'Small'],
|
||||||
|
'L',
|
||||||
|
['placeholder' => 'Select One...']
|
||||||
|
);
|
||||||
|
$this->assertEquals($select, '<select name="size"><option value="">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormSelectYear()
|
public function testFormSelectYear()
|
||||||
{
|
{
|
||||||
@@ -326,7 +339,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertContains('<select name="year"><option value="2000" selected="selected">2000</option><option value="2001">2001</option>', $select3);
|
$this->assertContains('<select name="year"><option value="2000" selected="selected">2000</option><option value="2001">2001</option>', $select3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormSelectRange()
|
public function testFormSelectRange()
|
||||||
{
|
{
|
||||||
$range = $this->formBuilder->selectRange('dob', 1900, 2013);
|
$range = $this->formBuilder->selectRange('dob', 1900, 2013);
|
||||||
@@ -335,7 +347,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertContains('<option value="2013">2013</option>', $range);
|
$this->assertContains('<option value="2013">2013</option>', $range);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormSelectMonth()
|
public function testFormSelectMonth()
|
||||||
{
|
{
|
||||||
$month1 = $this->formBuilder->selectMonth('month');
|
$month1 = $this->formBuilder->selectMonth('month');
|
||||||
@@ -347,7 +358,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertContains('<select id="foo" name="month"><option value="1">January</option>', $month3);
|
$this->assertContains('<select id="foo" name="month"><option value="1">January</option>', $month3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormCheckbox()
|
public function testFormCheckbox()
|
||||||
{
|
{
|
||||||
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
@@ -366,7 +376,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="checkbox" value="foobar">', $form4);
|
$this->assertEquals('<input class="span2" name="foo" type="checkbox" value="foobar">', $form4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormCheckboxRepopulation()
|
public function testFormCheckboxRepopulation()
|
||||||
{
|
{
|
||||||
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
@@ -390,6 +399,28 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input checked="checked" name="multicheck[]" type="checkbox" value="3">', $check3);
|
$this->assertEquals('<input checked="checked" name="multicheck[]" type="checkbox" value="3">', $check3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormCheckboxWithModelRelation()
|
||||||
|
{
|
||||||
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
|
$session->shouldReceive('getOldInput')->withNoArgs()->andReturn([]);
|
||||||
|
$session->shouldReceive('getOldInput')->with('items')->andReturn(null);
|
||||||
|
|
||||||
|
$mockModel2 = new StdClass();
|
||||||
|
$mockModel2->id = 2;
|
||||||
|
$mockModel3 = new StdClass();
|
||||||
|
$mockModel3->id = 3;
|
||||||
|
$this->setModel(['items' => new Collection([$mockModel2, $mockModel3])]);
|
||||||
|
|
||||||
|
$check1 = $this->formBuilder->checkbox('items[]', 1);
|
||||||
|
$check2 = $this->formBuilder->checkbox('items[]', 2);
|
||||||
|
$check3 = $this->formBuilder->checkbox('items[]', 3, false);
|
||||||
|
$check4 = $this->formBuilder->checkbox('items[]', 4, true);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="items[]" type="checkbox" value="1">', $check1);
|
||||||
|
$this->assertEquals('<input checked="checked" name="items[]" type="checkbox" value="2">', $check2);
|
||||||
|
$this->assertEquals('<input name="items[]" type="checkbox" value="3">', $check3);
|
||||||
|
$this->assertEquals('<input checked="checked" name="items[]" type="checkbox" value="4">', $check4);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormCheckboxWithoutSession()
|
public function testFormCheckboxWithoutSession()
|
||||||
{
|
{
|
||||||
@@ -400,7 +431,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input checked="checked" name="foo" type="checkbox" value="foobar">', $form2);
|
$this->assertEquals('<input checked="checked" name="foo" type="checkbox" value="foobar">', $form2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormRadio()
|
public function testFormRadio()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->input('radio', 'foo');
|
$form1 = $this->formBuilder->input('radio', 'foo');
|
||||||
@@ -414,7 +444,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" name="foo" type="radio" value="foobar">', $form4);
|
$this->assertEquals('<input class="span2" name="foo" type="radio" value="foobar">', $form4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormRadioRepopulation()
|
public function testFormRadioRepopulation()
|
||||||
{
|
{
|
||||||
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
@@ -428,7 +457,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input name="radio" type="radio" value="2">', $radio2);
|
$this->assertEquals('<input name="radio" type="radio" value="2">', $radio2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormSubmit()
|
public function testFormSubmit()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->submit('foo');
|
$form1 = $this->formBuilder->submit('foo');
|
||||||
@@ -438,7 +466,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<input class="span2" type="submit" value="foo">', $form2);
|
$this->assertEquals('<input class="span2" type="submit" value="foo">', $form2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormButton()
|
public function testFormButton()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->button('foo');
|
$form1 = $this->formBuilder->button('foo');
|
||||||
@@ -448,51 +475,61 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('<button class="span2" type="button">foo</button>', $form2);
|
$this->assertEquals('<button class="span2" type="button">foo</button>', $form2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testResetInput()
|
public function testResetInput()
|
||||||
{
|
{
|
||||||
$resetInput = $this->formBuilder->reset('foo');
|
$resetInput = $this->formBuilder->reset('foo');
|
||||||
$this->assertEquals('<input type="reset" value="foo">', $resetInput);
|
$this->assertEquals('<input type="reset" value="foo">', $resetInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testImageInput()
|
public function testImageInput()
|
||||||
{
|
{
|
||||||
$url = 'http://laravel.com/';
|
$url = 'http://laravel.com/';
|
||||||
$image = $this->formBuilder->image($url);
|
$image = $this->formBuilder->image($url);
|
||||||
|
|
||||||
$this->assertEquals('<input src="'. $url .'" type="image">', $image);
|
$this->assertEquals('<input src="'.$url.'" type="image">', $image);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormColor()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->color('foo');
|
||||||
|
$form2 = $this->formBuilder->color('foo', '#ff0000');
|
||||||
|
$form3 = $this->formBuilder->color('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="color">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="color" value="#ff0000">', $form2);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="color">', $form3);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setModel(array $data, $object = true)
|
protected function setModel(array $data, $object = true)
|
||||||
{
|
{
|
||||||
if ($object) $data = new FormBuilderModelStub($data);
|
if ($object) {
|
||||||
|
$data = new FormBuilderModelStub($data);
|
||||||
|
}
|
||||||
|
|
||||||
$this->formBuilder->model($data, ['method' => 'GET']);
|
$this->formBuilder->model($data, ['method' => 'GET']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FormBuilderModelStub {
|
class FormBuilderModelStub
|
||||||
|
{
|
||||||
protected $data;
|
protected $data;
|
||||||
|
|
||||||
public function __construct(array $data = [])
|
public function __construct(array $data = [])
|
||||||
{
|
{
|
||||||
foreach ($data as $key => $val)
|
foreach ($data as $key => $val) {
|
||||||
{
|
if (is_array($val)) {
|
||||||
if (is_array($val)) $val = new self($val);
|
$val = new self($val);
|
||||||
|
}
|
||||||
|
|
||||||
$this->data[$key] = $val;
|
$this->data[$key] = $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function __get($key)
|
public function __get($key)
|
||||||
{
|
{
|
||||||
return $this->data[$key];
|
return $this->data[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function __isset($key)
|
public function __isset($key)
|
||||||
{
|
{
|
||||||
return isset($this->data[$key]);
|
return isset($this->data[$key]);
|
||||||
|
|||||||
@@ -1,37 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Session\Store;
|
|
||||||
use Mockery as m;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Collective\Html\FormBuilder;
|
|
||||||
use Collective\Html\HtmlBuilder;
|
use Collective\Html\HtmlBuilder;
|
||||||
use Illuminate\Routing\UrlGenerator;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\RouteCollection;
|
use Illuminate\Routing\RouteCollection;
|
||||||
|
use Illuminate\Routing\UrlGenerator;
|
||||||
|
|
||||||
class HtmlBuilderTest extends PHPUnit_Framework_TestCase {
|
class HtmlBuilderTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Setup the test environment.
|
* Setup the test environment.
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET'));
|
$this->urlGenerator = new UrlGenerator(new RouteCollection(), Request::create('/foo', 'GET'));
|
||||||
$this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
|
$this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy the test environment.
|
|
||||||
*/
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
m::close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDl()
|
public function testDl()
|
||||||
{
|
{
|
||||||
$list = [
|
$list = [
|
||||||
'foo' => 'bar',
|
'foo' => 'bar',
|
||||||
'bing' => 'baz'
|
'bing' => 'baz',
|
||||||
];
|
];
|
||||||
|
|
||||||
$attributes = ['class' => 'example'];
|
$attributes = ['class' => 'example'];
|
||||||
@@ -61,7 +50,6 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$target = $this->urlGenerator->to('bar.ico');
|
$target = $this->urlGenerator->to('bar.ico');
|
||||||
$result = $this->htmlBuilder->favicon('http://foo.com/bar.ico');
|
$result = $this->htmlBuilder->favicon('http://foo.com/bar.ico');
|
||||||
|
|
||||||
$this->assertEquals('<link rel="shortcut icon" type="image/x-icon" href="'.$target.'">' . PHP_EOL, $result);
|
$this->assertEquals('<link rel="shortcut icon" type="image/x-icon" href="'.$target.'">'.PHP_EOL, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user