diff options
Diffstat (limited to 'src/Compile/Base.php')
| -rw-r--r-- | src/Compile/Base.php | 84 |
1 files changed, 6 insertions, 78 deletions
diff --git a/src/Compile/Base.php b/src/Compile/Base.php index 2d5c0c0e..10153501 100644 --- a/src/Compile/Base.php +++ b/src/Compile/Base.php @@ -82,84 +82,12 @@ abstract class Base implements CompilerInterface { * @return array of mapped attributes for further processing */ protected function getAttributes($compiler, $attributes) { - $_indexed_attr = []; - $options = array_fill_keys($this->option_flags, true); - foreach ($attributes as $key => $mixed) { - // shorthand ? - if (!is_array($mixed)) { - // options flag ? - if (isset($options[trim($mixed, '\'"')])) { - $_indexed_attr[trim($mixed, '\'"')] = true; - // shorthand attribute ? - } elseif (isset($this->shorttag_order[$key])) { - $_indexed_attr[$this->shorttag_order[$key]] = $mixed; - } else { - // too many shorthands - $compiler->trigger_template_error('too many shorthand attributes', null, true); - } - // named attribute - } else { - foreach ($mixed as $k => $v) { - // options flag? - if (isset($options[$k])) { - if (is_bool($v)) { - $_indexed_attr[$k] = $v; - } else { - if (is_string($v)) { - $v = trim($v, '\'" '); - } - - // Mapping array for boolean option value - static $optionMap = [1 => true, 0 => false, 'true' => true, 'false' => false]; - - if (isset($optionMap[$v])) { - $_indexed_attr[$k] = $optionMap[$v]; - } else { - $compiler->trigger_template_error( - "illegal value '" . var_export($v, true) . - "' for options flag '{$k}'", - null, - true - ); - } - } - // must be named attribute - } else { - $_indexed_attr[$k] = $v; - } - } - } - } - // check if all required attributes present - foreach ($this->required_attributes as $attr) { - if (!isset($_indexed_attr[$attr])) { - $compiler->trigger_template_error("missing '{$attr}' attribute", null, true); - } - } - // check for not allowed attributes - if ($this->optional_attributes !== ['_any']) { - $allowedAttributes = array_fill_keys( - array_merge( - $this->required_attributes, - $this->optional_attributes, - $this->option_flags - ), - true - ); - foreach ($_indexed_attr as $key => $dummy) { - if (!isset($allowedAttributes[$key]) && $key !== 0) { - $compiler->trigger_template_error("unexpected '{$key}' attribute", null, true); - } - } - } - // default 'false' for all options flags not set - foreach ($this->option_flags as $flag) { - if (!isset($_indexed_attr[$flag])) { - $_indexed_attr[$flag] = false; - } - } - - return $_indexed_attr; + return (new AttributeCompiler( + $this->required_attributes, + $this->optional_attributes, + $this->shorttag_order, + $this->option_flags + ))->getAttributes($compiler, $attributes); } /** |
