html-object-strings/src/Containers/Fragment.php

32 lines
699 B
PHP
Raw Normal View History

2022-11-30 14:55:35 +00:00
<?php
namespace ByJoby\HTML\Containers;
use ByJoby\HTML\NodeInterface;
2022-11-30 14:55:35 +00:00
use ByJoby\HTML\Traits\ContainerTrait;
use Stringable;
use Traversable;
2022-11-30 14:55:35 +00:00
class Fragment implements FragmentInterface
{
use ContainerTrait;
/**
* @param null|array<mixed,string|Stringable|NodeInterface>|Traversable<mixed,string|Stringable|NodeInterface>|null $children
*/
public function __construct(null|array|Traversable $children = null)
{
2022-12-21 18:48:59 +00:00
if (!$children) {
return;
}
foreach ($children as $child) {
$this->addChild($child);
}
}
2022-11-30 14:55:35 +00:00
public function __toString(): string
{
return implode(PHP_EOL, $this->children());
}
}