protected function fosterParent(Tag $tag)
	{
		if (!empty($this->openTags))
		{
			$tagName   = $tag->getName();
			$tagConfig = $this->tagsConfig[$tagName];

			if (!empty($tagConfig['rules']['fosterParent']))
			{
				$parent     = end($this->openTags);
				$parentName = $parent->getName();

				if (isset($tagConfig['rules']['fosterParent'][$parentName]))
				{
					if ($parentName !== $tagName && $this->currentFixingCost < $this->maxFixingCost)
					{
						$this->addFosterTag($tag, $parent);
					}

					// Reinsert current tag
					$this->tagStack[] = $tag;

					// And finally close its parent with a priority that ensures it is processed
					// before this tag
					$this->addMagicEndTag($parent, $tag->getPos(), $tag->getSortPriority() - 1);

					// Adjust the fixing cost to account for the additional tags/processing
					$this->currentFixingCost += 4;

					return true;
				}
			}
		}

		return false;
	}
protected function fosterParent(Tag $tag)
	{
		if (!empty($this->openTags))
		{
			$tagName   = $tag->getName();
			$tagConfig = $this->tagsConfig[$tagName];

			if (!empty($tagConfig['rules']['fosterParent']))
			{
				$parent     = end($this->openTags);
				$parentName = $parent->getName();

				if (isset($tagConfig['rules']['fosterParent'][$parentName]))
				{
					if ($parentName !== $tagName && $this->currentFixingCost < $this->maxFixingCost)
					{
						$this->addFosterTag($tag, $parent);
					}

					// Reinsert current tag
					$this->tagStack[] = $tag;

					// And finally close its parent with a priority that ensures it is processed
					// before this tag
					$this->addMagicEndTag($parent, $tag->getPos(), $tag->getSortPriority() - 1);

					// Adjust the fixing cost to account for the additional tags/processing
					$this->currentFixingCost += 4;

					return true;
				}
			}
		}

		return false;
	}
protected function fosterParent ( Tag $ tag ) { if ( ! empty ( $ this -> openTags ) ) { $ tagName = $ tag -> getName ( ) ; $ tagConfig = $ this -> tagsConfig [ $ tagName ] ; if ( ! empty ( $ tagConfig [ 'rules' ] [ 'fosterParent' ] ) ) { $ parent = end ( $ this -> openTags ) ; $ parentName = $ parent -> getName ( ) ; if ( isset ( $ tagConfig [ 'rules' ] [ 'fosterParent' ] [ $ parentName ] ) ) { if ( $ parentName !== $ tagName && $ this -> currentFixingCost < $ this -> maxFixingCost ) { $ this -> addFosterTag ( $ tag , $ parent ) ; } // Reinsert current tag $ this -> tagStack [ ] = $ tag ; // And finally close its parent with a priority that ensures it is processed // before this tag $ this -> addMagicEndTag ( $ parent , $ tag -> getPos ( ) , $ tag -> getSortPriority ( ) - 1 ) ; // Adjust the fixing cost to account for the additional tags/processing $ this -> currentFixingCost += 4 ; return true ; } } } return false ; }
Apply fosterParent rules associated with given tag

NOTE: this rule has the potential for creating an unbounded loop, either if a tag tries to
foster itself or two or more tags try to foster each other in a loop. We mitigate the
risk by preventing a tag from creating a child of itself (the parent still gets closed)
and by checking and increasing the currentFixingCost so that a loop of multiple tags
do not run indefinitely. The default tagLimit and nestingLimit also serve to prevent the
loop from running indefinitely

@param  Tag  $tag Tag
@return bool      Whether a new tag has been added
Apply fosterParent rules associated with given tag