icingaweb2-module-businessp.../library/Businessprocess/Html/Container.php

88 lines
1.7 KiB
PHP
Raw Normal View History

2016-11-27 17:54:03 -05:00
<?php
namespace Icinga\Module\Businessprocess\Html;
2016-11-27 17:54:03 -05:00
class Container extends BaseElement
{
/** @var string */
protected $contentSeparator = "\n";
/** @var string */
protected $tag = 'div';
protected function __construct()
{
}
2016-11-27 17:54:03 -05:00
/**
* @param Renderable|array|string $content
* @param Attributes|array $attributes
* @param string $tag
*
* @return static
*/
public static function create($attributes = null, $content = null, $tag = null)
2016-11-27 17:54:03 -05:00
{
$container = new static();
if ($content !== null) {
$container->setContent($content);
}
if ($attributes !== null) {
$container->setAttributes($attributes);
}
if ($tag !== null) {
$container->setTag($tag);
}
return $container;
2016-11-27 17:54:03 -05:00
}
}
class Old {
2016-11-27 17:54:03 -05:00
/**
* @inheritdoc
*/
public function render()
{
return $this->renderContainerFor(parent::render());
}
/**
* @inheritdoc
*/
public function renderError($error)
{
// TODO: eventually add class="error"
return $this->renderContainerFor(
parent::renderError($error)
);
}
/**
* @param bool $render
* @return $this
*/
public function renderIfEmpty($render = true)
{
$this->renderIfEmpty = $render;
return $this;
}
/**
* @param string $content
* @return string
*/
protected function renderContainerFor($content)
{
return sprintf(
'<%s%s>%s</%s>',
$this->tag,
$this->attributes->render(),
$content,
$this->tag
);
}
}