* @package zin * @version $Id * @link https://www.zentao.net */ namespace zin; require_once dirname(__DIR__) . DS . 'utils' . DS . 'dataset.class.php'; class style extends \zin\utils\dataset implements iDirective { /** * Magic method for setting style. * * @access public * @param string $name - Property name. * @param array $args - Property values. * @return style */ public function __call($name, $args) { $value = empty($args) ? true : (count($args) === 1 ? $args[0] : $args); return $this->setVal($name, $value); } /** * Method for sub class to hook on setting it. * * @access protected * @param string $name Property name or properties list. * @param mixed $value Property value. * @return style */ protected function setVal($name, $value) { $name = static::formatStyleName($name); if($value === null) { $this->storedData[$name] = $value; return $this; } if(!is_bool($value)) $value = static::formatStyleValue($name, $value); $this->storedData[$name] = $value; return $this; } /** * @param \zin\node $node * @param string $blockName */ public function apply($node, $blockName) { $style = array(); $class = array(); foreach ($this->storedData as $name => $value) { if(is_bool($value)) $class[$name] = $value; else $style[$name] = $value; } if($style) $node->setProp('style', $style); if($class) $node->setProp('class', $class); } /** * @param string|mixed[] $nameOrMap * @param mixed $value */ public function var($nameOrMap, $value = null) { if(is_array($nameOrMap)) { foreach($nameOrMap as $name => $val) $this->setVal('--' . $name, $val); return $this; } return $this->setVal('--' . $nameOrMap, $value); } /** * Magic static method for style property value. * * @access public * @param string $name - Property name. * @param array $args - Property values. * @return style */ public static function __callStatic($name, $args) { $style = new style(); $style->$name(...$args); return $style; } /** * @param string $name */ public static function formatStyleName($name) { return strtolower(preg_replace('/(?