application runner refactoring

This commit is contained in:
Yuri Kuznetsov
2020-12-17 18:43:57 +02:00
parent d6dec82610
commit 5ffd03ca85
4 changed files with 24 additions and 13 deletions

View File

@@ -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();
}
/**

View File

@@ -34,4 +34,5 @@ namespace Espo\Core\ApplicationRunners;
*/
interface ApplicationRunner
{
public function run();
}

View File

@@ -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();

View File

@@ -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);
}
}