/** * Displays the content. */ public function serve($options = null) { $contentValue = $this->contentValue; $contentType = $this->contentType; $spacingContent = $this->spacingContent; $internalOptions = array_merge($options, array('type' => $contentType)); $lastServeReturnValue = null; // If is ordered-array: if (is_array($contentValue)) { $contentValueArray = (array) $contentValue; $count = count($contentValueArray); $i = 0; foreach ($contentValueArray as $contentValueItem) { $i++; if (isset($contentValueItem) && $contentValueItem !== false) { // Cannot use empty as it discard '0' dumbly. $lastServeReturnValue = Serve::serve($contentValueItem, $internalOptions); if ($i < $count && isset($spacingContent)) { Serve::serve($spacingContent, $internalOptions); } } } // If is string or number: } elseif (is_scalar($contentValue)) { $lastServeReturnValue = Serve::serve($contentValue, $internalOptions); } return $lastServeReturnValue; }
/** * Displays the element with its attributes and content. */ public function serve($options = null) { $serveResult = array(); $isRSS = burntCheck($options['isRSS'], false); $isXML = burntCheck($options['isXML'], $isRSS); $isRootElement = burntCheck($options['isRootElement'], false); if ($isXML && $isRootElement) { echo '<?xml version="1.0"?>' . "\n"; } $tagName = $this->tagName; $attributes = $this->attributes; echo "<{$tagName}"; if (!empty($attributes)) { self::serveAttributesArray($attributes); } $isSelfClosing = burntCheck($options['isSelfClosing'], self::tagIsSelfClosing($tagName, $options)); if ($isXML && $isSelfClosing) { echo ' />'; } else { echo '>'; } $addNewLineAfterOpening = burntCheck($options['addNewLineAfterOpening'], self::tagShouldAddNewLineAfterOpening($tagName, $options)); if ($addNewLineAfterOpening) { echo "\n"; } $innerPreparedItem = $this->innerPreparedItem; $innerServeResult = null; if (isset($innerPreparedItem)) { $childOptions = array_merge((array) $options, array('isRootElement' => false)); $innerServeResult = Serve::serve($innerPreparedItem, $childOptions); } if ($addNewLineAfterOpening && empty($innerServeResult['endedWithNewLine'])) { echo "\n"; } if (!$isSelfClosing) { echo "</{$tagName}>"; } $addNewLineAfterClosing = burntCheck($options['addNewLineAfterClosing'], self::tagShouldAddNewLineAfterClosing($tagName, $options)); if ($addNewLineAfterClosing) { echo "\n"; $serveResult['endedWithNewLine'] = true; } return $serveResult; }