From 68dfedc20b316fc8e6e1623792b37f18125b42b0 Mon Sep 17 00:00:00 2001 From: crynobone Date: Sun, 13 Sep 2015 14:05:20 +0800 Subject: [PATCH] Add `Orchestra\Html\HtmlBuilder::attributable()`. Signed-off-by: crynobone --- src/HtmlBuilder.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index 9cca3aa..62de71c 100644 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -57,6 +57,20 @@ public function raw($value) return new Expression($value); } + /** + * Build a list of HTML attributes from one or two array and generate + * HTML attributes. + * + * @param array $attributes + * @param array $defaults + * + * @return string + */ + public function attributable(array $attributes, array $defaults = []) + { + return $this->attributes($this->decorate($attributes, $defaults)); + } + /** * Build a list of HTML attributes from one or two array. * @@ -88,8 +102,8 @@ protected function buildClassDecorate(array $attributes, array $defaults = []) { // Special consideration to class, where we need to merge both string // from $attributes and $defaults, then take union of both. - $default = Arr::get($defaults, 'class', ''); - $attribute = Arr::get($attributes, 'class', ''); + $default = isset($defaults['class'] ? $defaults['class'] : ''; + $attribute = isset($attributes['class'] ? $attributes['class'] : ''; $classes = explode(' ', trim($default.' '.$attribute)); $current = array_unique($classes);