From df7c77a0f686de11f1e63b564f51675bdcba5471 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sat, 5 May 2018 18:29:17 +0200 Subject: [PATCH] ipl-related fixes --- .../Table/IcingaServiceSetServiceTable.php | 6 +- .../Director/Web/Widget/ActivityLogInfo.php | 6 +- library/vendor/ipl/Html/BaseHtmlElement.php | 15 +++ library/vendor/ipl/Html/Container.php | 3 + library/vendor/ipl/Html/Html.php | 22 ++--- library/vendor/ipl/Html/HtmlDocument.php | 11 ++- library/vendor/ipl/Html/HtmlTag.php | 8 +- library/vendor/ipl/Html/Table.php | 94 +++++++++++++++---- .../ipl/Web/Table/ZfQueryBasedTable.php | 3 +- .../vendor/ipl/Web/Widget/AbstractList.php | 4 +- library/vendor/ipl/Web/Widget/Content.php | 8 +- library/vendor/ipl/Web/Widget/Controls.php | 7 +- library/vendor/ipl/Web/Widget/ListItem.php | 6 +- 13 files changed, 136 insertions(+), 57 deletions(-) diff --git a/library/Director/Web/Table/IcingaServiceSetServiceTable.php b/library/Director/Web/Table/IcingaServiceSetServiceTable.php index f789a891..d47c7918 100644 --- a/library/Director/Web/Table/IcingaServiceSetServiceTable.php +++ b/library/Director/Web/Table/IcingaServiceSetServiceTable.php @@ -4,7 +4,7 @@ namespace Icinga\Module\Director\Web\Table; use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Objects\IcingaServiceSet; -use dipl\Html\Element; +use dipl\Html\HtmlElement; use dipl\Html\Link; use dipl\Web\Table\ZfQueryBasedTable; @@ -67,7 +67,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable return $this; } - protected function addHeaderColumnsTo(Element $parent) + protected function addHeaderColumnsTo(HtmlElement $parent) { if ($this->host || $this->affectedHost) { $this->addHostHeaderTo($parent); @@ -125,7 +125,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable return $this->title ?: $this->translate('Servicename'); } - protected function addHostHeaderTo(Element $parent) + protected function addHostHeaderTo(HtmlElement $parent) { if (! $this->host) { $deleteLink = ''; diff --git a/library/Director/Web/Widget/ActivityLogInfo.php b/library/Director/Web/Widget/ActivityLogInfo.php index bcb1f225..37178cf5 100644 --- a/library/Director/Web/Widget/ActivityLogInfo.php +++ b/library/Director/Web/Widget/ActivityLogInfo.php @@ -2,13 +2,13 @@ namespace Icinga\Module\Director\Web\Widget; +use dipl\Html\HtmlElement; use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\ConfigDiff; use Icinga\Module\Director\Db; use Icinga\Module\Director\Forms\RestoreObjectForm; use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\Objects\IcingaObject; -use dipl\Html\Container; use dipl\Html\Html; use dipl\Html\Icon; use dipl\Html\Link; @@ -66,13 +66,13 @@ class ActivityLogInfo extends Html /** * @param Url $url - * @return Container + * @return HtmlElement */ public function getPagination(Url $url) { /** @var Url $url */ $url = $url->without('checksum')->without('show'); - $div = Container::create([ + $div = Html::tag('div', [ 'class' => 'pagination-control', 'style' => 'float: right; width: 5em' ]); diff --git a/library/vendor/ipl/Html/BaseHtmlElement.php b/library/vendor/ipl/Html/BaseHtmlElement.php index 071dc7be..f3831beb 100644 --- a/library/vendor/ipl/Html/BaseHtmlElement.php +++ b/library/vendor/ipl/Html/BaseHtmlElement.php @@ -54,6 +54,7 @@ abstract class BaseHtmlElement extends HtmlDocument /** * @param Attributes|array|null $attributes * @return $this + * @throws \Icinga\Exception\IcingaException */ public function setAttributes($attributes) { @@ -61,6 +62,12 @@ abstract class BaseHtmlElement extends HtmlDocument return $this; } + /** + * @param $key + * @param $value + * @return $this + * @throws \Icinga\Exception\ProgrammingError + */ public function setAttribute($key, $value) { $this->getAttributes()->set($key, $value); @@ -70,6 +77,7 @@ abstract class BaseHtmlElement extends HtmlDocument /** * @param Attributes|array|null $attributes * @return $this + * @throws \Icinga\Exception\ProgrammingError */ public function addAttributes($attributes) { @@ -77,6 +85,9 @@ abstract class BaseHtmlElement extends HtmlDocument return $this; } + /** + * @return array + */ public function getDefaultAttributes() { return $this->defaultAttributes; @@ -102,6 +113,10 @@ abstract class BaseHtmlElement extends HtmlDocument { } + /** + * @param array|ValidHtml|string $content + * @return $this + */ public function add($content) { if (! $this->hasBeenAssembled) { diff --git a/library/vendor/ipl/Html/Container.php b/library/vendor/ipl/Html/Container.php index 3572414a..511d1ecf 100644 --- a/library/vendor/ipl/Html/Container.php +++ b/library/vendor/ipl/Html/Container.php @@ -2,6 +2,9 @@ namespace dipl\Html; +/** + * @deprecated + */ class Container extends BaseHtmlElement { /** @var string */ diff --git a/library/vendor/ipl/Html/Html.php b/library/vendor/ipl/Html/Html.php index 5a043b01..104ed92a 100644 --- a/library/vendor/ipl/Html/Html.php +++ b/library/vendor/ipl/Html/Html.php @@ -5,10 +5,7 @@ namespace dipl\Html; use Exception; use Icinga\Exception\IcingaException; -/** - * TODO: This should no longer extend HtmlDocument - */ -class Html extends HtmlDocument +class Html { /** Charset to be used - we only support UTF-8 */ const CHARSET = 'UTF-8'; @@ -210,30 +207,23 @@ class Html extends HtmlDocument return self::$htmlEscapeFlags; } - /** - * @deprecated - */ + /* + // @deprecated public static function element($name, $attributes = null) { return Html::tag($name, $attributes); } - /** - * @deprecated - * @see Html::add() - */ + // @deprecated public function addContent($content) { return $this->add($content); } - /** - * @deprecated - * - * @return bool - */ + // @deprecated public function hasContent() { return ! $this->isEmpty(); } + */ } diff --git a/library/vendor/ipl/Html/HtmlDocument.php b/library/vendor/ipl/Html/HtmlDocument.php index 647055c3..9c3421c9 100644 --- a/library/vendor/ipl/Html/HtmlDocument.php +++ b/library/vendor/ipl/Html/HtmlDocument.php @@ -20,9 +20,12 @@ class HtmlDocument implements ValidHtml, Countable /** @var array */ private $contentIndex = []; + protected $hasBeenAssembled = false; + /** * @param ValidHtml|array|string $content * @return $this + * @throws \Icinga\Exception\IcingaException */ public function add($content) { @@ -75,6 +78,7 @@ class HtmlDocument implements ValidHtml, Countable /** * @param $content * @return $this + * @throws \Icinga\Exception\IcingaException */ public function prepend($content) { @@ -108,6 +112,7 @@ class HtmlDocument implements ValidHtml, Countable /** * @param $string * @return HtmlDocument + * @throws \Icinga\Exception\IcingaException */ public function addPrintf($string) { @@ -122,6 +127,7 @@ class HtmlDocument implements ValidHtml, Countable /** * @param HtmlDocument|array|string $content * @return $this + * @throws \Icinga\Exception\IcingaException */ public function setContent($content) { @@ -151,7 +157,10 @@ class HtmlDocument implements ValidHtml, Countable public function render() { $html = []; - $this->assemble(); + if (! $this->hasBeenAssembled) { + $this->hasBeenAssembled = true; + $this->assemble(); + } foreach ($this->content as $element) { if (is_string($element)) { diff --git a/library/vendor/ipl/Html/HtmlTag.php b/library/vendor/ipl/Html/HtmlTag.php index de857183..2cc53707 100644 --- a/library/vendor/ipl/Html/HtmlTag.php +++ b/library/vendor/ipl/Html/HtmlTag.php @@ -11,21 +11,21 @@ abstract class HtmlTag * @param $content * @param Attributes|array $attributes * - * @return Element + * @return HtmlElement */ public static function h1($content, $attributes = null) { - return Element::create('h1', $attributes)->setContent($content); + return HtmlElement::create('h1', $attributes)->setContent($content); } /** * @param $content * @param Attributes|array $attributes * - * @return Element + * @return HtmlElement */ public static function p($content, $attributes = null) { - return Element::create('p', $attributes)->setContent($content); + return HtmlElement::create('p', $attributes)->setContent($content); } } diff --git a/library/vendor/ipl/Html/Table.php b/library/vendor/ipl/Html/Table.php index a86a961b..6b7e0619 100644 --- a/library/vendor/ipl/Html/Table.php +++ b/library/vendor/ipl/Html/Table.php @@ -11,16 +11,16 @@ class Table extends BaseHtmlElement /** @var string */ protected $tag = 'table'; - /** @var Element */ + /** @var HtmlElement */ private $caption; - /** @var Element */ + /** @var HtmlElement */ private $header; - /** @var Element */ + /** @var HtmlElement */ private $body; - /** @var Element */ + /** @var HtmlElement */ private $footer; /** @var array */ @@ -49,7 +49,7 @@ class Table extends BaseHtmlElement */ public function setCaption($content) { - $this->caption = Element::create('caption')->addContent( + $this->caption = Html::tag('caption')->add( $content ); @@ -61,11 +61,11 @@ class Table extends BaseHtmlElement * * @param Attributes|array $attributes * @param Html|array|string $content - * @return Element + * @return HtmlElement */ public static function tr($content = null, $attributes = null) { - return Element::create('tr', $attributes, $content); + return Html::tag('tr', $attributes, $content); } /** @@ -73,11 +73,11 @@ class Table extends BaseHtmlElement * * @param Attributes|array $attributes * @param Html|array|string $content - * @return Element + * @return HtmlElement */ public static function th($content = null, $attributes = null) { - return Element::create('th', $attributes, $content); + return HtmlElement::create('th', $attributes, $content); } /** @@ -85,13 +85,20 @@ class Table extends BaseHtmlElement * * @param Attributes|array $attributes * @param Html|array|string $content - * @return Element + * @return HtmlElement */ public static function td($content = null, $attributes = null) { - return Element::create('td', $attributes, $content); + return HtmlElement::create('td', $attributes, $content); } + /** + * @param $row + * @param null $attributes + * @param string $tag + * @return HtmlElement + * @throws \Icinga\Exception\IcingaException + */ public static function row($row, $attributes = null, $tag = 'td') { $tr = static::tr(); @@ -106,6 +113,10 @@ class Table extends BaseHtmlElement return $tr; } + /** + * @return HtmlElement + * @throws \Icinga\Exception\IcingaException + */ public function generateHeader() { return $this->nextHeader()->add( @@ -113,14 +124,23 @@ class Table extends BaseHtmlElement ); } + /** + * @return HtmlElement + * @throws \Icinga\Exception\IcingaException + */ public function generateFooter() { - return Element::create('tfoot')->add( + return HtmlElement::create('tfoot')->add( $this->addHeaderColumnsTo(static::tr()) ); } - protected function addHeaderColumnsTo(Element $parent) + /** + * @param HtmlElement $parent + * @return HtmlElement + * @throws \Icinga\Exception\IcingaException + */ + protected function addHeaderColumnsTo(HtmlElement $parent) { foreach ($this->getColumnsToBeRendered() as $column) { $parent->add( @@ -139,15 +159,25 @@ class Table extends BaseHtmlElement return $this->columnsToBeRendered; } + /** + * @param array $columns + * @return $this + */ public function setColumnsToBeRendered(array $columns) { $this->columnsToBeRendered = $columns; + return $this; } + /** + * @param $row + * @return HtmlElement + * @throws \Icinga\Exception\IcingaException + */ public function renderRow($row) { - $tr = $this->addRowClasses(Element::create('tr'), $row); + $tr = $this->addRowClasses(Html::tag('tr'), $row); $columns = $this->getColumnsToBeRendered(); if ($columns === null) { @@ -166,7 +196,13 @@ class Table extends BaseHtmlElement return $tr; } - public function addRowClasses(Element $tr, $row) + /** + * @param HtmlElement $tr + * @param $row + * @return HtmlElement + * @throws \Icinga\Exception\ProgrammingError + */ + public function addRowClasses(HtmlElement $tr, $row) { $classes = $this->getRowClasses($row); if (! empty($classes)) { @@ -176,6 +212,11 @@ class Table extends BaseHtmlElement return $tr; } + /** + * @param Traversable $rows + * @return HtmlDocument|HtmlElement + * @throws \Icinga\Exception\IcingaException + */ public function renderRows(Traversable $rows) { $body = $this->body(); @@ -186,24 +227,34 @@ class Table extends BaseHtmlElement return $body; } + /** + * @return HtmlElement + */ public function body() { if ($this->body === null) { - $this->body = Element::create('tbody')->setSeparator("\n"); + $this->body = Html::tag('tbody')->setSeparator("\n"); } return $this->body; } + /** + * @return HtmlElement + */ public function header() { if ($this->header === null) { - $this->header = Element::create('thead')->setSeparator("\n"); + $this->header = Html::tag('thead')->setSeparator("\n"); } return $this->header; } + /** + * @return HtmlElement + * @throws \Icinga\Exception\IcingaException + */ public function footer() { if ($this->footer === null) { @@ -213,6 +264,9 @@ class Table extends BaseHtmlElement return $this->footer; } + /** + * @return HtmlElement + */ public function nextBody() { if ($this->body !== null) { @@ -223,6 +277,9 @@ class Table extends BaseHtmlElement return $this->body(); } + /** + * @return HtmlElement + */ public function nextHeader() { if ($this->header !== null) { @@ -233,6 +290,9 @@ class Table extends BaseHtmlElement return $this->header(); } + /** + * @return string + */ public function renderContent() { if (null !== $this->caption) { diff --git a/library/vendor/ipl/Web/Table/ZfQueryBasedTable.php b/library/vendor/ipl/Web/Table/ZfQueryBasedTable.php index 5840984c..f0b8008c 100644 --- a/library/vendor/ipl/Web/Table/ZfQueryBasedTable.php +++ b/library/vendor/ipl/Web/Table/ZfQueryBasedTable.php @@ -7,7 +7,6 @@ use Icinga\Data\Filter\Filter; use Icinga\Exception\ProgrammingError; use dipl\Db\Zf1\FilterRenderer; use dipl\Db\Zf1\SelectPaginationAdapter; -use dipl\Html\Container; use dipl\Html\DeferredText; use dipl\Html\Html; use dipl\Html\Link; @@ -119,7 +118,7 @@ abstract class ZfQueryBasedTable extends QueryBasedTable public function dumpSqlQuery(Url $url) { $self = $this; - return Container::create(['class' => 'sql-dump'], [ + return Html::tag('div', ['class' => 'sql-dump'], [ Link::create('[ close ]', $url->without('format')), Html::tag('h3', null, $this->translate('SQL Query')), Html::tag('pre', null, new DeferredText( diff --git a/library/vendor/ipl/Web/Widget/AbstractList.php b/library/vendor/ipl/Web/Widget/AbstractList.php index ab1a55ac..466220c4 100644 --- a/library/vendor/ipl/Web/Widget/AbstractList.php +++ b/library/vendor/ipl/Web/Widget/AbstractList.php @@ -4,8 +4,8 @@ namespace dipl\Web\Widget; use dipl\Html\Attributes; use dipl\Html\BaseHtmlElement; -use dipl\Html\Element; use dipl\Html\Html; +use dipl\Html\HtmlElement; class AbstractList extends BaseHtmlElement { @@ -35,6 +35,6 @@ class AbstractList extends BaseHtmlElement */ public function addItem($content, $attributes = null) { - return $this->add(Element::create('li', $attributes, $content)); + return $this->add(HtmlElement::create('li', $attributes, $content)); } } diff --git a/library/vendor/ipl/Web/Widget/Content.php b/library/vendor/ipl/Web/Widget/Content.php index 6f7773c4..cebc70fd 100644 --- a/library/vendor/ipl/Web/Widget/Content.php +++ b/library/vendor/ipl/Web/Widget/Content.php @@ -2,11 +2,13 @@ namespace dipl\Web\Widget; -use dipl\Html\Container; +use dipl\Html\BaseHtmlElement; -class Content extends Container +class Content extends BaseHtmlElement { + protected $tag = 'div'; + protected $contentSeparator = "\n"; - protected $defaultAttributes = array('class' => 'content'); + protected $defaultAttributes = ['class' => 'content']; } diff --git a/library/vendor/ipl/Web/Widget/Controls.php b/library/vendor/ipl/Web/Widget/Controls.php index 9809616d..9353ffae 100644 --- a/library/vendor/ipl/Web/Widget/Controls.php +++ b/library/vendor/ipl/Web/Widget/Controls.php @@ -3,15 +3,16 @@ namespace dipl\Web\Widget; use dipl\Html\BaseHtmlElement; -use dipl\Html\Container; use dipl\Html\Html; use dipl\Html\HtmlDocument; -class Controls extends Container +class Controls extends BaseHtmlElement { + protected $tag = 'div'; + protected $contentSeparator = "\n"; - protected $defaultAttributes = array('class' => 'controls'); + protected $defaultAttributes = ['class' => 'controls']; /** @var Tabs */ private $tabs; diff --git a/library/vendor/ipl/Web/Widget/ListItem.php b/library/vendor/ipl/Web/Widget/ListItem.php index b1d39e45..bf779932 100644 --- a/library/vendor/ipl/Web/Widget/ListItem.php +++ b/library/vendor/ipl/Web/Widget/ListItem.php @@ -4,15 +4,15 @@ namespace dipl\Web\Widget; use dipl\Html\Attributes; use dipl\Html\BaseHtmlElement; -use dipl\Html\Element; use dipl\Html\Html; +use dipl\Html\ValidHtml; class ListItem extends BaseHtmlElement { protected $contentSeparator = "\n"; /** - * @param Html|array|string $content + * @param ValidHtml|array|string $content * @param Attributes|array $attributes * * @return $this @@ -20,7 +20,7 @@ class ListItem extends BaseHtmlElement public function addItem($content, $attributes = null) { return $this->add( - Element::create('li', $content, $attributes) + Html::tag('li', $attributes, $content) ); } }