/** * @param GenericTagInterface $tag * @return HtmlTag */ public function setBody(GenericTagInterface $tag) { if ('body' !== $tag->getTagName()) { $err = 'tag must have a tag name of -(body)'; throw new InvalidArgumentException($err); } $this->body = $tag; return $this; }
/** * Move all assignments into the view. Build the view into a string, note * that when the view has dynamically generated javascript a.k.a (pjs) * view composition (build) will return an array of two strings, content, * and js in that order. Content is assigned to the body tag and js is * assigned as content to the inline script tag. We finally turn the * body tag content into a string and return it. * * @throws DomainException * @param HtmlTagInterface $body * @return string */ protected function buildView(GenericTagInterface $body) { if (!$this->isView()) { return ''; } if ('body' !== $body->getTagName()) { $err = 'build view will only accept an html body tag'; throw new DomainException($err); } $view = $this->getView(); $view->load($this->getAll()); $result = $view->build(); $content = ''; $initJs = null; if (is_array($result)) { $content = current($result); $initJs = next($result); if ($this->isJs() && is_string($initJs)) { $this->addToInlineScript($initJs, 'append'); } } else { if (is_string($result)) { $content = $result; } } $body->addContent($content, 'prepend'); return $body->getContentString(); }
/** * @throws InvalidArgumentException * @param GenericTagInterface $tag * @return HeadTag */ public function addScript(GenericTagInterface $tag) { if ('script' !== $tag->getTagName()) { $err = 'must have a tag name of -(script)'; throw new InvalidArgumentException($err); } $this->scripts[] = $tag; return $this; }