diff --git a/src/FormBuilder.php b/src/FormBuilder.php
index f400924..69f4808 100755
--- a/src/FormBuilder.php
+++ b/src/FormBuilder.php
@@ -1,14 +1,16 @@
-url = $url;
- $this->html = $html;
- $this->csrfToken = $csrfToken;
+ $this->url = $url;
+ $this->html = $html;
+ $this->csrfToken = $csrfToken;
}
/**
@@ -98,26 +100,25 @@ class FormBuilder {
*/
public function open(array $options = [])
{
- $method = array_get($options, 'method', 'post');
+ $method = array_get($options, 'method', 'post');
// We need to extract the proper method from the attributes. If the method is
// something other than GET or POST we'll use POST since we will spoof the
// actual method since forms don't support the reserved methods in HTML.
$attributes['method'] = $this->getMethod($method);
- $attributes['action'] = $this->getAction($options);
+ $attributes['action'] = $this->getAction($options);
- $attributes['accept-charset'] = 'UTF-8';
+ $attributes['accept-charset'] = 'UTF-8';
// If the method is PUT, PATCH or DELETE we will need to add a spoofer hidden
// field that will instruct the Symfony request to pretend the method is a
// different method than it actually is, for convenience from the forms.
$append = $this->getAppendage($method);
- if(isset($options['files']) && $options['files'])
- {
- $options['enctype'] = 'multipart/form-data';
- }
+ if (isset($options['files']) && $options['files']) {
+ $options['enctype'] = 'multipart/form-data';
+ }
// Finally we're ready to create the final form HTML field. We will attribute
// format the array of attributes. We will also add on the appendage which
@@ -133,7 +134,7 @@ class FormBuilder {
// extra value for the hidden _method field if it's needed for the form.
$attributes = $this->html->attributes($attributes);
- return '
';
+ return '';
}
/**
@@ -184,9 +185,9 @@ class FormBuilder {
*/
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);
}
/**
@@ -200,13 +201,13 @@ class FormBuilder {
*/
public function label($name, $value = null, $options = [])
{
- $this->labels[] = $name;
+ $this->labels[] = $name;
- $options = $this->html->attributes($options);
+ $options = $this->html->attributes($options);
- $value = e($this->formatLabel($name, $value));
+ $value = e($this->formatLabel($name, $value));
- return '';
+ return '';
}
/**
@@ -219,7 +220,7 @@ class FormBuilder {
*/
protected function formatLabel($name, $value)
{
- return $value ?: ucwords(str_replace('_', ' ', $name));
+ return $value ?: ucwords(str_replace('_', ' ', $name));
}
/**
@@ -234,26 +235,27 @@ class FormBuilder {
*/
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
// 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.
$id = $this->getIdAttribute($name, $options);
- if( ! in_array($type, $this->skipValueTypes))
- {
- $value = $this->getValueAttribute($name, $value);
- }
+ if (!in_array($type, $this->skipValueTypes)) {
+ $value = $this->getValueAttribute($name, $value);
+ }
// Once we have the type, value, and ID we can merge them into the rest of the
// attributes array so we can convert them into their HTML attribute format
// when creating the HTML element. Then, we will return the entire input.
$merge = compact('type', 'value', 'id');
- $options = array_merge($options, $merge);
+ $options = array_merge($options, $merge);
- return 'html->attributes($options) . '>';
+ return 'html->attributes($options).'>';
}
/**
@@ -267,7 +269,7 @@ class FormBuilder {
*/
public function text($name, $value = null, $options = [])
{
- return $this->input('text', $name, $value, $options);
+ return $this->input('text', $name, $value, $options);
}
/**
@@ -280,7 +282,7 @@ class FormBuilder {
*/
public function password($name, $options = [])
{
- return $this->input('password', $name, '', $options);
+ return $this->input('password', $name, '', $options);
}
/**
@@ -294,7 +296,7 @@ class FormBuilder {
*/
public function hidden($name, $value = null, $options = [])
{
- return $this->input('hidden', $name, $value, $options);
+ return $this->input('hidden', $name, $value, $options);
}
/**
@@ -308,7 +310,7 @@ class FormBuilder {
*/
public function email($name, $value = null, $options = [])
{
- return $this->input('email', $name, $value, $options);
+ return $this->input('email', $name, $value, $options);
}
/**
@@ -322,7 +324,7 @@ class FormBuilder {
*/
public function tel($name, $value = null, $options = [])
{
- return $this->input('tel', $name, $value, $options);
+ return $this->input('tel', $name, $value, $options);
}
/**
@@ -336,7 +338,7 @@ class FormBuilder {
*/
public function number($name, $value = null, $options = [])
{
- return $this->input('number', $name, $value, $options);
+ return $this->input('number', $name, $value, $options);
}
/**
@@ -350,12 +352,11 @@ class FormBuilder {
*/
public function date($name, $value = null, $options = [])
{
- if($value instanceof DateTime)
- {
- $value = $value->format('Y-m-d');
- }
+ if ($value instanceof DateTime) {
+ $value = $value->format('Y-m-d');
+ }
- return $this->input('date', $name, $value, $options);
+ return $this->input('date', $name, $value, $options);
}
/**
@@ -369,7 +370,7 @@ class FormBuilder {
*/
public function time($name, $value = null, $options = [])
{
- return $this->input('time', $name, $value, $options);
+ return $this->input('time', $name, $value, $options);
}
/**
@@ -383,7 +384,7 @@ class FormBuilder {
*/
public function url($name, $value = null, $options = [])
{
- return $this->input('url', $name, $value, $options);
+ return $this->input('url', $name, $value, $options);
}
/**
@@ -396,7 +397,7 @@ class FormBuilder {
*/
public function file($name, $options = [])
{
- return $this->input('file', $name, null, $options);
+ return $this->input('file', $name, null, $options);
}
/**
@@ -410,25 +411,27 @@ class FormBuilder {
*/
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
// on the textarea element definition. If they are not present, we will just
// assume some sane default values for these attributes for the developer.
$options = $this->setTextAreaSize($options);
- $options['id'] = $this->getIdAttribute($name, $options);
+ $options['id'] = $this->getIdAttribute($name, $options);
- $value = (string) $this->getValueAttribute($name, $value);
+ $value = (string) $this->getValueAttribute($name, $value);
- unset($options['size']);
+ unset($options['size']);
// Next we will convert the attributes into a string form. Also we have removed
// the size attribute, as it was merely a short-cut for the rows and cols on
// the element. Then we'll create the final textarea elements HTML for us.
$options = $this->html->attributes($options);
- return '';
+ return '';
}
/**
@@ -440,19 +443,18 @@ class FormBuilder {
*/
protected function setTextAreaSize($options)
{
- if(isset($options['size']))
- {
- return $this->setQuickTextAreaSize($options);
- }
+ if (isset($options['size'])) {
+ return $this->setQuickTextAreaSize($options);
+ }
// If the "size" attribute was not specified, we will just look for the regular
// columns and rows attributes, using sane defaults if these do not exist on
// the attributes array. We'll then return this entire options array back.
$cols = array_get($options, 'cols', 50);
- $rows = array_get($options, 'rows', 10);
+ $rows = array_get($options, 'rows', 10);
- return array_merge($options, compact('cols', 'rows'));
+ return array_merge($options, compact('cols', 'rows'));
}
/**
@@ -464,9 +466,9 @@ class FormBuilder {
*/
protected function setQuickTextAreaSize($options)
{
- $segments = explode('x', $options['size']);
+ $segments = explode('x', $options['size']);
- return array_merge($options, ['cols' => $segments[0], 'rows' => $segments[1]]);
+ return array_merge($options, ['cols' => $segments[0], 'rows' => $segments[1]]);
}
/**
@@ -481,39 +483,39 @@ class FormBuilder {
*/
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
// should provide a convenient method of re-populating the forms on post.
$selected = $this->getValueAttribute($name, $selected);
- $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
// 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.
$html = [];
- if(isset($options['placeholder']))
- {
- $html[] = $this->placeholderOption($options['placeholder'], $selected);
- unset($options['placeholder']);
- }
+ if (isset($options['placeholder'])) {
+ $html[] = $this->placeholderOption($options['placeholder'], $selected);
+ unset($options['placeholder']);
+ }
- foreach($list as $value => $display)
- {
- $html[] = $this->getSelectOption($display, $value, $selected);
- }
+ foreach ($list as $value => $display) {
+ $html[] = $this->getSelectOption($display, $value, $selected);
+ }
// Once we have all of this HTML, we can join this into a single element after
// formatting the attributes into an HTML "attributes" string, then we will
// build out a final select statement, which will contain all the values.
$options = $this->html->attributes($options);
- $list = implode('', $html);
+ $list = implode('', $html);
- return "";
+ return "";
}
/**
@@ -529,9 +531,9 @@ class FormBuilder {
*/
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);
- return $this->select($name, $range, $selected, $options);
+ return $this->select($name, $range, $selected, $options);
}
/**
@@ -547,7 +549,7 @@ class FormBuilder {
*/
public function selectYear()
{
- return call_user_func_array([$this, 'selectRange'], func_get_args());
+ return call_user_func_array([$this, 'selectRange'], func_get_args());
}
/**
@@ -562,14 +564,13 @@ class FormBuilder {
*/
public function selectMonth($name, $selected = null, $options = [], $format = '%B')
{
- $months = [];
+ $months = [];
- foreach(range(1, 12) as $month)
- {
- $months[$month] = strftime($format, mktime(0, 0, 0, $month, 1));
- }
+ foreach (range(1, 12) as $month) {
+ $months[$month] = strftime($format, mktime(0, 0, 0, $month, 1));
+ }
- return $this->select($name, $months, $selected, $options);
+ return $this->select($name, $months, $selected, $options);
}
/**
@@ -583,12 +584,11 @@ class FormBuilder {
*/
public function getSelectOption($display, $value, $selected)
{
- if(is_array($display))
- {
- return $this->optionGroup($display, $value, $selected);
- }
+ if (is_array($display)) {
+ return $this->optionGroup($display, $value, $selected);
+ }
- return $this->option($display, $value, $selected);
+ return $this->option($display, $value, $selected);
}
/**
@@ -602,14 +602,13 @@ class FormBuilder {
*/
protected function optionGroup($list, $label, $selected)
{
- $html = [];
+ $html = [];
- foreach($list as $value => $display)
- {
- $html[] = $this->option($display, $value, $selected);
- }
+ foreach ($list as $value => $display) {
+ $html[] = $this->option($display, $value, $selected);
+ }
- return '';
+ return '';
}
/**
@@ -623,11 +622,11 @@ class FormBuilder {
*/
protected function option($display, $value, $selected)
{
- $selected = $this->getSelectedValue($value, $selected);
+ $selected = $this->getSelectedValue($value, $selected);
- $options = ['value' => $value, 'selected' => $selected];
+ $options = ['value' => $value, 'selected' => $selected];
- return '';
+ return '';
}
/**
@@ -640,12 +639,12 @@ class FormBuilder {
*/
protected function placeholderOption($display, $selected)
{
- $selected = $this->getSelectedValue(null, $selected);
+ $selected = $this->getSelectedValue(null, $selected);
- $options = compact('selected');
- $options['value'] = '';
+ $options = compact('selected');
+ $options['value'] = '';
- return '';
+ return '';
}
/**
@@ -658,12 +657,11 @@ class FormBuilder {
*/
protected function getSelectedValue($value, $selected)
{
- if(is_array($selected))
- {
- return in_array($value, $selected) ? 'selected' : null;
- }
+ if (is_array($selected)) {
+ return in_array($value, $selected) ? 'selected' : null;
+ }
- return ((string) $value == (string) $selected) ? 'selected' : null;
+ return ((string) $value == (string) $selected) ? 'selected' : null;
}
/**
@@ -678,7 +676,7 @@ class FormBuilder {
*/
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);
}
/**
@@ -693,9 +691,11 @@ class FormBuilder {
*/
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);
}
/**
@@ -711,11 +711,13 @@ class FormBuilder {
*/
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);
}
/**
@@ -730,8 +732,7 @@ class FormBuilder {
*/
protected function getCheckedState($type, $name, $value, $checked)
{
- switch($type)
- {
+ switch ($type) {
case 'checkbox':
return $this->getCheckboxCheckedState($name, $value, $checked);
@@ -754,24 +755,23 @@ class FormBuilder {
*/
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, $checked);
+ $posted = $this->getValueAttribute($name, $checked);
- if (is_array($posted))
- {
- return in_array($value, $posted);
- }
- else if ($posted instanceof Collection)
- {
- return $posted->contains('id', $value);
- }
- else
- {
- return (bool) $posted;
- }
+ if (is_array($posted)) {
+ return in_array($value, $posted);
+ } elseif ($posted instanceof Collection) {
+ return $posted->contains('id', $value);
+ } else {
+ return (bool) $posted;
+ }
}
/**
@@ -785,9 +785,11 @@ class FormBuilder {
*/
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;
}
/**
@@ -799,7 +801,7 @@ class FormBuilder {
*/
protected function missingOldAndModel($name)
{
- return (is_null($this->old($name)) && is_null($this->getModelValueAttribute($name)));
+ return (is_null($this->old($name)) && is_null($this->getModelValueAttribute($name)));
}
/**
@@ -812,7 +814,7 @@ class FormBuilder {
*/
public function reset($value, $attributes = [])
{
- return $this->input('reset', null, $value, $attributes);
+ return $this->input('reset', null, $value, $attributes);
}
/**
@@ -826,9 +828,9 @@ class FormBuilder {
*/
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);
}
/**
@@ -841,7 +843,7 @@ class FormBuilder {
*/
public function submit($value = null, $options = [])
{
- return $this->input('submit', null, $value, $options);
+ return $this->input('submit', null, $value, $options);
}
/**
@@ -854,12 +856,11 @@ class FormBuilder {
*/
public function button($value = null, $options = [])
{
- if( ! array_key_exists('type', $options))
- {
- $options['type'] = 'button';
- }
+ if (!array_key_exists('type', $options)) {
+ $options['type'] = 'button';
+ }
- return '';
+ return '';
}
/**
@@ -871,9 +872,9 @@ class FormBuilder {
*/
protected function getMethod($method)
{
- $method = strtoupper($method);
+ $method = strtoupper($method);
- return $method != 'GET' ? 'POST' : $method;
+ return $method != 'GET' ? 'POST' : $method;
}
/**
@@ -885,28 +886,25 @@ class FormBuilder {
*/
protected function getAction(array $options)
{
- // 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
// a form providing a convenient interface for creating the form actions.
- if(isset($options['url']))
- {
- return $this->getUrlAction($options['url']);
+ if (isset($options['url'])) {
+ return $this->getUrlAction($options['url']);
}
- if(isset($options['route']))
- {
- return $this->getRouteAction($options['route']);
- }
+ if (isset($options['route'])) {
+ return $this->getRouteAction($options['route']);
+ }
// 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
// actions and return them from the method. Otherwise, we'll use current.
- elseif(isset($options['action']))
- {
- return $this->getControllerAction($options['action']);
+ elseif (isset($options['action'])) {
+ return $this->getControllerAction($options['action']);
}
- return $this->url->current();
+ return $this->url->current();
}
/**
@@ -918,12 +916,11 @@ class FormBuilder {
*/
protected function getUrlAction($options)
{
- if(is_array($options))
- {
- return $this->url->to($options[0], array_slice($options, 1));
- }
+ if (is_array($options)) {
+ return $this->url->to($options[0], array_slice($options, 1));
+ }
- return $this->url->to($options);
+ return $this->url->to($options);
}
/**
@@ -935,12 +932,11 @@ class FormBuilder {
*/
protected function getRouteAction($options)
{
- if(is_array($options))
- {
- return $this->url->route($options[0], array_slice($options, 1));
- }
+ if (is_array($options)) {
+ return $this->url->route($options[0], array_slice($options, 1));
+ }
- return $this->url->route($options);
+ return $this->url->route($options);
}
/**
@@ -952,12 +948,11 @@ class FormBuilder {
*/
protected function getControllerAction($options)
{
- if(is_array($options))
- {
- return $this->url->action($options[0], array_slice($options, 1));
- }
+ if (is_array($options)) {
+ return $this->url->action($options[0], array_slice($options, 1));
+ }
- return $this->url->action($options);
+ return $this->url->action($options);
}
/**
@@ -969,25 +964,23 @@ class FormBuilder {
*/
protected function getAppendage($method)
{
- list($method, $appendage) = [strtoupper($method), ''];
+ list($method, $appendage) = [strtoupper($method), ''];
// 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
// form to initiate PUT and DELETE requests in addition to the typical.
- if(in_array($method, $this->spoofedMethods))
- {
- $appendage .= $this->hidden('_method', $method);
+ if (in_array($method, $this->spoofedMethods)) {
+ $appendage .= $this->hidden('_method', $method);
}
// 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
// always have available on every form the developers creates for them.
- if($method != 'GET')
- {
- $appendage .= $this->token();
+ if ($method != 'GET') {
+ $appendage .= $this->token();
}
- return $appendage;
+ return $appendage;
}
/**
@@ -1000,15 +993,13 @@ class FormBuilder {
*/
public function getIdAttribute($name, $attributes)
{
- if(array_key_exists('id', $attributes))
- {
- return $attributes['id'];
- }
+ if (array_key_exists('id', $attributes)) {
+ return $attributes['id'];
+ }
- if(in_array($name, $this->labels))
- {
- return $name;
- }
+ if (in_array($name, $this->labels)) {
+ return $name;
+ }
}
/**
@@ -1021,19 +1012,21 @@ class FormBuilder {
*/
public function getValueAttribute($name, $value = null)
{
- if(is_null($name)) return $value;
+ if (is_null($name)) {
+ return $value;
+ }
- if( ! is_null($this->old($name)))
- {
- return $this->old($name);
- }
+ if (!is_null($this->old($name))) {
+ return $this->old($name);
+ }
- if( ! is_null($value)) return $value;
+ if (!is_null($value)) {
+ return $value;
+ }
- if(isset($this->model))
- {
- return $this->getModelValueAttribute($name);
- }
+ if (isset($this->model)) {
+ return $this->getModelValueAttribute($name);
+ }
}
/**
@@ -1045,7 +1038,7 @@ class FormBuilder {
*/
protected function getModelValueAttribute($name)
{
- return data_get($this->model, $this->transformKey($name));
+ return data_get($this->model, $this->transformKey($name));
}
/**
@@ -1057,10 +1050,9 @@ class FormBuilder {
*/
public function old($name)
{
- if(isset($this->session))
- {
- return $this->session->getOldInput($this->transformKey($name));
- }
+ if (isset($this->session)) {
+ return $this->session->getOldInput($this->transformKey($name));
+ }
}
/**
@@ -1070,7 +1062,7 @@ class FormBuilder {
*/
public function oldInputIsEmpty()
{
- return (isset($this->session) && count($this->session->getOldInput()) == 0);
+ return (isset($this->session) && count($this->session->getOldInput()) == 0);
}
/**
@@ -1082,7 +1074,7 @@ class FormBuilder {
*/
protected function transformKey($key)
{
- return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key);
+ return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key);
}
/**
@@ -1092,7 +1084,7 @@ class FormBuilder {
*/
public function getSessionStore()
{
- return $this->session;
+ return $this->session;
}
/**
@@ -1104,8 +1096,8 @@ class FormBuilder {
*/
public function setSessionStore(Session $session)
{
- $this->session = $session;
+ $this->session = $session;
- return $this;
+ return $this;
}
}
diff --git a/src/FormFacade.php b/src/FormFacade.php
index 064f953..66d459f 100644
--- a/src/FormFacade.php
+++ b/src/FormFacade.php
@@ -1,17 +1,21 @@
-url = $url;
+ }
- /**
- * Create a new HTML builder instance.
- *
- * @param \Illuminate\Routing\UrlGenerator $url
- * @return void
- */
- public function __construct(UrlGenerator $url = null)
- {
- $this->url = $url;
- }
+ /**
+ * Convert an HTML string to entities.
+ *
+ * @param string $value
+ *
+ * @return string
+ */
+ public function entities($value)
+ {
+ return htmlentities($value, ENT_QUOTES, 'UTF-8', false);
+ }
- /**
- * Convert an HTML string to entities.
- *
- * @param string $value
- * @return string
- */
- public function entities($value)
- {
- return htmlentities($value, ENT_QUOTES, 'UTF-8', false);
- }
+ /**
+ * Convert entities to HTML characters.
+ *
+ * @param string $value
+ *
+ * @return string
+ */
+ public function decode($value)
+ {
+ return html_entity_decode($value, ENT_QUOTES, 'UTF-8');
+ }
- /**
- * Convert entities to HTML characters.
- *
- * @param string $value
- * @return string
- */
- public function decode($value)
- {
- return html_entity_decode($value, ENT_QUOTES, 'UTF-8');
- }
+ /**
+ * Generate a link to a JavaScript file.
+ *
+ * @param string $url
+ * @param array $attributes
+ * @param bool $secure
+ *
+ * @return string
+ */
+ public function script($url, $attributes = [], $secure = null)
+ {
+ $attributes['src'] = $this->url->asset($url, $secure);
- /**
- * Generate a link to a JavaScript file.
- *
- * @param string $url
- * @param array $attributes
- * @param bool $secure
- * @return string
- */
- public function script($url, $attributes = array(), $secure = null)
- {
- $attributes['src'] = $this->url->asset($url, $secure);
+ return ''.PHP_EOL;
+ }
- return ''.PHP_EOL;
- }
+ /**
+ * Generate a link to a CSS file.
+ *
+ * @param string $url
+ * @param array $attributes
+ * @param bool $secure
+ *
+ * @return string
+ */
+ public function style($url, $attributes = [], $secure = null)
+ {
+ $defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet'];
- /**
- * Generate a link to a CSS file.
- *
- * @param string $url
- * @param array $attributes
- * @param bool $secure
- * @return string
- */
- public function style($url, $attributes = array(), $secure = null)
- {
- $defaults = array('media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet');
+ $attributes = $attributes + $defaults;
- $attributes = $attributes + $defaults;
+ $attributes['href'] = $this->url->asset($url, $secure);
- $attributes['href'] = $this->url->asset($url, $secure);
+ return 'attributes($attributes).'>'.PHP_EOL;
+ }
- return 'attributes($attributes).'>'.PHP_EOL;
- }
+ /**
+ * Generate an HTML image element.
+ *
+ * @param string $url
+ * @param string $alt
+ * @param array $attributes
+ * @param bool $secure
+ *
+ * @return string
+ */
+ public function image($url, $alt = null, $attributes = [], $secure = null)
+ {
+ $attributes['alt'] = $alt;
- /**
- * Generate an HTML image element.
- *
- * @param string $url
- * @param string $alt
- * @param array $attributes
- * @param bool $secure
- * @return string
- */
- public function image($url, $alt = null, $attributes = array(), $secure = null)
- {
- $attributes['alt'] = $alt;
+ return 'attributes($attributes).'>';
+ }
- return 'attributes($attributes).'>';
- }
+ /**
+ * Generate a link to a Favicon file.
+ *
+ * @param string $url
+ * @param array $attributes
+ * @param bool $secure
+ *
+ * @return string
+ */
+ public function favicon($url, $attributes = [], $secure = null)
+ {
+ $defaults = ['rel' => 'shortcut icon', 'type' => 'image/x-icon'];
- /**
- * Generate a link to a Favicon file.
- *
- * @param string $url
- * @param array $attributes
- * @param bool $secure
- * @return string
- */
- public function favicon($url, $attributes = array(), $secure = null)
- {
- $defaults = array('rel' => 'shortcut icon', 'type' => 'image/x-icon');
+ $attributes = $attributes + $defaults;
- $attributes = $attributes + $defaults;
+ $attributes['href'] = $this->url->asset($url, $secure);
- $attributes['href'] = $this->url->asset($url, $secure);
+ return 'attributes($attributes).'>'.PHP_EOL;
+ }
- return 'attributes($attributes).'>'.PHP_EOL;
- }
+ /**
+ * Generate a HTML link.
+ *
+ * @param string $url
+ * @param string $title
+ * @param array $attributes
+ * @param bool $secure
+ *
+ * @return string
+ */
+ public function link($url, $title = null, $attributes = [], $secure = null)
+ {
+ $url = $this->url->to($url, [], $secure);
- /**
- * Generate a HTML link.
- *
- * @param string $url
- * @param string $title
- * @param array $attributes
- * @param bool $secure
- * @return string
- */
- public function link($url, $title = null, $attributes = array(), $secure = null)
- {
- $url = $this->url->to($url, array(), $secure);
+ if (is_null($title) || $title === false) {
+ $title = $url;
+ }
- if (is_null($title) || $title === false) $title = $url;
+ return 'attributes($attributes).'>'.$this->entities($title).'';
+ }
- return 'attributes($attributes).'>'.$this->entities($title).'';
- }
+ /**
+ * Generate a HTTPS HTML link.
+ *
+ * @param string $url
+ * @param string $title
+ * @param array $attributes
+ *
+ * @return string
+ */
+ public function secureLink($url, $title = null, $attributes = [])
+ {
+ return $this->link($url, $title, $attributes, true);
+ }
- /**
- * Generate a HTTPS HTML link.
- *
- * @param string $url
- * @param string $title
- * @param array $attributes
- * @return string
- */
- public function secureLink($url, $title = null, $attributes = array())
- {
- return $this->link($url, $title, $attributes, true);
- }
+ /**
+ * Generate a HTML link to an asset.
+ *
+ * @param string $url
+ * @param string $title
+ * @param array $attributes
+ * @param bool $secure
+ *
+ * @return string
+ */
+ public function linkAsset($url, $title = null, $attributes = [], $secure = null)
+ {
+ $url = $this->url->asset($url, $secure);
- /**
- * Generate a HTML link to an asset.
- *
- * @param string $url
- * @param string $title
- * @param array $attributes
- * @param bool $secure
- * @return string
- */
- public function linkAsset($url, $title = null, $attributes = array(), $secure = null)
- {
- $url = $this->url->asset($url, $secure);
+ return $this->link($url, $title ?: $url, $attributes, $secure);
+ }
- return $this->link($url, $title ?: $url, $attributes, $secure);
- }
+ /**
+ * Generate a HTTPS HTML link to an asset.
+ *
+ * @param string $url
+ * @param string $title
+ * @param array $attributes
+ *
+ * @return string
+ */
+ public function linkSecureAsset($url, $title = null, $attributes = [])
+ {
+ return $this->linkAsset($url, $title, $attributes, true);
+ }
- /**
- * Generate a HTTPS HTML link to an asset.
- *
- * @param string $url
- * @param string $title
- * @param array $attributes
- * @return string
- */
- public function linkSecureAsset($url, $title = null, $attributes = array())
- {
- return $this->linkAsset($url, $title, $attributes, true);
- }
+ /**
+ * Generate a HTML link to a named route.
+ *
+ * @param string $name
+ * @param string $title
+ * @param array $parameters
+ * @param array $attributes
+ *
+ * @return string
+ */
+ public function linkRoute($name, $title = null, $parameters = [], $attributes = [])
+ {
+ return $this->link($this->url->route($name, $parameters), $title, $attributes);
+ }
- /**
- * Generate a HTML link to a named route.
- *
- * @param string $name
- * @param string $title
- * @param array $parameters
- * @param array $attributes
- * @return string
- */
- public function linkRoute($name, $title = null, $parameters = array(), $attributes = array())
- {
- return $this->link($this->url->route($name, $parameters), $title, $attributes);
- }
+ /**
+ * Generate a HTML link to a controller action.
+ *
+ * @param string $action
+ * @param string $title
+ * @param array $parameters
+ * @param array $attributes
+ *
+ * @return string
+ */
+ public function linkAction($action, $title = null, $parameters = [], $attributes = [])
+ {
+ return $this->link($this->url->action($action, $parameters), $title, $attributes);
+ }
- /**
- * Generate a HTML link to a controller action.
- *
- * @param string $action
- * @param string $title
- * @param array $parameters
- * @param array $attributes
- * @return string
- */
- public function linkAction($action, $title = null, $parameters = array(), $attributes = array())
- {
- return $this->link($this->url->action($action, $parameters), $title, $attributes);
- }
+ /**
+ * Generate a HTML link to an email address.
+ *
+ * @param string $email
+ * @param string $title
+ * @param array $attributes
+ *
+ * @return string
+ */
+ public function mailto($email, $title = null, $attributes = [])
+ {
+ $email = $this->email($email);
- /**
- * Generate a HTML link to an email address.
- *
- * @param string $email
- * @param string $title
- * @param array $attributes
- * @return string
- */
- public function mailto($email, $title = null, $attributes = array())
- {
- $email = $this->email($email);
+ $title = $title ?: $email;
- $title = $title ?: $email;
+ $email = $this->obfuscate('mailto:').$email;
- $email = $this->obfuscate('mailto:') . $email;
+ return 'attributes($attributes).'>'.$this->entities($title).'';
+ }
- return 'attributes($attributes).'>'.$this->entities($title).'';
- }
+ /**
+ * Obfuscate an e-mail address to prevent spam-bots from sniffing it.
+ *
+ * @param string $email
+ *
+ * @return string
+ */
+ public function email($email)
+ {
+ return str_replace('@', '@', $this->obfuscate($email));
+ }
- /**
- * Obfuscate an e-mail address to prevent spam-bots from sniffing it.
- *
- * @param string $email
- * @return string
- */
- public function email($email)
- {
- return str_replace('@', '@', $this->obfuscate($email));
- }
+ /**
+ * Generate an ordered list of items.
+ *
+ * @param array $list
+ * @param array $attributes
+ *
+ * @return string
+ */
+ public function ol($list, $attributes = [])
+ {
+ return $this->listing('ol', $list, $attributes);
+ }
- /**
- * Generate an ordered list of items.
- *
- * @param array $list
- * @param array $attributes
- * @return string
- */
- public function ol($list, $attributes = array())
- {
- return $this->listing('ol', $list, $attributes);
- }
+ /**
+ * Generate an un-ordered list of items.
+ *
+ * @param array $list
+ * @param array $attributes
+ *
+ * @return string
+ */
+ public function ul($list, $attributes = [])
+ {
+ return $this->listing('ul', $list, $attributes);
+ }
- /**
- * Generate an un-ordered list of items.
- *
- * @param array $list
- * @param array $attributes
- * @return string
- */
- public function ul($list, $attributes = array())
- {
- return $this->listing('ul', $list, $attributes);
- }
+ /**
+ * Generate a description list of items.
+ *
+ * @param array $list
+ * @param array $attributes
+ *
+ * @return string
+ */
+ public function dl(array $list, array $attributes = [])
+ {
+ $attributes = $this->attributes($attributes);
- /**
- * Generate a description list of items.
- *
- * @param array $list
- * @param array $attributes
- * @return string
- */
- public function dl(array $list, array $attributes = [])
- {
- $attributes = $this->attributes($attributes);
+ $html = "
';
+ return $html;
+ }
- return $html;
- }
+ /**
+ * Create a listing HTML element.
+ *
+ * @param string $type
+ * @param array $list
+ * @param array $attributes
+ *
+ * @return string
+ */
+ protected function listing($type, $list, $attributes = [])
+ {
+ $html = '';
- /**
- * Create a listing HTML element.
- *
- * @param string $type
- * @param array $list
- * @param array $attributes
- * @return string
- */
- protected function listing($type, $list, $attributes = array())
- {
- $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
+ // 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.
+ foreach ($list as $key => $value) {
+ $html .= $this->listingElement($key, $type, $value);
+ }
- // 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
- // present in the array. Then we will build out the final listing elements.
- foreach ($list as $key => $value)
- {
- $html .= $this->listingElement($key, $type, $value);
- }
+ $attributes = $this->attributes($attributes);
- $attributes = $this->attributes($attributes);
+ return "<{$type}{$attributes}>{$html}{$type}>";
+ }
- return "<{$type}{$attributes}>{$html}{$type}>";
- }
+ /**
+ * Create the HTML for a listing element.
+ *
+ * @param mixed $key
+ * @param string $type
+ * @param mixed $value
+ *
+ * @return string
+ */
+ protected function listingElement($key, $type, $value)
+ {
+ if (is_array($value)) {
+ return $this->nestedListing($key, $type, $value);
+ } else {
+ return '