diff --git a/application/Espo/Core/Loaders/EntityManagerHelper.php b/application/Espo/Core/Di/FileManagerAware.php similarity index 86% rename from application/Espo/Core/Loaders/EntityManagerHelper.php rename to application/Espo/Core/Di/FileManagerAware.php index e6c3bfc7af..4fb86fa401 100644 --- a/application/Espo/Core/Loaders/EntityManagerHelper.php +++ b/application/Espo/Core/Di/FileManagerAware.php @@ -27,14 +27,11 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Core\Loaders; +namespace Espo\Core\Di; -class EntityManagerHelper extends Base +use Espo\Core\Utils\File\Manager as FileManager; + +interface FileManagerAware { - public function load() - { - return new \Espo\Core\ORM\Helper( - $this->getContainer()->get('config') - ); - } + public function setFileManager(FileManager $fileManager); } diff --git a/application/Espo/Core/Loaders/WebSocketSubmission.php b/application/Espo/Core/Di/FileManagerSetter.php similarity index 85% rename from application/Espo/Core/Loaders/WebSocketSubmission.php rename to application/Espo/Core/Di/FileManagerSetter.php index 65b014ba7c..84fc9d181f 100644 --- a/application/Espo/Core/Loaders/WebSocketSubmission.php +++ b/application/Espo/Core/Di/FileManagerSetter.php @@ -27,14 +27,16 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Core\Loaders; +namespace Espo\Core\Di; -class WebSocketSubmission extends Base +use Espo\Core\Utils\File\Manager as FileManager; + +trait FileManagerSetter { - public function load() + protected $fileManager; + + public function setFileManager(FileManager $fileManager) { - return new \Espo\Core\WebSocket\Submission( - $this->getContainer()->get('config') - ); + $this->fileManager = $fileManager; } } diff --git a/application/Espo/Core/ExternalAccount/ClientManager.php b/application/Espo/Core/ExternalAccount/ClientManager.php index 1f73db94b7..eb3a6daccf 100644 --- a/application/Espo/Core/ExternalAccount/ClientManager.php +++ b/application/Espo/Core/ExternalAccount/ClientManager.php @@ -33,21 +33,28 @@ use Espo\Core\Exceptions\Error; use Espo\Core\Exceptions\Forbidden; use Espo\Core\Exceptions\NotFound; -use Espo\Core\InjectableFactory; +use Espo\Core\{ + ORM\EntityManager, + Utils\Metadata, + Utils\Config, + InjectableFactory, +}; class ClientManager { protected $entityManager; - protected $metadata; + protected $config; + protected $injectableFactory = null; protected $clientMap = []; - protected $injectableFactory = null; - public function __construct( - $entityManager, $metadata, $config, ?InjectableFactory $injectableFactory = null) - { + EntityManager $entityManager, + Metadata $metadata, + Config $config, + ?InjectableFactory $injectableFactory = null + ) { $this->entityManager = $entityManager; $this->metadata = $metadata; $this->config = $config; diff --git a/application/Espo/Core/Formula/Evaluator.php b/application/Espo/Core/Formula/Evaluator.php index a34455d6d0..cb677c039b 100644 --- a/application/Espo/Core/Formula/Evaluator.php +++ b/application/Espo/Core/Formula/Evaluator.php @@ -33,6 +33,8 @@ use Espo\Core\Exceptions\Error; use Espo\Core\InjectableFactory; +use Espo\Core\ORM\Entity; + class Evaluator { private $functionFactory = null; @@ -55,7 +57,7 @@ class Evaluator $this->parsedHash = []; } - public function process($expression, $entity = null, $variables = null) + public function process(string $expression, ?Entity $entity = null, ?object $variables = null) { if (!array_key_exists($expression, $this->parsedHash)) { $item = $this->parser->parse($expression); diff --git a/application/Espo/Core/Formula/Manager.php b/application/Espo/Core/Formula/Manager.php index b72a9c6a4e..ee6b81e6eb 100644 --- a/application/Espo/Core/Formula/Manager.php +++ b/application/Espo/Core/Formula/Manager.php @@ -34,8 +34,13 @@ use Espo\Core\Exceptions\Error; use Espo\Core\InjectableFactory; use Espo\Core\Utils\Metadata; +use Espo\Core\ORM\Entity; + class Manager { + protected $injectableFactory; + protected $metadata; + public function __construct(InjectableFactory $injectableFactory, Metadata $metadata) { $functionClassNameMap = $metadata->get(['app', 'formula', 'functionClassNameMap'], []); @@ -43,7 +48,7 @@ class Manager $this->evaluator = new Evaluator($injectableFactory, $functionClassNameMap); } - public function run($script, $entity = null, $variables = null) + public function run(string $script, ?Entity $entity = null, ?object $variables = null) { return $this->evaluator->process($script, $entity, $variables); } diff --git a/application/Espo/Core/Loaders/EntityManager.php b/application/Espo/Core/Loaders/EntityManager.php index 1c4b8eb3df..3e343e1e00 100644 --- a/application/Espo/Core/Loaders/EntityManager.php +++ b/application/Espo/Core/Loaders/EntityManager.php @@ -36,6 +36,7 @@ use Espo\Core\{ ORM\EntityManager as EntityManagerService, ORM\RepositoryFactory, ORM\EntityFactory, + ORM\Helper, }; class EntityManager implements Loader @@ -59,6 +60,8 @@ class EntityManager implements Loader 'entityFactory' => $entityFactory, ]); + $helper = $this->injectableFactory->create(Helper::class); + $config = $this->config; $params = [ @@ -82,6 +85,7 @@ class EntityManager implements Loader 'params' => $params, 'repositoryFactory' => $repositoryFactory, 'entityFactory' => $entityFactory, + 'helper' => $helper, ]); return $entityManager; diff --git a/application/Espo/Core/Loaders/ExternalAccountClientManager.php b/application/Espo/Core/Loaders/ExternalAccountClientManager.php deleted file mode 100644 index 78f4d64fd6..0000000000 --- a/application/Espo/Core/Loaders/ExternalAccountClientManager.php +++ /dev/null @@ -1,42 +0,0 @@ -getContainer()->get('entityManager'), - $this->getContainer()->get('metadata'), - $this->getContainer()->get('config') - ); - } -} diff --git a/application/Espo/Core/Loaders/FormulaManager.php b/application/Espo/Core/Loaders/FormulaManager.php deleted file mode 100644 index 17719696e5..0000000000 --- a/application/Espo/Core/Loaders/FormulaManager.php +++ /dev/null @@ -1,43 +0,0 @@ -getContainer()->get('injectableFactory'), - $this->getContainer()->get('metadata') - ); - - return $formulaManager; - } -} diff --git a/application/Espo/Core/Loaders/PasswordHash.php b/application/Espo/Core/Loaders/PasswordHash.php deleted file mode 100644 index 828a6fc20d..0000000000 --- a/application/Espo/Core/Loaders/PasswordHash.php +++ /dev/null @@ -1,40 +0,0 @@ -getContainer()->get('config') - ); - } -} diff --git a/application/Espo/Core/Loaders/SelectManagerFactory.php b/application/Espo/Core/Loaders/SelectManagerFactory.php deleted file mode 100644 index 04587f96f1..0000000000 --- a/application/Espo/Core/Loaders/SelectManagerFactory.php +++ /dev/null @@ -1,48 +0,0 @@ -getContainer()->get('entityManager'), - $this->getContainer()->get('user'), - $this->getContainer()->get('acl'), - $this->getContainer()->get('aclManager'), - $this->getContainer()->get('metadata'), - $this->getContainer()->get('config'), - $this->getContainer()->get('fieldManagerUtil'), - $this->getContainer()->get('injectableFactory'), - $this->getContainer()->get('classFinder') - ); - } -} diff --git a/application/Espo/Core/Loaders/ServiceFactory.php b/application/Espo/Core/Loaders/ServiceFactory.php deleted file mode 100644 index d3a98152ac..0000000000 --- a/application/Espo/Core/Loaders/ServiceFactory.php +++ /dev/null @@ -1,41 +0,0 @@ -getContainer()->get('classFinder'), - $this->getContainer()->get('injectableFactory') - ); - } -} diff --git a/application/Espo/Core/Loaders/TemplateFileManager.php b/application/Espo/Core/Loaders/TemplateFileManager.php deleted file mode 100644 index b3569ba977..0000000000 --- a/application/Espo/Core/Loaders/TemplateFileManager.php +++ /dev/null @@ -1,45 +0,0 @@ -getContainer()->get('config'), - $this->getContainer()->get('metadata'), - $this->getContainer()->get('fileManager') - ); - - return $templateFileManager; - } -} - diff --git a/application/Espo/Core/Loaders/WebhookManager.php b/application/Espo/Core/Loaders/WebhookManager.php deleted file mode 100644 index 484a1e3355..0000000000 --- a/application/Espo/Core/Loaders/WebhookManager.php +++ /dev/null @@ -1,43 +0,0 @@ -getContainer()->get('config'), - $this->getContainer()->get('fileManager'), - $this->getContainer()->get('entityManager'), - $this->getContainer()->get('fieldManagerUtil') - ); - } -} diff --git a/application/Espo/Core/ORM/EntityManager.php b/application/Espo/Core/ORM/EntityManager.php index 087fc18b72..28706ee2c2 100644 --- a/application/Espo/Core/ORM/EntityManager.php +++ b/application/Espo/Core/ORM/EntityManager.php @@ -54,12 +54,12 @@ class EntityManager extends BaseEntityManager RepositoryFactory $repositoryFactory, EntityFactory $entityFactory, HookManager $hookManager, - Helper $entityManagerHelper + Helper $helper ) { parent::__construct($params, $repositoryFactory, $entityFactory); $this->hookManager = $hookManager; - $this->helper = $entityManagerHelper; + $this->helper = $helper; } // TODO Check whether setUser is needed here diff --git a/application/Espo/Core/ORM/Repository.php b/application/Espo/Core/ORM/Repository.php index 639f3f2839..62e5072e56 100644 --- a/application/Espo/Core/ORM/Repository.php +++ b/application/Espo/Core/ORM/Repository.php @@ -33,6 +33,7 @@ use \Espo\Core\Interfaces\Injectable; use \Espo\ORM\EntityFactory; +/** Deprecated */ abstract class Repository extends \Espo\ORM\Repository implements Injectable { protected $dependencyList = []; diff --git a/application/Espo/Core/SelectManagerFactory.php b/application/Espo/Core/SelectManagerFactory.php index 50de12d51e..12244a2d23 100644 --- a/application/Espo/Core/SelectManagerFactory.php +++ b/application/Espo/Core/SelectManagerFactory.php @@ -40,20 +40,14 @@ use Espo\Core\Utils\Util; class SelectManagerFactory { private $entityManager; - private $user; - private $acl; - private $metadata; - private $injectableFactory; - private $fieldManagerUtil; - private $classFinder; - protected $baseClassName = '\\Espo\\Core\\SelectManager'; + protected $baseClassName = SelectManager::class; public function __construct( EntityManager $entityManager, @@ -64,8 +58,8 @@ class SelectManagerFactory Utils\Config $config, Utils\FieldManagerUtil $fieldManagerUtil, InjectableFactory $injectableFactory, - Utils\ClassFinder $classFinder) - { + Utils\ClassFinder $classFinder + ) { $this->entityManager = $entityManager; $this->user = $user; $this->acl = $acl; diff --git a/application/Espo/Core/Utils/TemplateFileManager.php b/application/Espo/Core/Utils/TemplateFileManager.php index e646a46dc0..2cb6870177 100644 --- a/application/Espo/Core/Utils/TemplateFileManager.php +++ b/application/Espo/Core/Utils/TemplateFileManager.php @@ -146,4 +146,3 @@ class TemplateFileManager return $fileName; } } - diff --git a/application/Espo/Core/Webhook/Manager.php b/application/Espo/Core/Webhook/Manager.php index 3251eb3fb6..21b87f5516 100644 --- a/application/Espo/Core/Webhook/Manager.php +++ b/application/Espo/Core/Webhook/Manager.php @@ -42,7 +42,7 @@ class Manager protected $config; protected $fileManager; protected $entityManager; - protected $fieldManager; + protected $fieldManagerUtil; private $cacheFile = 'data/cache/application/webhooks.php'; @@ -54,12 +54,12 @@ class Manager Config $config, FileManager $fileManager, EntityManager $entityManager, - FieldManagerUtil $fieldManager + FieldManagerUtil $fieldManagerUtil ) { $this->config = $config; $this->fileManager = $fileManager; $this->entityManager = $entityManager; - $this->fieldManager = $fieldManager; + $this->fieldManagerUtil = $fieldManagerUtil; $this->loadData(); } @@ -202,11 +202,11 @@ class Manager $this->logDebugEvent($event, $entity); } - foreach ($this->fieldManager->getEntityTypeFieldList($entity->getEntityType()) as $field) { + foreach ($this->fieldManagerUtil->getEntityTypeFieldList($entity->getEntityType()) as $field) { $itemEvent = $entity->getEntityType() . '.fieldUpdate.' . $field; if (!$this->eventExists($itemEvent)) continue; - $attributeList = $this->fieldManager->getActualAttributeList($entity->getEntityType(), $field); + $attributeList = $this->fieldManagerUtil->getActualAttributeList($entity->getEntityType(), $field); $isChanged = false; foreach ($attributeList as $attribute) { if (in_array($attribute, $this->skipAttributeList)) continue; @@ -219,7 +219,7 @@ class Manager if ($isChanged) { $itemData = (object) []; $itemData->id = $entity->id; - $attributeList = $this->fieldManager->getAttributeList($entity->getEntityType(), $field); + $attributeList = $this->fieldManagerUtil->getAttributeList($entity->getEntityType(), $field); foreach ($attributeList as $attribute) { if (in_array($attribute, $this->skipAttributeList)) continue; $itemData->$attribute = $entity->get($attribute); diff --git a/application/Espo/ORM/Repositories/RDB.php b/application/Espo/ORM/Repositories/RDB.php index ca24cf7209..03893f7010 100644 --- a/application/Espo/ORM/Repositories/RDB.php +++ b/application/Espo/ORM/Repositories/RDB.php @@ -35,7 +35,6 @@ use Espo\ORM\EntityCollection; use Espo\ORM\Entity; use Espo\ORM\IEntity; - class RDB extends \Espo\ORM\Repository { /** @@ -110,7 +109,7 @@ class RDB extends \Espo\ORM\Repository } } - public function getById($id, array $params = []) : ?Entity + public function getById(string $id, array $params = []) : ?Entity { $entity = $this->entityFactory->create($this->entityType); if (!$entity) return null; @@ -122,7 +121,7 @@ class RDB extends \Espo\ORM\Repository return $this->getMapper()->selectById($entity, $id, $params); } - public function get($id = null) : ?Entity + public function get(?string $id = null) : ?Entity { if (is_null($id)) { return $this->getNew(); @@ -170,7 +169,7 @@ class RDB extends \Espo\ORM\Repository return $result; } - public function restoreDeleted($id) + public function restoreDeleted(string $id) { return $this->getMapper()->restoreDeleted($this->entityType, $id); } @@ -193,7 +192,7 @@ class RDB extends \Espo\ORM\Repository return $result; } - public function deleteFromDb($id, $onlyDeleted = false) + public function deleteFromDb(string $id, bool $onlyDeleted = false) { return $this->getMapper()->deleteFromDb($this->entityType, $id, $onlyDeleted); } @@ -282,7 +281,7 @@ class RDB extends \Espo\ORM\Repository } } - public function countRelated(Entity $entity, $relationName, array $params = []) + public function countRelated(Entity $entity, string $relationName, array $params = []) { if (!$entity->id) { return; @@ -295,7 +294,7 @@ class RDB extends \Espo\ORM\Repository return intval($this->getMapper()->countRelated($entity, $relationName, $params)); } - public function isRelated(Entity $entity, $relationName, $foreign) + public function isRelated(Entity $entity, string $relationName, $foreign) { if (!$entity->id) { return null; @@ -342,7 +341,7 @@ class RDB extends \Espo\ORM\Repository ]); } - public function relate(Entity $entity, $relationName, $foreign, $data = null, array $options = []) + public function relate(Entity $entity, string $relationName, $foreign, $data = null, array $options = []) { if (!$entity->id) { return; @@ -383,7 +382,7 @@ class RDB extends \Espo\ORM\Repository } - public function unrelate(Entity $entity, $relationName, $foreign, array $options = []) + public function unrelate(Entity $entity, string $relationName, $foreign, array $options = []) { if (!$entity->id) { return; @@ -451,7 +450,7 @@ class RDB extends \Espo\ORM\Repository { } - public function updateRelation(Entity $entity, $relationName, $foreign, $data) + public function updateRelation(Entity $entity, string $relationName, $foreign, $data) { if (!$entity->id) { return; @@ -470,7 +469,7 @@ class RDB extends \Espo\ORM\Repository return null; } - public function massRelate(Entity $entity, $relationName, array $params = [], array $options = []) + public function massRelate(Entity $entity, string $relationName, array $params = [], array $options = []) { if (!$entity->id) { return; diff --git a/application/Espo/ORM/Repository.php b/application/Espo/ORM/Repository.php index 2ec45a4d88..f32362cfaa 100644 --- a/application/Espo/ORM/Repository.php +++ b/application/Espo/ORM/Repository.php @@ -81,7 +81,7 @@ abstract class Repository return $this->entityType; } - abstract public function get($id = null); + abstract public function get(?string $id = null); abstract public function save(Entity $entity); diff --git a/application/Espo/Repositories/Preferences.php b/application/Espo/Repositories/Preferences.php index 464a19b7ba..240e15a459 100644 --- a/application/Espo/Repositories/Preferences.php +++ b/application/Espo/Repositories/Preferences.php @@ -30,53 +30,63 @@ namespace Espo\Repositories; use Espo\ORM\Entity; +use Espo\ORM\Repository; use Espo\Core\Utils\Json; -class Preferences extends \Espo\Core\ORM\Repository +use Espo\Core\Di\{ + FileManagerAware, + FileManagerSetter, + MetadataAware, + MetadataSetter, + ConfigAware, + ConfigSetter, + EntityManagerAware, + EntityManagerSetter, +}; + +class Preferences extends Repository implements + FileManagerAware, + MetadataAware, + ConfigAware, + EntityManagerAware { + use FileManagerSetter; + use MetadataSetter; + use ConfigSetter; + use EntityManagerSetter; + protected $defaultAttributeListFromSettings = [ 'decimalMark', 'thousandSeparator', 'exportDelimiter', - 'followCreatedEntities' + 'followCreatedEntities', ]; - protected $data = array(); + protected $data = []; protected $entityType = 'Preferences'; - protected function init() - { - parent::init(); - $this->addDependencyList([ - 'fileManager', - 'metadata', - 'config', - 'entityManager' - ]); - } - protected function getFileManager() { - return $this->getInjection('fileManager'); + return $this->fileManager; } protected function getEntityManger() { - return $this->getInjection('entityManager'); + return $this->entityManager; } protected function getMetadata() { - return $this->getInjection('metadata'); + return $this->metadata; } protected function getConfig() { - return $this->getInjection('config'); + return $this->config; } - public function get($id = null) + public function get(?string $id = null) { if ($id) { $entity = $this->entityFactory->create('Preferences'); @@ -236,7 +246,7 @@ class Preferences extends \Espo\Core\ORM\Repository $ps = $pdo->query($sql); } - public function remove(Entity $entity, array $options = array()) + public function remove(Entity $entity, array $options = []) { if (!$entity->id) return; $this->deleteFromDb($entity->id); diff --git a/application/Espo/Resources/metadata/app/containerServices.json b/application/Espo/Resources/metadata/app/containerServices.json index 5e177eb62d..530e898031 100644 --- a/application/Espo/Resources/metadata/app/containerServices.json +++ b/application/Espo/Resources/metadata/app/containerServices.json @@ -20,15 +20,33 @@ "cronManager": { "className": "Espo\\Core\\CronManager" }, + "webSocketSubmission": { + "className": "Espo\\Core\\WebSocket\\Submission" + }, "crypt": { "className": "Espo\\Core\\Utils\\Crypt" }, + "passwordHash": { + "className": "Espo\\Core\\Utils\\PasswordHash" + }, "number": { "loaderClassName": "Espo\\Core\\Loaders\\NumberUtil" }, "controllerManager": { "className": "Espo\\Core\\ControllerManager" }, + "selectManagerFactory": { + "className": "Espo\\Core\\SelectManagerFactory" + }, + "serviceFactory": { + "className": "Espo\\Core\\ServiceFactory" + }, + "templateFileManager": { + "className": "Espo\\Core\\Utils\\TemplateFileManager" + }, + "webhookManager": { + "className": "Espo\\Core\\Webhook\\Manager" + }, "scheduledJob": { "className": "Espo\\Core\\Utils\\ScheduledJob" }, @@ -83,6 +101,12 @@ "entityManagerUtil": { "className": "Espo\\Core\\Utils\\EntityManager" }, + "externalAccountClientManager": { + "className": "Espo\\Core\\ExternalAccount\\ClientManager" + }, + "formulaManager": { + "className": "Espo\\Core\\Formula\\Manager" + }, "user": { "settable": true }