| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded |
| 4 |
namespace Yoast\WP\SEO\Llms_Txt\Domain\Markdown\Sections; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Llms_Txt\Application\Markdown_Escaper; |
| 7 |
|
| 8 |
/** |
| 9 |
* Represents the title section. |
| 10 |
*/ |
| 11 |
class Title implements Section_Interface { |
| 12 |
|
| 13 |
/** |
| 14 |
* The site title. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
private $site_title; |
| 19 |
|
| 20 |
/** |
| 21 |
* The site tagline. |
| 22 |
* |
| 23 |
* @var string |
| 24 |
*/ |
| 25 |
private $site_tagline; |
| 26 |
|
| 27 |
/** |
| 28 |
* Class constructor. |
| 29 |
* |
| 30 |
* @param string $site_title The site title. |
| 31 |
* @param string $site_tagline The site tagline. |
| 32 |
*/ |
| 33 |
public function __construct( |
| 34 |
string $site_title, |
| 35 |
string $site_tagline |
| 36 |
) { |
| 37 |
$this->site_title = $site_title; |
| 38 |
$this->site_tagline = $site_tagline; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Returns the prefix of the section. |
| 43 |
* |
| 44 |
* @return string |
| 45 |
*/ |
| 46 |
public function get_prefix(): string { |
| 47 |
return '# '; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Renders the title section. |
| 52 |
* |
| 53 |
* @return string |
| 54 |
*/ |
| 55 |
public function render(): string { |
| 56 |
if ( $this->site_tagline === '' ) { |
| 57 |
return $this->site_title; |
| 58 |
} |
| 59 |
|
| 60 |
if ( $this->site_title === '' ) { |
| 61 |
return $this->site_tagline; |
| 62 |
} |
| 63 |
|
| 64 |
return "$this->site_title: $this->site_tagline"; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Escapes the markdown content. |
| 69 |
* |
| 70 |
* @param Markdown_Escaper $markdown_escaper The markdown escaper. |
| 71 |
* |
| 72 |
* @return void |
| 73 |
*/ |
| 74 |
public function escape_markdown( Markdown_Escaper $markdown_escaper ): void { |
| 75 |
$this->site_title = $markdown_escaper->escape_markdown_content( $this->site_title ); |
| 76 |
$this->site_tagline = $markdown_escaper->escape_markdown_content( $this->site_tagline ); |
| 77 |
} |
| 78 |
} |
| 79 |
|