et \. */ private string $head = ''; /** * Texte qui sera compris entre \ et \. */ private string $title = ''; /** * Texte qui sera compris entre \ et \. */ private string $body = ''; /** * Constructeur. * * @param string $title Titre de la page */ public function __construct(string $title = '') { $this->setTitle($title); } /** * Retourner le contenu de $this->head. */ public function getHead(): string { return $this->head; } /** * Retourner le contenu de $this->title. */ public function getTitle(): string { return $this->title; } /** * Affecter le titre de la page. * * @param string $title Le titre */ public function setTitle(string $title): void { $this->title = $title; } /** * Retourner le contenu de $this->body. */ public function getBody(): string { return $this->body; } /** * Ajouter un contenu dans $this->head. * * @param string $content Le contenu à ajouter */ public function appendToHead(string $content): void { $this->head .= $content; } /** * Ajouter un contenu CSS dans $this->head. * * @param string $css Le contenu CSS à ajouter * * @see WebPage::appendToHead(string $content) : void */ public function appendCss(string $css): void { $this->appendToHead( << {$css} HTML ); } /** * Ajouter l'URL d'un script CSS dans $this->head. * * @param string $url L'URL du script CSS * * @see WebPage::appendToHead(string $content) : void */ public function appendCssUrl(string $url): void { $this->appendToHead( << HTML ); } /** * Ajouter un contenu JavaScript dans $this->head. * * @param string $js Le contenu JavaScript à ajouter * * @see WebPage::appendToHead(string $content) : void */ public function appendJs(string $js): void { $this->appendToHead( << {$js} HTML ); } /** * Ajouter l'URL d'un script JavaScript dans $this->head. * * @param string $url L'URL du script JavaScript * * @see WebPage::appendToHead(string $content) : void */ public function appendJsUrl(string $url): void { $this->appendToHead( << HTML ); } /** * Ajouter un contenu dans $this->body. * * @param string $content Le contenu à ajouter */ public function appendContent(string $content): void { $this->body .= $content; } /** * Produire la page Web complète. */ public function toHTML(): string { $lastModification = self::getLastModification(); return << {$this->getTitle()} {$this->getHead()} {$this->getBody()}
Dernière modification : {$lastModification}
HTML; } /** * Donner la date et l'heure de la dernière modification du script principal. * * @see https://www.php.net/manual/fr/function.getlastmod.php * @see https://www.php.net/manual/fr/class.datetime.php * @see https://www.php.net/manual/fr/datetime.format.php */ public static function getLastModification(): string { $date = new \DateTime(); $date->setTimestamp(getlastmod()); return $date->format('d/m/Y - H:i:s'); } }