| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui; |
| 6: | |
| 7: | /** |
| 8: | * Works same as Callback but will be executed when the current |
| 9: | * pass completes. Agile UI uses two-pass system - first to |
| 10: | * initialize objects, second to render them. If you use this during |
| 11: | * Init, then it will be executed. |
| 12: | */ |
| 13: | class CallbackLater extends Callback |
| 14: | { |
| 15: | /** |
| 16: | * Executes user-specified action before rendering or if App is |
| 17: | * already in rendering state, then before output. |
| 18: | */ |
| 19: | #[\Override] |
| 20: | public function set($fx = null, $fxArgs = null) |
| 21: | { |
| 22: | if ($this->getApp()->isRendering) { |
| 23: | return parent::set($fx, $fxArgs); |
| 24: | } |
| 25: | |
| 26: | $this->getApp()->onHook(App::HOOK_BEFORE_RENDER, function () use ($fx, $fxArgs) { |
| 27: | return parent::set($fx, $fxArgs); |
| 28: | }); |
| 29: | |
| 30: | return null; |
| 31: | } |
| 32: | } |
| 33: |