private function text_addComponent($content, $trim = self::NO_TRIM) { $context = $this->current->context; if ($context->condenseLiterals) { switch ($trim) { case self::TRIM_LEFT: $content = preg_replace(self::TRIM_LEFT_CONTENT, '', $content); break; case self::TRIM_RIGHT: $content = preg_replace(self::TRIM_RIGHT_CONTENT, '', $content); break; case self::TRIM: $content = preg_replace(self::TRIM_LITERAL_CONTENT, '', $content); break; } } if ($content != '') { if (isset($this->currentScalarProperty)) { $this->currentScalarValue .= $content; //Note: data binding will be taken care of later. } else { if ($content[0] == '{') { $lit = Text::from($context); $lit->setBindings(['value' => new Expression($content)]); } else { $lit = Text::from($context, $content); } $this->current->addChild($lit); } } }
/** * Converts an array of Metadata trees to actual content that can be rendered. * * @param self[] $metadata The metadata to be converted. * @param Component $parent The content will be assigned to this component and will inherit its context. * @param bool $prepend When true, children are prepended to the existing content, or the the beginning of a * collection property. */ public static function compile(array $metadata, Component $parent, $prepend = false) { foreach ($metadata as $item) { if (!$item instanceof self) { $parent->addChild($item->cloneWithContext($parent->context), $prepend); continue; } $tag = $item->getTagName(); $propName = lcfirst($tag); // Insert metadata if ($parent->props && !$parent instanceof self && $parent->props->defines($propName)) { if ($parent->props->getTypeOf($propName) == type::collection) { $comp = new self($parent->context, $tag, $parent->props->getRelatedTypeOf($propName), $item->props->getAll(), $item->bindings); if ($prepend) { array_unshift($parent->props->{$propName}, $comp); } else { array_push($parent->props->{$propName}, $comp); } } else { $comp = new self($parent->context, $tag, $parent->props->getTypeOf($propName), $item->props->getAll(), $item->bindings); $parent->props->set($propName, $comp); } } else { $comp = $tag === 'Text' ? Text::from($parent->context, $item->value) : $parent->context->createComponentFromTag($tag, $parent, $item->props->getAll(), $item->bindings); $parent->addChild($comp, $prepend); } // Now, compile the children. self::compile($item->getChildren(), $comp); } }