From 3a03fa344bd0a39ac966f78ea4a1554b8add251a Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Fri, 29 Nov 2013 00:34:39 +0200 Subject: [PATCH] html builder: bulk add attributes --- src/htmlbuilder.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/htmlbuilder.php b/src/htmlbuilder.php index c253eab..6b4aa4f 100644 --- a/src/htmlbuilder.php +++ b/src/htmlbuilder.php @@ -33,6 +33,21 @@ class Tag return $this; } + public function attrs($attributes) + { + foreach ($attributes as $k => $v) { + if ($k == 'class') { + if (!is_array($v)) + $v = explode(' ', $v); + foreach ($v as $class) + $this->addClass($class); + } else { + $this->attributes[$k] = $v; + } + } + return $this; + } + private function getListAttribute($name) { $classes = isset($this->attributes[$name]) ? $this->attributes[$name] : array(); -- 2.49.0