> */ private $objects; /** * @var ?string */ protected $currentAction; /** * @var array */ protected $params; /** * @param string $managerName * @param \Espo\Core\Container $container * @param array $params */ public function __construct($managerName, $container, $params) { $this->managerName = $managerName; $this->container = $container; $params['name'] = $managerName; $this->params = $params; } /** * @return string */ protected function getManagerName() { return $this->managerName; } /** * @return \Espo\Core\Container */ protected function getContainer() { return $this->container; } /** * @param string $action * @return void */ public function setAction($action) { $this->currentAction = $action; } /** * @return string */ public function getAction() { assert($this->currentAction !== null); return $this->currentAction; } /** * @return array */ public function getParams() { return $this->params; } /** * @param mixed $data * @return mixed * @throws Error */ public function run($data) { $object = $this->getObject(); return $object->run($data); } /** * @param string $actionName * @return \Espo\Core\Upgrades\Actions\Base * @throws Error */ public function getActionClass($actionName) { return $this->getObject($actionName); } /** * @return array * @throws Error */ public function getManifest() { return $this->getObject()->getManifest(); } /** * @param ?string $actionName * @return \Espo\Core\Upgrades\Actions\Base * @throws Error */ protected function getObject($actionName = null) { $managerName = $this->getManagerName(); if (!$actionName) { $actionName = $this->getAction(); } if (!isset($this->objects[$managerName][$actionName])) { $class = '\Espo\Core\Upgrades\Actions\\' . ucfirst($managerName) . '\\' . ucfirst($actionName); if (!class_exists($class)) { throw new Error('Could not find an action ['.ucfirst($actionName).'], class ['.$class.'].'); } /** @var class-string<\Espo\Core\Upgrades\Actions\Base> $class */ $this->objects[$managerName][$actionName] = new $class($this->container, $this); } return $this->objects[$managerName][$actionName]; } }