2016-11-27 17:54:03 -05:00
|
|
|
<?php
|
|
|
|
|
|
2016-11-27 17:54:38 -05:00
|
|
|
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';
|
|
|
|
|
|
2016-11-27 17:54:38 -05:00
|
|
|
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
|
|
|
|
|
*/
|
2016-11-27 17:54:38 -05:00
|
|
|
public static function create($attributes = null, $content = null, $tag = null)
|
2016-11-27 17:54:03 -05:00
|
|
|
{
|
2016-11-27 17:54:38 -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
|
|
|
}
|
2016-11-27 17:54:38 -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
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-11-27 17:54:38 -05:00
|
|
|
|
|
|
|
|
}
|