Loading CHANGELOG.md +5 −0 Original line number Diff line number Diff line CHANGELOG ========= 6.2.4 (03/12/2024) ------------------ - Possibilité d'ajouter des callbacks pour suivre en temps réel l'évolution des calculs 6.2.3 (20/08/2024) ------------------ Loading src/Event.php 0 → 100644 +23 −0 Original line number Diff line number Diff line <?php namespace UnicaenTbl; use UnicaenTbl\TableauBord; class Event { const CALCUL = 'calcul'; const GET = 'get'; const PROCESS = 'process'; const SET = 'set'; const FINISH = 'finish'; const PROGRESS = 'progress'; public TableauBord $tableauBord; public string $action; public ?int $progress = null; public ?int $total = null; } No newline at end of file src/Service/TableauBordService.php +30 −32 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace UnicaenTbl\Service; use phpDocumentor\Reflection\Types\Mixed_; use UnicaenTbl\TableauBord; /** Loading @@ -11,8 +12,14 @@ use UnicaenTbl\TableauBord; */ class TableauBordService { /** @var array|TableauBord[] */ protected array $tableauxBord = []; /** * @var callable|null */ private mixed $onAction = null; /** Loading @@ -31,8 +38,10 @@ class TableauBordService } public function getTableauBord(string $name): TableauBord { $this->tableauxBord[$name]->setOnAction($this->getOnAction()); return $this->tableauxBord[$name]; } Loading @@ -49,6 +58,21 @@ class TableauBordService public function getOnAction(): ?callable { return $this->onAction; } public function setOnAction(?callable $onAction): TableauBordService { $this->onAction = $onAction; return $this; } public function calculer(string|TableauBord $tableauBord, array $params = []): self { if (is_string($tableauBord)) { Loading @@ -62,11 +86,7 @@ class TableauBordService /** * @return int * @throws \Doctrine\DBAL\DBALException */ public function calculerTout(array $excludes = [], $beforeTrigger = null, $afterTrigger = null) public function calculerTout(array $excludes = []): bool { $tableauxBord = $this->getTableauxBord(); Loading @@ -75,32 +95,10 @@ class TableauBordService if (in_array($tableauBord->getName(), $excludes)) { continue; } $begin = microtime(true); if ($beforeTrigger instanceof \Closure) { $beforeTrigger([ 'tableau-bord' => $tableauBord->getName(), ]); } try { $tableauBord->setOnAction($this->getOnAction()); $tableauBord->calculer([]); if ($afterTrigger instanceof \Closure) { $afterTrigger([ 'tableau-bord' => $tableauBord->getName(), 'result' => true, 'duree' => microtime(true) - $begin, ]); } } catch (\Exception $e) { if ($afterTrigger instanceof \Closure) { $afterTrigger([ 'tableau-bord' => $tableauBord->getName(), 'result' => false, 'exception' => $e, 'duree' => microtime(true) - $begin, ]); } $result = false; } } Loading src/TableauBord.php +52 −0 Original line number Diff line number Diff line Loading @@ -3,8 +3,10 @@ namespace UnicaenTbl; use Psr\Container\ContainerInterface; use UnicaenTbl\Event; use UnicaenTbl\Process\ProcessInterface; /** * Description of TableauBord * Loading @@ -18,6 +20,15 @@ class TableauBord protected ?ProcessInterface $process = null; private float $timingBegin = 0.0; protected float $timing = 0.0; /** * @var callable|null */ private mixed $onAction = null; /** @var string[] */ protected array $options = []; Loading @@ -40,6 +51,42 @@ class TableauBord public function getOnAction(): ?callable { return $this->onAction; } public function setOnAction(?callable $onAction): TableauBord { $this->onAction = $onAction; return $this; } public function getTiming(): float { return $this->timing; } public function onAction(string $action, ?int $progress = null, ?int $total = null) { if (null !== $this->onAction) { $event = new Event(); $event->tableauBord = $this; $event->action = $action; $event->progress = $progress; $event->total = $total; call_user_func($this->onAction, $event); } } public function getOrder(): int { return $this->order; Loading Loading @@ -131,7 +178,12 @@ class TableauBord public function calculer(array $params = []) { $this->timing = 0.0; $this->timingBegin = microtime(true); $this->onAction(Event::CALCUL); $this->getProcess()->run($this, $params); $this->timing = microtime(true) - $this->timingBegin; $this->onAction(Event::FINISH); } } No newline at end of file Loading
CHANGELOG.md +5 −0 Original line number Diff line number Diff line CHANGELOG ========= 6.2.4 (03/12/2024) ------------------ - Possibilité d'ajouter des callbacks pour suivre en temps réel l'évolution des calculs 6.2.3 (20/08/2024) ------------------ Loading
src/Event.php 0 → 100644 +23 −0 Original line number Diff line number Diff line <?php namespace UnicaenTbl; use UnicaenTbl\TableauBord; class Event { const CALCUL = 'calcul'; const GET = 'get'; const PROCESS = 'process'; const SET = 'set'; const FINISH = 'finish'; const PROGRESS = 'progress'; public TableauBord $tableauBord; public string $action; public ?int $progress = null; public ?int $total = null; } No newline at end of file
src/Service/TableauBordService.php +30 −32 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace UnicaenTbl\Service; use phpDocumentor\Reflection\Types\Mixed_; use UnicaenTbl\TableauBord; /** Loading @@ -11,8 +12,14 @@ use UnicaenTbl\TableauBord; */ class TableauBordService { /** @var array|TableauBord[] */ protected array $tableauxBord = []; /** * @var callable|null */ private mixed $onAction = null; /** Loading @@ -31,8 +38,10 @@ class TableauBordService } public function getTableauBord(string $name): TableauBord { $this->tableauxBord[$name]->setOnAction($this->getOnAction()); return $this->tableauxBord[$name]; } Loading @@ -49,6 +58,21 @@ class TableauBordService public function getOnAction(): ?callable { return $this->onAction; } public function setOnAction(?callable $onAction): TableauBordService { $this->onAction = $onAction; return $this; } public function calculer(string|TableauBord $tableauBord, array $params = []): self { if (is_string($tableauBord)) { Loading @@ -62,11 +86,7 @@ class TableauBordService /** * @return int * @throws \Doctrine\DBAL\DBALException */ public function calculerTout(array $excludes = [], $beforeTrigger = null, $afterTrigger = null) public function calculerTout(array $excludes = []): bool { $tableauxBord = $this->getTableauxBord(); Loading @@ -75,32 +95,10 @@ class TableauBordService if (in_array($tableauBord->getName(), $excludes)) { continue; } $begin = microtime(true); if ($beforeTrigger instanceof \Closure) { $beforeTrigger([ 'tableau-bord' => $tableauBord->getName(), ]); } try { $tableauBord->setOnAction($this->getOnAction()); $tableauBord->calculer([]); if ($afterTrigger instanceof \Closure) { $afterTrigger([ 'tableau-bord' => $tableauBord->getName(), 'result' => true, 'duree' => microtime(true) - $begin, ]); } } catch (\Exception $e) { if ($afterTrigger instanceof \Closure) { $afterTrigger([ 'tableau-bord' => $tableauBord->getName(), 'result' => false, 'exception' => $e, 'duree' => microtime(true) - $begin, ]); } $result = false; } } Loading
src/TableauBord.php +52 −0 Original line number Diff line number Diff line Loading @@ -3,8 +3,10 @@ namespace UnicaenTbl; use Psr\Container\ContainerInterface; use UnicaenTbl\Event; use UnicaenTbl\Process\ProcessInterface; /** * Description of TableauBord * Loading @@ -18,6 +20,15 @@ class TableauBord protected ?ProcessInterface $process = null; private float $timingBegin = 0.0; protected float $timing = 0.0; /** * @var callable|null */ private mixed $onAction = null; /** @var string[] */ protected array $options = []; Loading @@ -40,6 +51,42 @@ class TableauBord public function getOnAction(): ?callable { return $this->onAction; } public function setOnAction(?callable $onAction): TableauBord { $this->onAction = $onAction; return $this; } public function getTiming(): float { return $this->timing; } public function onAction(string $action, ?int $progress = null, ?int $total = null) { if (null !== $this->onAction) { $event = new Event(); $event->tableauBord = $this; $event->action = $action; $event->progress = $progress; $event->total = $total; call_user_func($this->onAction, $event); } } public function getOrder(): int { return $this->order; Loading Loading @@ -131,7 +178,12 @@ class TableauBord public function calculer(array $params = []) { $this->timing = 0.0; $this->timingBegin = microtime(true); $this->onAction(Event::CALCUL); $this->getProcess()->run($this, $params); $this->timing = microtime(true) - $this->timingBegin; $this->onAction(Event::FINISH); } } No newline at end of file