ipl\Html: allow to get first content element

This commit is contained in:
Thomas Gelf 2017-07-24 08:40:39 +02:00
parent 74351f2146
commit f06ac06b5b
1 changed files with 21 additions and 2 deletions

View File

@ -32,6 +32,25 @@ class Html implements ValidHtml
return $this;
}
/**
* @param $tag
* @return BaseElement
* @throws ProgrammingError
*/
public function getFirst($tag)
{
foreach ($this->content as $c) {
if ($c instanceof BaseElement && $c->getTag() === $tag) {
return $c;
}
}
throw new ProgrammingError(
'Trying to get first %s, but there is no such',
$tag
);
}
/**
* @param $content
* @return $this
@ -81,7 +100,7 @@ class Html implements ValidHtml
/**
* @param Html|array|string $content
* @return self
* @return $this
*/
public function setContent($content)
{
@ -146,7 +165,7 @@ class Html implements ValidHtml
* @param $tag
* @param null $attributes
* @param null $content
* @return Element
* @return BaseElement
*/
public static function tag($tag, $attributes = null, $content = null)
{