diff --git a/src/ext/spout/SpoutBuilder.php b/src/ext/spout/SpoutBuilder.php index e45f1e9..1542d15 100644 --- a/src/ext/spout/SpoutBuilder.php +++ b/src/ext/spout/SpoutBuilder.php @@ -6,7 +6,6 @@ use nulib\file\tab\AbstractBuilder; use nulib\file\tab\TAbstractBuilder; use nulib\os\path; use nulib\php\func; -use nulib\php\nur_func; use nulib\php\time\Date; use nulib\php\time\DateTime; use nulib\ref\ext\spout\ref_builder; @@ -95,20 +94,23 @@ class SpoutBuilder extends AbstractBuilder { if (($rotation = $cell["rotation"] ?? null) !== null) $style->setTextRotation($rotation); if (($format = $cell["format"] ?? null) !== null) $style->setFormat($format); if (($border = $cell["border"] ?? null) !== null) { - if (is_string($border)) { - $parts = explode(" ", $border); - $border = []; + if (is_array($border)) $borderDefs = $border; + else $borderDefs = preg_split('/\s*,\s*/', trim(strval($border))); + $border = null; + foreach ($borderDefs as $borderDef) { + $parts = preg_split('/\s+/', $borderDef); + $borderDef = []; $styleAll = null; $widthAll = null; $colorAll = null; foreach ($parts as $part) { if ($part === "all") { - $border["left"] = []; - $border["top"] = []; - $border["right"] = []; - $border["bottom"] = []; + $borderDef["left"] = []; + $borderDef["top"] = []; + $borderDef["right"] = []; + $borderDef["bottom"] = []; } elseif (preg_match('/^(left|top|right|bottom)$/', $part)) { - $border[$part] = []; + $borderDef[$part] = []; } elseif (preg_match('/^(none|solid|dashed|dotted|double)$/', $part)) { $styleAll = $part; } elseif (preg_match('/^(thin|medium|thick)$/', $part)) { @@ -117,18 +119,23 @@ class SpoutBuilder extends AbstractBuilder { $colorAll = $part; } } - foreach ($border as &$part) { + foreach ($borderDef as &$part) { if ($styleAll !== null) $part["style"] = $styleAll; if ($widthAll !== null) $part["width"] = $widthAll; if ($colorAll !== null) $part["color"] = $colorAll; }; unset($part); + + $top = $borderDef["top"] ?? null; + $right = $borderDef["right"] ?? null; + $bottom = $borderDef["bottom"] ?? null; + $left = $borderDef["left"] ?? null; + + self::add_border_part($border, "top", $top); + self::add_border_part($border, "right", $right); + self::add_border_part($border, "bottom", $bottom); + self::add_border_part($border, "left", $left); } - $parts = null; - self::add_border_part($parts, "top", $border["top"] ?? null); - self::add_border_part($parts, "right", $border["right"] ?? null); - self::add_border_part($parts, "bottom", $border["bottom"] ?? null); - self::add_border_part($parts, "left", $border["left"] ?? null); - if ($parts !== null) $style->setBorder(new Border(...$parts)); + if ($border !== null) $style->setBorder(new Border(...$border)); } if (($autofit = $cell["autofit"] ?? null) !== null) $style->setShouldShrinkToFit($autofit); return $style; @@ -333,13 +340,8 @@ class SpoutBuilder extends AbstractBuilder { } if (array_key_exists("cook_func", $sheetParams)) { $cookFunc = $sheetParams["cook_func"] ?? null; - $cookCtx = $cookArgs = null; - if ($cookFunc !== null) { - nur_func::ensure_func($cookFunc, $this, $cookArgs); - $cookCtx = nur_func::_prepare($cookFunc); - } - $this->cookCtx = $cookCtx; - $this->cookArgs = $cookArgs; + if ($cookFunc !== null) $cookFunc = func::with($cookFunc)->bind($this); + $this->cookFunc = $cookFunc; } } return $this;