1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace Atk4\Ui\UserAction;
6:
7: use Atk4\Data\Model;
8: use Atk4\Ui\View;
9:
10: /**
11: * Multi entity views like CardDeck can render many items with the same UA, to improve
12: * the performance and reduce the total page size, render the UA executors only once.
13: */
14: class SharedExecutorsContainer extends View
15: {
16: /** @var array<string, SharedExecutor> */
17: public array $sharedExecutors = [];
18:
19: public function getExecutor(Model\UserAction $action): SharedExecutor
20: {
21: $action->getOwner()->assertIsModel(); // @phpstan-ignore-line
22: $this->getOwner()->model->assertIsModel($action->getModel());
23:
24: if (!isset($this->sharedExecutors[$action->shortName])) {
25: $ex = $this->getExecutorFactory()->createExecutor($action, $this);
26: $ex->executeModelAction();
27: $this->sharedExecutors[$action->shortName] = new SharedExecutor($ex);
28: }
29:
30: return $this->sharedExecutors[$action->shortName];
31: }
32: }
33: