htmlizerFactory = $htmlizerFactory; $this->aclManager = $aclManager; } /** * Setting a user also sets applyAcl. */ public function setUser(User $user): self { $this->user = $user; $this->setApplyAcl(); return $this; } public function setEntity(Entity $entity): self { $this->entity = $entity; return $this; } /** * @param stdClass|array $data Additional data. */ public function setData($data): self { if (!is_array($data) && !$data instanceof stdClass) { throw new InvalidArgumentException(); } if (is_object($data)) { $data = get_object_vars($data); } $this->data = $data; return $this; } public function setSkipRelations(bool $skipRelations = true): self { $this->skipRelations = $skipRelations; return $this; } public function setApplyAcl(bool $applyAcl = true): self { $this->applyAcl = $applyAcl; return $this; } public function render(): string { if (!$this->template) { throw new LogicException("No template."); } return $this->renderTemplate($this->template); } public function renderTemplate(string $template): string { return $this->renderTemplateInternal($template, $this->createHtmlizer()); } private function renderTemplateInternal(string $template, Htmlizer $htmlizer): string { return $htmlizer->render( $this->entity, $template, null, $this->data, $this->skipRelations ); } /** * @return string */ public function renderMultipleTemplates(string ...$templateList): array { $htmlizer = $this->createHtmlizer(); $resultList = []; foreach ($templateList as $template) { $resultList[] = $this->renderTemplateInternal($template, $htmlizer); } return $resultList; } private function createHtmlizer(): Htmlizer { return $this->user ? $this->htmlizerFactory->createForUser($this->user) : $this->htmlizerFactory->create(!$this->applyAcl); } }