modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2025-11-12 09:19:35 +04:00
parent 944daa8ea4
commit 9b83f276fe
6 changed files with 20 additions and 14 deletions

View File

@ -162,7 +162,7 @@ abstract class Application {
return $page;
}
function ensurePhase(IPage $page, int $phase, bool $after=false, &$output=null) {
protected function ensurePhase(IPage $page, int $phase, bool $after=false, &$output=null) {
if (!$page->didComponentPhase($phase)) {
if ($page->beforeComponentPhase($phase)) {
page::set_component_phase($phase);

View File

@ -6,10 +6,10 @@ use nulib\web\model\IComponent;
abstract class AbstractComponent implements IComponent {
use TComponentPhase;
const COMPONENT_CAN_PREPARE = false;
const COMPONENT_CAN_CONFIGURE = false;
const COMPONENT_CAN_SETUP = false;
const COMPONENT_CAN_TEARDOWN = false;
const COMPONENT_PHASE_CAN_PREPARE = false;
const COMPONENT_PHASE_CAN_CONFIGURE = false;
const COMPONENT_PHASE_CAN_SETUP = false;
const COMPONENT_PHASE_CAN_TEARDOWN = false;
function RENDERER_CLASS(): ?string {
return static::RENDERER_CLASS;

View File

@ -1,14 +1,16 @@
<?php
namespace nulib\web\base;
use nulib\web\model\IComponent;
use nulib\php\content\c;
use nulib\php\content\IContent;
use nulib\php\content\IPrintable;
use nulib\web\model\IRenderer;
class HtmlRenderer implements IRenderer {
function render($data): void {
header("Content-Type: text/html; charset=utf-8");
if ($data instanceof IComponent) {
$data->print();
if ($data instanceof IPrintable || $data instanceof IContent) {
c::write([$data]);
} else {
echo $data;
}

View File

@ -14,15 +14,15 @@ trait TComponentPhase {
$this->currentComponentPhase = $phase;
switch ($phase) {
case page::PHASE_PREPARE:
if (static::COMPONENT_CAN_PREPARE) $this->prepare();
if (static::COMPONENT_PHASE_CAN_PREPARE) $this->doComponentPhasePrepare();
break;
case page::PHASE_CONFIGURE:
if (static::COMPONENT_CAN_CONFIGURE) $this->configure();
if (static::COMPONENT_PHASE_CAN_CONFIGURE) $this->doComponentPhaseConfigure();
break;
case page::PHASE_SETUP:
if (static::COMPONENT_CAN_SETUP) return $this->setup();
if (static::COMPONENT_PHASE_CAN_SETUP) return $this->doComponentPhaseSetup();
case page::PHASE_TEARDOWN:
if (static::COMPONENT_CAN_TEARDOWN) $this->teardown();
if (static::COMPONENT_PHASE_CAN_TEARDOWN) $this->doComponentPhaseTeardown();
break;
}
return null;

View File

@ -1,7 +1,9 @@
<?php
namespace nulib\web\model;
interface IComponent {
use nulib\php\content\IContent;
interface IComponent extends IContent {
/** retourner la classe de renderer à utiliser pour afficher ce composant */
function RENDERER_CLASS(): ?string;

View File

@ -1,7 +1,9 @@
<?php
namespace nulib\web\model;
interface IPage extends IComponent {
use nulib\php\content\IPrintable;
interface IPage extends IComponent, IPrintable {
/** indiquer si cette page a besoin d'avoir une session valide */
function USE_SESSION(): bool;