From: Andrey Kutejko Date: Thu, 28 Nov 2013 22:34:39 +0000 (+0200) Subject: html builder: bulk add attributes X-Git-Tag: 0.1~6 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=3a03fa344bd0a39ac966f78ea4a1554b8add251a;p=missing-tools.git html builder: bulk add attributes --- 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();