This commit is contained in:
Yuri Kuznetsov
2021-02-07 18:46:19 +02:00
parent a733c6c68d
commit ee4220e1ce
18 changed files with 44 additions and 35 deletions

View File

@@ -60,7 +60,7 @@ class Application
$this->initPreloads();
}
protected function initContainer()
protected function initContainer() : void
{
$this->container = (new ContainerBuilder())->build();
}
@@ -68,7 +68,7 @@ class Application
/**
* Run a specific application runner.
*/
public function run(string $className, ?StdClass $params = null)
public function run(string $className, ?StdClass $params = null) : void
{
if (!$className || !class_exists($className)) {
$this->getLog()->error("Application runner '{$className}' does not exist.");
@@ -147,7 +147,7 @@ class Application
return $this->container->get('config');
}
protected function initAutoloads()
protected function initAutoloads() : void
{
$autoload = $this->getInjectableFactory()->create(Autoload::class);
@@ -157,7 +157,7 @@ class Application
/**
* Initialize services that has the 'preload' parameter.
*/
protected function initPreloads()
protected function initPreloads() : void
{
foreach ($this->getMetadata()->get(['app', 'containerServices']) ?? [] as $name => $defs) {
if ($defs['preload'] ?? false) {
@@ -169,7 +169,7 @@ class Application
/**
* Set a base path of an index file related to the application directory. Used for a portal.
*/
public function setClientBasePath(string $basePath)
public function setClientBasePath(string $basePath) : void
{
$this->getClientManager()->setBasePath($basePath);
}
@@ -177,7 +177,7 @@ class Application
/**
* Setup the system user. The system user is used when no user is logged in.
*/
public function setupSystemUser()
public function setupSystemUser() : void
{
$this->getApplicationUser()->setupSystemUser();
}

View File

@@ -80,7 +80,7 @@ class Api implements ApplicationRunner
$this->log = $log;
}
public function run()
public function run() : void
{
$slim = SlimAppFactory::create();

View File

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

View File

@@ -47,7 +47,7 @@ class ClearCache implements ApplicationRunner
$this->dataManager = $dataManager;
}
public function run()
public function run() : void
{
$this->dataManager->clearCache();
}

View File

@@ -45,7 +45,7 @@ class Client implements ApplicationRunner
$this->clientManager = $clientManager;
}
public function run()
public function run() : void
{
$this->clientManager->display();
}

View File

@@ -49,7 +49,7 @@ class Command implements ApplicationRunner
$this->commandManager = $commandManager;
}
public function run()
public function run() : void
{
ob_start();

View File

@@ -51,10 +51,11 @@ class Cron implements ApplicationRunner
$this->config = $config;
}
public function run()
public function run() : void
{
if ($this->config->get('cronDisabled')) {
$GLOBALS['log']->warning("Cron is not run because it's disabled with 'cronDisabled' param.");
return;
}

View File

@@ -47,7 +47,7 @@ class Daemon implements ApplicationRunner
protected $config;
public function __construct(Config $config)
public function __construct(Config $config) : void
{
$this->config = $config;
}
@@ -59,12 +59,14 @@ class Daemon implements ApplicationRunner
$timeout = $this->config->get('daemonProcessTimeout');
$phpExecutablePath = $this->config->get('phpExecutablePath');
if (!$phpExecutablePath) {
$phpExecutablePath = (new PhpExecutableFinder)->find();
}
if (!$maxProcessNumber || !$interval) {
$GLOBALS['log']->error("Daemon config params are not set.");
return;
}
@@ -73,6 +75,7 @@ class Daemon implements ApplicationRunner
while (true) {
$toSkip = false;
$runningCount = 0;
foreach ($processList as $i => $process) {
if ($process->isRunning()) {
$runningCount++;
@@ -80,16 +83,23 @@ class Daemon implements ApplicationRunner
unset($processList[$i]);
}
}
$processList = array_values($processList);
if ($runningCount >= $maxProcessNumber) {
$toSkip = true;
}
if (!$toSkip) {
$process = new Process([$phpExecutablePath, 'cron.php']);
$process->setTimeout($timeout);
$process->run();
$processList[] = $process;
}
sleep($interval);
}
}

View File

@@ -91,7 +91,7 @@ class EntryPoint implements ApplicationRunner
$this->params = $params ?? (object) [];
}
public function run()
public function run() : void
{
$requestWrapped = new RequestWrapper(
ServerRequestCreatorFactory::create()->createServerRequestFromGlobals(),

View File

@@ -54,7 +54,7 @@ class Job implements ApplicationRunner
$this->params = $params;
}
public function run()
public function run() : void
{
$this->cronManager->runJobById($this->params->id);
}

View File

@@ -69,7 +69,7 @@ class PortalClient implements ApplicationRunner
$this->params = $params ?? (object) [];
}
public function run()
public function run() : void
{
$id = $this->params->id ??
Url::detectPortalId() ??

View File

@@ -44,7 +44,7 @@ class Preload implements ApplicationRunner
{
use Cli;
public function run()
public function run() : void
{
$preload = new PreloadUtil();

View File

@@ -47,7 +47,7 @@ class Rebuild implements ApplicationRunner
$this->dataManager = $dataManager;
}
public function run()
public function run() : void
{
$this->dataManager->rebuild();
}

View File

@@ -85,7 +85,7 @@ class WebSocket implements ApplicationRunner
}
}
public function run()
public function run() : void
{
$loop = EventLoopFactory::create();

View File

@@ -199,7 +199,7 @@ class Container
/**
* Set a service object. Must be configured as settable.
*/
public function set(string $name, object $object)
public function set(string $name, object $object) : void
{
if (!$this->configuration->isSettable($name)) {
throw new Error("Service '{$name}' is not settable.");
@@ -233,7 +233,7 @@ class Container
return $this->loaderClassNames[$name] ?? $this->configuration->getLoaderClassName($name);
}
private function load(string $name)
private function load(string $name) : void
{
$loadMethodName = 'load' . ucfirst($name);

View File

@@ -33,7 +33,6 @@ use Espo\Core\{
Exceptions\Error,
Interfaces\Injectable,
Binding\BindingContainer,
Binding\BindingLoader,
Binding\Binding,
};
@@ -253,8 +252,10 @@ class InjectableFactory
throw new Error("InjectableFactory: Bad binding.");
}
protected function areDependencyClassesMatching(ReflectionClass $paramHintClass, ReflectionClass $returnHintClass) : bool
{
protected function areDependencyClassesMatching(
ReflectionClass $paramHintClass, ReflectionClass $returnHintClass
) : bool {
if ($paramHintClass->getName() === $returnHintClass->getName()) {
return true;
}
@@ -292,8 +293,10 @@ class InjectableFactory
}
}
protected function classHasDependencySetter(ReflectionClass $class, string $name, bool $skipInstanceCheck = false) : bool
{
protected function classHasDependencySetter(
ReflectionClass $class, string $name, bool $skipInstanceCheck = false
) : bool {
$methodName = 'set' . ucfirst($name);
if (!$class->hasMethod($methodName) || !$class->getMethod($methodName)->isPublic()) {

View File

@@ -57,7 +57,7 @@ class Application extends BaseApplication
$this->initPreloads();
}
protected function initContainer()
protected function initContainer() : void
{
$this->container = (new ContainerBuilder())
->withConfigClassName(Config::class)
@@ -66,7 +66,7 @@ class Application extends BaseApplication
->build();
}
protected function initPortal(?string $portalId)
protected function initPortal(?string $portalId) : void
{
if (!$portalId) {
throw new Error("Portal ID was not passed to Portal\Application.");
@@ -95,12 +95,7 @@ class Application extends BaseApplication
$this->container->setPortal($portal);
}
protected function getPortal()
{
return $this->portal;
}
protected function initPreloads()
protected function initPreloads() : void
{
parent::initPreloads();

View File

@@ -49,7 +49,7 @@ class Client implements ApplicationRunner
$this->applicationState = $applicationState;
}
public function run()
public function run() : void
{
$portalId = $this->applicationState->getPortal()->id;