HEX
Server: Apache
System: Linux andromeda.lojoweb.com 4.18.0-372.26.1.el8_6.x86_64 #1 SMP Tue Sep 13 06:07:14 EDT 2022 x86_64
User: nakedfoamlojoweb (1056)
PHP: 8.0.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/cwd/wp-content/plugins/wordpress-seo/src/llms-txt/domain/markdown/llms-txt-renderer.php
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
namespace Yoast\WP\SEO\Llms_Txt\Domain\Markdown;

use Yoast\WP\SEO\Llms_Txt\Domain\Markdown\Sections\Section_Interface;

/**
 * The renderer of the LLMs.txt file.
 */
class Llms_Txt_Renderer {

	/**
	 * The sections.
	 *
	 * @var Section_Interface[]
	 */
	private $sections;

	/**
	 * Adds a section.
	 *
	 * @param Section_Interface $section The section to add.
	 *
	 * @return void
	 */
	public function add_section( Section_Interface $section ): void {
		$this->sections[] = $section;
	}

	/**
	 * Returns the sections.
	 *
	 * @return Section_Interface[]
	 */
	public function get_sections(): array {
		return $this->sections;
	}

	/**
	 * Renders the items of the bucket.
	 *
	 * @return string
	 */
	public function render(): string {
		if ( empty( $this->sections ) ) {
			return '';
		}

		$rendered_sections = [];
		foreach ( $this->sections as $section ) {
			$section_content = $section->render();
			if ( $section_content === '' ) {
				continue;
			}

			$rendered_sections[] = $section->get_prefix() . $section_content . \PHP_EOL;
		}

		return \implode( \PHP_EOL, $rendered_sections );
	}
}