/** * @param array $links * * @return $this|self */ private function setSchema(array $links = []) : self { $this->schema = new HtmlContainer('<script>'); $this->schema->addAttribute('type', 'application/ld+json'); $content = ['@context' => 'http://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => []]; $uri = clone self::request()->getUri(); $count = 1; foreach ($links as $url => $link) { $content['itemListElement'][] = ['@type' => 'ListItem', 'position' => $count, 'item' => ['@id' => $uri->setPath($url)->get(false), 'name' => $link]]; $count++; } $this->schema->setContent(json_encode($content)); $this->add($this->schema); return $this; }
/** * @param bool $required * * @return $this|self */ public function setRequired(bool $required = true) { if ($required) { $this->field->addAttribute('required', 'required'); } else { $this->field->removeAttribute('required'); } return $this; }
/** * @param string|null $namespace * @param string|null $service * @param string|null $method * @param int|null $version */ public function init(string $namespace = null, string $service = null, string $method = null, int $version = null) { self::translator()->addFile(__DIR__ . '/../lang/global', 'swaggerserver'); $this->masterpage = new MasterPage($namespace, $service, $method, $version); if (!is_numeric($version) && $version) { $version = (int) str_replace('/v', '', $version); } if ($namespace) { $route = $method ? 'method' : ($service ? 'service' : 'namespace'); $swagger = new HtmlElement('<a>', '{···}'); $swagger->addAttribute('href', (string) self::uri('swagger/generation/' . $route, ['namespace' => $namespace, 'version' => $version ? $version : $this->maxVersion($namespace), 'service' => $service, 'method' => $method]))->addClass(['btn', 'btn-success']); $this->masterpage->addTitleBadge($swagger); } }
/** * @param int $page * @param string $display * * @return HtmlElement */ private function getLi(int $page, string $display = null) : HtmlElement { $li = new HtmlElement('<li>'); $url = call_user_func($this->argsCallback, $this, $page); if ($page == $this->current) { $li->addClass($display ? 'disabled' : 'active'); } if ($this->current == $page) { $li->setContent('<span href="' . $url . '">' . ($display ?: $page) . '</span>'); } else { $li->setContent('<a href="' . $url . '">' . ($display ?: $page) . '</a>'); } if ($this->current - 1 == $page) { $li->addAttribute('rel', 'prev'); } if ($this->current + 1 == $page) { $li->addAttribute('rel', 'next'); } return $li; }
/** * @return string */ public function render() { $timerEvent = new TimerEvent('router.htmlPage', ['elements' => sizeof($this->elements)]); $out = '<!DOCTYPE html lang="' . self::locale() . '">' . "\n"; // default seo if (!$this->headTitle && ($title = self::trans('seo.default/title'))) { $this->setHeadTitle($title); } if (!$this->headDescription && ($description = self::trans('seo.default/description'))) { $this->setHeadDescription($description); } // add mandatory headers $language = new HtmlElement('<meta />'); $language->addAttributes(['http-equiv' => 'Content-Language', 'content' => self::locale()]); $this->head->addFirst($language); $charset = new HtmlElement('<meta />'); $charset->addAttribute('charset', 'utf-8'); $this->head->addFirst($charset); $content = $this->body->getContent(); if ($content) { $this->body->setContent($content . $this->footer->render()); } $parent = parent::render(); $out .= $parent; $timerEvent->addData(['size' => $this->getContent() ? strlen($this->getContent()) : strlen($parent)]); self::emit($timerEvent); return $out; }
/** * @param array $data */ public function __construct(array $data = []) { $this->element = new HtmlElement('<script>'); $this->element->addAttribute('type', 'application/json'); $this->data = $data; }