mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
container default loaders
This commit is contained in:
@@ -42,6 +42,10 @@ use Espo\Core\{
|
||||
Utils\Route,
|
||||
Utils\Autoload,
|
||||
Portal\Application as PortalApplication,
|
||||
Loaders\Config as ConfigLoader,
|
||||
Loaders\Log as LogLoader,
|
||||
Loaders\FileManager as FileManagerLoader,
|
||||
Loaders\Metadata as MetadataLoader,
|
||||
};
|
||||
|
||||
class Application
|
||||
@@ -54,6 +58,13 @@ class Application
|
||||
|
||||
private $auth;
|
||||
|
||||
protected $loaderClassNames = [
|
||||
'config' => ConfigLoader::class,
|
||||
'log' => LogLoader::class,
|
||||
'fileManager' => FileManagerLoader::class,
|
||||
'metadata' => MetadataLoader::class,
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
@@ -66,7 +77,7 @@ class Application
|
||||
|
||||
protected function initContainer()
|
||||
{
|
||||
$this->container = new Container(ContainerConfiguration::class);
|
||||
$this->container = new Container(ContainerConfiguration::class, $this->loaderClassNames);
|
||||
}
|
||||
|
||||
// TODO make protected
|
||||
|
||||
@@ -40,10 +40,13 @@ class Container
|
||||
{
|
||||
private $data = [];
|
||||
|
||||
private $loaderClassNames;
|
||||
|
||||
protected $configuration;
|
||||
|
||||
public function __construct(string $configurationClassName)
|
||||
public function __construct(string $configurationClassName, array $loaderClassNames = [])
|
||||
{
|
||||
$this->loaderClassNames = $loaderClassNames;
|
||||
$this->configuration = $this->get('injectableFactory')->create($configurationClassName);
|
||||
}
|
||||
|
||||
@@ -100,7 +103,7 @@ class Container
|
||||
return;
|
||||
}
|
||||
|
||||
$loaderClassName = $this->configuration->getLoaderClassName($name);
|
||||
$loaderClassName = $this->loaderClassNames[$name] ?? $this->configuration->getLoaderClassName($name);
|
||||
|
||||
$object = null;
|
||||
|
||||
@@ -147,40 +150,6 @@ class Container
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadLog()
|
||||
{
|
||||
$config = $this->get('config');
|
||||
|
||||
$path = $config->get('logger.path', 'data/logs/espo.log');
|
||||
$rotation = $config->get('logger.rotation', true);
|
||||
|
||||
$log = new \Espo\Core\Utils\Log('Espo');
|
||||
$levelCode = $log::toMonologLevel($config->get('logger.level', 'WARNING'));
|
||||
|
||||
if ($rotation) {
|
||||
$maxFileNumber = $config->get('logger.maxFileNumber', 30);
|
||||
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\RotatingFileHandler($path, $maxFileNumber, $levelCode);
|
||||
} else {
|
||||
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\StreamHandler($path, $levelCode);
|
||||
}
|
||||
$log->pushHandler($handler);
|
||||
|
||||
$errorHandler = new \Monolog\ErrorHandler($log);
|
||||
$errorHandler->registerExceptionHandler(null, false);
|
||||
$errorHandler->registerErrorHandler([], false);
|
||||
|
||||
$GLOBALS['log'] = $log;
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
protected function loadFileManager()
|
||||
{
|
||||
return new \Espo\Core\Utils\File\Manager(
|
||||
$this->get('config')
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadControllerManager()
|
||||
{
|
||||
return new \Espo\Core\ControllerManager(
|
||||
@@ -195,13 +164,6 @@ class Container
|
||||
return $this->get('entityManager')->getEntity('Preferences', $this->get('user')->id);
|
||||
}
|
||||
|
||||
protected function loadConfig()
|
||||
{
|
||||
return new \Espo\Core\Utils\Config(
|
||||
new \Espo\Core\Utils\File\Manager()
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadHookManager()
|
||||
{
|
||||
return new \Espo\Core\HookManager(
|
||||
@@ -237,14 +199,6 @@ class Container
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadMetadata()
|
||||
{
|
||||
return new \Espo\Core\Utils\Metadata(
|
||||
$this->get('fileManager'),
|
||||
$this->get('config')->get('useCache')
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadSchema()
|
||||
{
|
||||
return new \Espo\Core\Utils\Database\Schema\Schema(
|
||||
|
||||
45
application/Espo/Core/Loaders/Config.php
Normal file
45
application/Espo/Core/Loaders/Config.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
use Espo\Core\Utils\Config as ConfigService;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
|
||||
class Config implements Loader
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
return new ConfigService(new FileManager());
|
||||
}
|
||||
}
|
||||
50
application/Espo/Core/Loaders/FileManager.php
Normal file
50
application/Espo/Core/Loaders/FileManager.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Config,
|
||||
Utils\File\Manager as FileManagerService,
|
||||
};
|
||||
|
||||
class FileManager implements Loader
|
||||
{
|
||||
protected $config;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
return new FileManagerService($this->config);
|
||||
}
|
||||
}
|
||||
79
application/Espo/Core/Loaders/Log.php
Normal file
79
application/Espo/Core/Loaders/Log.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Config,
|
||||
Utils\Log as LogService,
|
||||
};
|
||||
|
||||
use Espo\Core\Utils\Log\Monolog\Handler\{
|
||||
RotatingFileHandler,
|
||||
StreamHandler,
|
||||
};
|
||||
|
||||
use Monolog\ErrorHandler as MonologErrorHandler;
|
||||
|
||||
class Log implements Loader
|
||||
{
|
||||
protected $config;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
$config = $this->config;
|
||||
|
||||
$path = $config->get('logger.path', 'data/logs/espo.log');
|
||||
$rotation = $config->get('logger.rotation', true);
|
||||
|
||||
$log = new LogService('Espo');
|
||||
$levelCode = $log::toMonologLevel($config->get('logger.level', 'WARNING'));
|
||||
|
||||
if ($rotation) {
|
||||
$maxFileNumber = $config->get('logger.maxFileNumber', 30);
|
||||
$handler = new RotatingFileHandler($path, $maxFileNumber, $levelCode);
|
||||
} else {
|
||||
$handler = new StreamHandler($path, $levelCode);
|
||||
}
|
||||
$log->pushHandler($handler);
|
||||
|
||||
$errorHandler = new MonologErrorHandler($log);
|
||||
$errorHandler->registerExceptionHandler(null, false);
|
||||
$errorHandler->registerErrorHandler([], false);
|
||||
|
||||
$GLOBALS['log'] = $log;
|
||||
|
||||
return $log;
|
||||
}
|
||||
}
|
||||
53
application/Espo/Core/Loaders/Metadata.php
Normal file
53
application/Espo/Core/Loaders/Metadata.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
use Espo\Core\{
|
||||
Utils\Metadata as MetadataService,
|
||||
Utils\Config,
|
||||
Utils\File\Manager as FileManager,
|
||||
};
|
||||
|
||||
class Metadata implements Loader
|
||||
{
|
||||
protected $fileManager;
|
||||
protected $config;
|
||||
|
||||
public function __construct(FileManager $fileManager, Config $config)
|
||||
{
|
||||
$this->fileManager = $fileManager;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
return new MetadataService($this->fileManager, $this->config->get('useCache'));
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ class Application extends \Espo\Core\Application
|
||||
|
||||
protected function initContainer()
|
||||
{
|
||||
$this->container = new PortalContainer(PortalContainerConfiguration::class);
|
||||
$this->container = new PortalContainer(PortalContainerConfiguration::class, $this->loaderClassNames);
|
||||
}
|
||||
|
||||
protected function getPortal()
|
||||
|
||||
Reference in New Issue
Block a user