From 5ffd03ca855db64b497d0182170da73be2a4f0e1 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 17 Dec 2020 18:43:57 +0200 Subject: [PATCH] application runner refactoring --- application/Espo/Core/Application.php | 9 ++++++--- .../ApplicationRunners/ApplicationRunner.php | 1 + .../Espo/Core/ApplicationRunners/EntryPoint.php | 17 ++++++++++------- .../Espo/Core/ApplicationRunners/Job.php | 10 +++++++--- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index f40f5d99de..243844d56d 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -43,6 +43,7 @@ use Espo\Core\{ }; use ReflectionClass; +use StdClass; /** * A central access point of the application. @@ -68,7 +69,7 @@ class Application /** * Run a specific application runner. */ - public function run(string $className, ?object $params = null) + public function run(string $className, ?StdClass $params = null) { if (!$className || !class_exists($className)) { $this->getLog()->error("Application runner '{$className}' does not exist."); @@ -88,9 +89,11 @@ class Application $this->setupSystemUser(); } - $runner = $this->getInjectableFactory()->create($className); + $runner = $this->getInjectableFactory()->createWith($className, [ + 'params' => $params, + ]); - $runner->run($params); + $runner->run(); } /** diff --git a/application/Espo/Core/ApplicationRunners/ApplicationRunner.php b/application/Espo/Core/ApplicationRunners/ApplicationRunner.php index 2dd9e125cd..d47c5e7cff 100644 --- a/application/Espo/Core/ApplicationRunners/ApplicationRunner.php +++ b/application/Espo/Core/ApplicationRunners/ApplicationRunner.php @@ -34,4 +34,5 @@ namespace Espo\Core\ApplicationRunners; */ interface ApplicationRunner { + public function run(); } diff --git a/application/Espo/Core/ApplicationRunners/EntryPoint.php b/application/Espo/Core/ApplicationRunners/EntryPoint.php index a04a8d5e29..c2156746d2 100644 --- a/application/Espo/Core/ApplicationRunners/EntryPoint.php +++ b/application/Espo/Core/ApplicationRunners/EntryPoint.php @@ -60,6 +60,8 @@ use Exception; */ class EntryPoint implements ApplicationRunner { + protected $params; + protected $injectableFactory; protected $entryPointManager; protected $entityManager; @@ -73,7 +75,8 @@ class EntryPoint implements ApplicationRunner EntityManager $entityManager, ClientManager $clientManager, ApplicationUser $applicationUser, - AuthTokenManager $authTokenManager + AuthTokenManager $authTokenManager, + ?StdClass $params = null ) { $this->injectableFactory = $injectableFactory; $this->entryPointManager = $entryPointManager; @@ -81,16 +84,16 @@ class EntryPoint implements ApplicationRunner $this->clientManager = $clientManager; $this->applicationUser = $applicationUser; $this->authTokenManager = $authTokenManager; + + $this->params = $params ?? (object) []; } - public function run(?StdClass $params = null) + public function run() { - $params = $params ?? (object) []; + $entryPoint = $this->params->entryPoint ?? $_GET['entryPoint']; - $entryPoint = $params->entryPoint ?? $_GET['entryPoint']; - - $final = $params->final ?? false; - $data = $params->data ?? null; + $final = $this->params->final ?? false; + $data = $this->params->data ?? null; if (!$entryPoint) { throw new Error(); diff --git a/application/Espo/Core/ApplicationRunners/Job.php b/application/Espo/Core/ApplicationRunners/Job.php index 18025a1472..8901446036 100644 --- a/application/Espo/Core/ApplicationRunners/Job.php +++ b/application/Espo/Core/ApplicationRunners/Job.php @@ -43,15 +43,19 @@ class Job implements ApplicationRunner use Cli; use SetupSystemUser; + protected $params; + protected $cronManager; - public function __construct(CronManager $cronManager) + public function __construct(CronManager $cronManager, StdClass $params) { $this->cronManager = $cronManager; + + $this->params = $params; } - public function run(StdClass $params) + public function run() { - $this->cronManager->runJobById($params->id); + $this->cronManager->runJobById($this->params->id); } }