decoupling

This commit is contained in:
Yuri Kuznetsov
2020-06-22 19:16:40 +03:00
parent b2fa393673
commit 6b2fdf5400
37 changed files with 377 additions and 505 deletions
+2
View File
@@ -45,6 +45,7 @@ use Espo\Core\{
Loaders\Config as ConfigLoader,
Loaders\Log as LogLoader,
Loaders\FileManager as FileManagerLoader,
Loaders\DataManager as DataManagerLoader,
Loaders\Metadata as MetadataLoader,
};
@@ -62,6 +63,7 @@ class Application
'config' => ConfigLoader::class,
'log' => LogLoader::class,
'fileManager' => FileManagerLoader::class,
'dataManager' => DataManagerLoader::class,
'metadata' => MetadataLoader::class,
];
@@ -29,15 +29,23 @@
namespace Espo\Core\Console;
use Espo\Core\Utils\Util;
use Espo\Core\{
InjectableFactory,
Utils\Metadata,
Utils\Util,
};
use Espo\Core\Exceptions\Error;
class CommandManager
{
protected $container;
protected $injectableFactory;
protected $metadata;
public function __construct(\Espo\Core\Container $container)
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
{
$this->container = $container;
$this->injectableFactory = $injectableFactory;
$this->metadata = $metadata;
}
public function run(string $command)
@@ -52,24 +60,27 @@ class CommandManager
$className = $this->getClassName($command);
$impl = new $className($this->container);
return $impl->run($options, $flagList, $argumentList);
$obj = $this->injectableFactory->create($className);
return $obj->run($options, $flagList, $argumentList);
}
protected function getClassName(string $command)
protected function getClassName(string $command) : string
{
$className = '\\Espo\\Core\\Console\\Commands\\' . $command;
$className = $this->container->get('metadata')->get(['app', 'consoleCommands', $command, 'className'], $className);
$className =
$this->metadata->get(['app', 'consoleCommands', $command, 'className']) ??
'Espo\\Core\\Console\\Commands\\' . $command;
if (!class_exists($className)) {
$msg = "Command '{$command}' does not exist.";
echo $msg . "\n";
throw new \Espo\Core\Exceptions\Error($msg);
throw new Error($msg);
}
return $className;
}
protected function getParams(array $argv)
protected function getParams(array $argv) : array
{
$argumentList = [];
$options = [];
@@ -29,41 +29,51 @@
namespace Espo\Core\Console\Commands;
class AclCheck extends Base
use Espo\Core\Portal\Application as PortalApplication;
use Espo\Core\Container;
class AclCheck implements Command
{
public function run($options)
protected $container;
public function __construct(Container $container)
{
$this->container = $container;
}
public function run(array $options) : ?string
{
$userId = $options['userId'] ?? null;
$scope = $options['scope'] ?? null;
$id = $options['id'] ?? null;
$action = $options['action'] ?? null;
if (empty($userId)) return;
if (empty($scope)) return;
if (empty($id)) return;
if (empty($userId)) return null;
if (empty($scope)) return null;
if (empty($id)) return null;
$container = $this->getContainer();
$container = $this->container;
$entityManager = $container->get('entityManager');
$user = $entityManager->getEntity('User', $userId);
if (!$user) return;
if (!$user) return null;
if ($user->isPortal()) {
$portalIdList = $user->getLinkMultipleIdList('portals');
foreach ($portalIdList as $portalId) {
$application = new \Espo\Core\Portal\Application($portalId);
$application = new PortalApplication($portalId);
$containerPortal = $application->getContainer();
$entityManager = $containerPortal->get('entityManager');
$user = $entityManager->getEntity('User', $userId);
if (!$user) return;
if (!$user) return null;
$result = $this->check($user, $scope, $id, $action, $containerPortal);
if ($result) {
return 'true';
}
}
return;
return null;
}
if ($this->check($user, $scope, $id, $action, $container)) {
@@ -76,12 +86,14 @@ class AclCheck extends Base
$entityManager = $container->get('entityManager');
$entity = $entityManager->getEntity($scope, $id);
if (!$entity) return;
if (!$entity) return false;
$aclManager = $container->get('aclManager');
if ($aclManager->check($user, $entity, $action)) {
return true;
}
return false;
}
}
@@ -29,27 +29,36 @@
namespace Espo\Core\Console\Commands;
class AuthTokenCheck extends Base
use Espo\Core\ORM\EntityManager;
class AuthTokenCheck implements Command
{
public function run($options, $flagList, $argumentList)
protected $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function run(array $options, array $flagList, array $argumentList) : ?string
{
$token = $argumentList[0] ?? null;
if (empty($token)) return;
if (empty($token)) return null;
$entityManager = $this->getContainer()->get('entityManager');
$entityManager = $this->entityManager;
$authToken = $entityManager->getRepository('AuthToken')->where([
'token' => $token,
'isActive' => true,
])->findOne();
if (!$authToken) return;
if (!$authToken->get('userId')) return;
if (!$authToken) return null;
if (!$authToken->get('userId')) return null;
$userId = $authToken->get('userId');
$user = $entityManager->getEntity('User', $userId);
if (!$user) return;
if (!$user) return null;
return $user->id;
}
@@ -29,6 +29,7 @@
namespace Espo\Core\Console\Commands;
/** Deprecated */
abstract class Base
{
private $container;
@@ -29,11 +29,20 @@
namespace Espo\Core\Console\Commands;
class ClearCache extends Base
use Espo\Core\DataManager;
class ClearCache implements Command
{
protected $dataManager;
public function __construct(DataManager $dataManager)
{
$this->dataManager = $dataManager;
}
public function run()
{
$this->getContainer()->get('dataManager')->clearCache();
$this->dataManager->clearCache();
echo "Cache has been cleared.\n";
}
}
@@ -27,14 +27,9 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Loaders;
namespace Espo\Core\Console\Commands;
class HtmlizerFactory extends Base
interface Command
{
public function load()
{
return new \Espo\Core\Htmlizer\Factory(
$this->getContainer()
);
}
}
@@ -31,11 +31,21 @@ namespace Espo\Core\Console\Commands;
use Espo\Core\Exceptions\Error;
class Extension extends Base
use Espo\Core\Container;
use Espo\Core\ExtensionManager;
class Extension implements Command
{
protected $extensionManager = null;
public function run($options, $flagList, $argumentList)
protected $container;
public function __construct(Container $container)
{
$this->container = $container;
}
public function run(array $options, array $flagList)
{
if (in_array('u', $flagList)) {
// uninstall
@@ -180,12 +190,12 @@ class Extension extends Base
protected function createExtensionManager()
{
return new \Espo\Core\ExtensionManager($this->getContainer());
return new ExtensionManager($this->container);
}
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
return $this->container->get('entityManager');
}
protected function out(string $string)
@@ -29,15 +29,24 @@
namespace Espo\Core\Console\Commands;
class Import extends Base
use Espo\Core\ServiceFactory;
class Import implements Command
{
public function run($options, $flagList, $argumentList)
protected $serviceFactory;
public function __construct(ServiceFactory $serviceFactory)
{
$this->serviceFactory = $serviceFactory;
}
public function run(array $options, array $flagList)
{
$id = $options['id'] ?? null;
$filePath = $options['file'] ?? null;
$paramsId = $options['paramsId'] ?? null;
$service = $this->getContainer()->get('serviceFactory')->create('Import');
$service = $this->serviceFactory->create('Import');
$forceResume = in_array('resume', $flagList);
$revert = in_array('revert', $flagList);
@@ -29,11 +29,20 @@
namespace Espo\Core\Console\Commands;
class Rebuild extends Base
use Espo\Core\DataManager;
class Rebuild implements Command
{
protected $dataManager;
public function __construct(DataManager $dataManager)
{
$this->dataManager = $dataManager;
}
public function run()
{
$this->getContainer()->get('dataManager')->rebuild();
$this->dataManager->rebuild();
echo "Rebuild has been done.\n";
}
}
@@ -29,9 +29,23 @@
namespace Espo\Core\Console\Commands;
class RunJob extends Base
use Espo\Core\CronManager;
use Espo\Core\Utils\Util;
use Espo\Core\Container;
use Espo\Core\ORM\EntityManager;
class RunJob implements Command
{
public function run($options, $flags, $argumentList)
protected $container;
protected $entityManager;
public function __construct(Container $container, EntityManager $entityManager)
{
$this->container = $container;
$this->entityManager = $entityManager;
}
public function run(array $options, array $flags, array $argumentList)
{
$jobName = $options['job'] ?? null;
$targetId = $options['targetId'] ?? null;
@@ -43,10 +57,10 @@ class RunJob extends Base
if (!$jobName) echo "No job specified.\n";
$jobName = ucfirst(\Espo\Core\Utils\Util::hyphenToCamelCase($jobName));
$jobName = ucfirst(Util::hyphenToCamelCase($jobName));
$container = $this->getContainer();
$entityManager = $container->get('entityManager');
$container = $this->container;
$entityManager = $this->entityManager;
$job = $entityManager->createEntity('Job', [
'name' => $jobName,
@@ -55,7 +69,7 @@ class RunJob extends Base
'targetId' => $targetId,
]);
$cronManager = new \Espo\Core\CronManager($container);
$cronManager = new CronManager($container);
$result = $cronManager->runJob($job);
@@ -29,9 +29,21 @@
namespace Espo\Core\Console\Commands;
class SetPassword extends Base
use Espo\Core\Container;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Utils\PasswordHash;
class SetPassword implements Command
{
public function run($options, $flagList, $argumentList)
protected $entityManager;
public function __construct(EntityManager $entityManager, PasswordHash $passwordHash)
{
$this->entityManager = $entityManager;
$this->passwordHash = $passwordHash;
}
public function run(array $options, array $flagList, array $argumentList)
{
$userName = $argumentList[0] ?? null;
@@ -40,7 +52,7 @@ class SetPassword extends Base
die;
}
$em = $this->getContainer()->get('entityManager');
$em = $this->entityManager;
$user = $em->getRepository('User')->where(['userName' => $userName])->findOne();
@@ -63,7 +75,7 @@ class SetPassword extends Base
die;
}
$hash = $this->getContainer()->get('passwordHash');
$hash = $this->passwordHash;
$user->set('password', $hash->hash($password));
@@ -29,11 +29,20 @@
namespace Espo\Core\Console\Commands;
class Version extends Base
use Espo\Core\Utils\Config;
class Version implements Command
{
public function run($options, $flagList, $argumentList)
protected $config;
public function __construct(Config $config)
{
$version = $this->getContainer()->get('config')->get('version');
$this->config = $config;
}
public function run()
{
$version = $this->config->get('version');
if (is_null($version)) {
return;
+10 -112
View File
@@ -53,7 +53,7 @@ class Container
}
/**
* Obtain a service.
* Obtain a service object.
*/
public function get(string $name) : ?object
{
@@ -77,23 +77,25 @@ class Container
if (method_exists($this, $loadMethodName)) return true;
if ($this->configuration->getLoaderClassName($name)) return true;
if ($this->configuration->getServiceClassName($name)) return true;
return false;
}
public function set(string $name, object $obj)
/**
* Set a service object. Must be configured as settable.
*/
public function set(string $name, object $object)
{
if (!$this->configuration->isSettable($name)) {
throw new Error("Service '{$name}' is not settable.");
}
$this->setForced($name, $obj);
$this->setForced($name, $object);
}
protected function setForced(string $name, object $obj)
protected function setForced(string $name, object $object)
{
$this->data[$name] = $obj;
$this->data[$name] = $object;
}
private function load(string $name)
@@ -139,9 +141,9 @@ class Container
return $this;
}
protected function loadSlim()
protected function loadInjectableFactory()
{
return new \Espo\Core\Utils\Api\Slim();
return new InjectableFactory($this);
}
protected function loadFileStorageManager()
@@ -152,37 +154,11 @@ class Container
);
}
protected function loadControllerManager()
{
return new \Espo\Core\ControllerManager(
$this->get('injectableFactory'),
$this->get('classFinder'),
$this->get('metadata') // TODO remove
);
}
protected function loadPreferences()
{
return $this->get('entityManager')->getEntity('Preferences', $this->get('user')->id);
}
protected function loadHookManager()
{
return new \Espo\Core\HookManager(
$this->get('injectableFactory'),
$this->get('fileManager'),
$this->get('metadata'),
$this->get('config')
);
}
protected function loadOutput()
{
return new \Espo\Core\Utils\Api\Output(
$this->get('slim')
);
}
protected function loadDateTime()
{
return new \Espo\Core\Utils\DateTime(
@@ -193,44 +169,6 @@ class Container
);
}
protected function loadNumber()
{
return new \Espo\Core\Utils\NumberUtil(
$this->get('config')->get('decimalMark'),
$this->get('config')->get('thousandSeparator')
);
}
protected function loadSchema()
{
return new \Espo\Core\Utils\Database\Schema\Schema(
$this->get('config'),
$this->get('metadata'),
$this->get('fileManager'),
$this->get('entityManager'),
$this->get('classParser'),
$this->get('ormMetadata')
);
}
protected function loadOrmMetadata()
{
return new \Espo\Core\Utils\Metadata\OrmMetadata(
$this->get('metadata'),
$this->get('fileManager'),
$this->get('config')
);
}
protected function loadClassParser()
{
return new \Espo\Core\Utils\File\ClassParser(
$this->get('fileManager'),
$this->get('config'),
$this->get('metadata')
);
}
protected function loadLanguage()
{
return new \Espo\Core\Utils\Language(
@@ -260,44 +198,4 @@ class Container
$this->get('config')->get('useCache')
);
}
protected function loadCrypt()
{
return new \Espo\Core\Utils\Crypt(
$this->get('config')
);
}
protected function loadScheduledJob()
{
return new \Espo\Core\Utils\ScheduledJob(
$this
);
}
protected function loadDataManager()
{
return new \Espo\Core\DataManager(
$this
);
}
protected function loadFieldManager()
{
return new \Espo\Core\Utils\FieldManager(
$this
);
}
protected function loadFieldManagerUtil()
{
return new \Espo\Core\Utils\FieldManagerUtil(
$this->get('metadata')
);
}
protected function loadInjectableFactory()
{
return new InjectableFactory($this);
}
}
+4 -4
View File
@@ -51,7 +51,7 @@ class DataManager
*
* @return bool
*/
public function rebuild($entityList = null)
public function rebuild($target = null)
{
$result = $this->clearCache();
@@ -59,7 +59,7 @@ class DataManager
$result &= $this->rebuildMetadata();
$result &= $this->rebuildDatabase($entityList);
$result &= $this->rebuildDatabase($target);
$this->rebuildScheduledJobs();
@@ -89,12 +89,12 @@ class DataManager
*
* @return bool
*/
public function rebuildDatabase($entityList = null)
public function rebuildDatabase($target = null)
{
$schema = $this->getContainer()->get('schema');
try {
$result = $schema->rebuild($entityList);
$result = $schema->rebuild($target);
} catch (\Throwable $e) {
$result = false;
$GLOBALS['log']->error('Fault to rebuild database schema. Details: '. $e->getMessage());
+11 -17
View File
@@ -29,29 +29,23 @@
namespace Espo\Core\Htmlizer;
use Espo\Core\Container;
use Espo\Core\InjectableFactory;
class Factory
{
protected $container;
protected $injectableFactory;
public function __construct(Container $container)
{
$this->container = $container;
public function __construct(InjectableFactory $injectableFactory) {
$this->injectableFactory = $injectableFactory;
}
public function create(bool $skipAcl = false)
public function create(bool $skipAcl = false) : Htmlizer
{
return new Htmlizer(
$this->container->get('fileManager'),
$this->container->get('dateTime'),
$this->container->get('number'),
!$skipAcl ? $this->container->get('acl') : null,
$this->container->get('entityManager'),
$this->container->get('metadata'),
$this->container->get('defaultLanguage'),
$this->container->get('config'),
$this->container->get('serviceFactory')
);
$with = [];
if ($skipAcl) {
$with['acl'] = null;
}
return $this->injectableFactory->createWith(Htmlizer::class, $with);
}
}
+3 -3
View File
@@ -40,6 +40,7 @@ use Espo\Core\Utils\Language;
use Espo\Core\Utils\Metadata;
use Espo\ORM\EntityManager;
use Espo\Core\ServiceFactory;
use Espo\Core\Acl;
use LightnCandy\LightnCandy as LightnCandy;
@@ -58,14 +59,13 @@ class Htmlizer
FileManager $fileManager,
DateTime $dateTime,
NumberUtil $number,
$acl = null,
?Acl $acl = null,
?EntityManager $entityManager = null,
?Metadata $metadata = null,
?Language $language = null,
?Config $config = null,
?ServiceFactory $serviceFactory = null
)
{
) {
$this->fileManager = $fileManager;
$this->dateTime = $dateTime;
$this->number = $number;
@@ -1,42 +0,0 @@
<?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;
class AuthenticationFactory extends Base
{
public function load()
{
$obj = new \Espo\Core\Utils\Authentication\Utils\AuthenticationFactory(
$this->getContainer()->get('injectableFactory'),
$this->getContainer()->get('metadata')
);
return $obj;
}
}
@@ -1,40 +0,0 @@
<?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;
class ClassFinder extends Base
{
public function load()
{
return new \Espo\Core\Utils\ClassFinder(
$this->getContainer()->get('classParser')
);
}
}
@@ -29,12 +29,25 @@
namespace Espo\Core\Loaders;
class ConsoleCommandManager extends Base
use Espo\Core\{
InjectableFactory,
Utils\Metadata,
Console\CommandManager,
};
class ConsoleCommandManager implements Loader
{
protected $injectableFactory;
protected $metadata;
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
{
$this->injectableFactory = $injectableFactory;
$this->metadata = $metadata;
}
public function load()
{
return new \Espo\Core\Console\CommandManager(
$this->getContainer()
);
return new CommandManager($this->injectableFactory, $this->metadata);
}
}
@@ -29,14 +29,20 @@
namespace Espo\Core\Loaders;
class Auth2FAFactory extends Base
use Espo\Core\{
Container,
DataManager as DataManagerService,
};
class DataManager implements Loader
{
public function __construct(Container $container)
{
$this->container = $container;
}
public function load()
{
$obj = new \Espo\Core\Utils\Authentication\TwoFA\Utils\Factory(
$this->getContainer()->get('injectableFactory'),
$this->getContainer()->get('metadata')
);
return $obj;
return new DataManagerService($this->container);
}
}
@@ -1,41 +0,0 @@
<?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;
class FieldValidatorManager extends Base
{
public function load()
{
return new \Espo\Core\Utils\FieldValidatorManager(
$this->getContainer()->get('metadata'),
$this->getContainer()->get('fieldManagerUtil')
);
}
}
-40
View File
@@ -1,40 +0,0 @@
<?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;
class Hasher extends Base
{
public function load()
{
return new \Espo\Core\Utils\Hasher(
$this->getContainer()->get('config')
);
}
}
@@ -1,42 +0,0 @@
<?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;
class MailSender extends Base
{
public function load()
{
return new \Espo\Core\Mail\Sender(
$this->getContainer()->get('config'),
$this->getContainer()->get('entityManager'),
$this->getContainer()->get('serviceFactory')
);
}
}
@@ -29,14 +29,22 @@
namespace Espo\Core\Loaders;
class Auth2FAUserFactory extends Base
use Espo\Core\{
Utils\Config,
Utils\NumberUtil as NumberUtilService,
};
class NumberUtil implements Loader
{
protected $config;
public function __construct(Config $config)
{
$this->config = $config;
}
public function load()
{
$obj = new \Espo\Core\Utils\Authentication\TwoFA\Utils\UserFactory(
$this->getContainer()->get('injectableFactory'),
$this->getContainer()->get('metadata')
);
return $obj;
return new NumberUtilService($this->config->get('decimalMark'), $this->config->get('thousandSeparator'));
}
}
-40
View File
@@ -1,40 +0,0 @@
<?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;
class Totp extends Base
{
public function load()
{
return new \Espo\Core\Utils\Authentication\TwoFA\Utils\Totp(
$this->getContainer()->get('config')
);
}
}
+7 -1
View File
@@ -42,6 +42,12 @@ use Laminas\Mail\Transport\Envelope;
use Espo\Core\Exceptions\Error;
use Espo\Core\{
Utils\Config,
ORM\EntityManager,
ServiceFactory,
};
class Sender
{
protected $config;
@@ -64,7 +70,7 @@ class Sender
private $envelope = null;
public function __construct($config, $entityManager, $serviceFactory = null)
public function __construct(Config $config, EntityManager $entityManager, ?ServiceFactory $serviceFactory = null)
{
$this->config = $config;
$this->entityManager = $entityManager;
+2 -2
View File
@@ -47,10 +47,10 @@ class Output
];
protected $ignorePrintXStatusReasonExceptionClassNameList = [
'PDOException'
'PDOException',
];
public function __construct(\Espo\Core\Utils\Api\Slim $slim)
public function __construct(Slim $slim)
{
$this->slim = $slim;
}
@@ -51,9 +51,9 @@ class AuthenticationFactory
if (!$className) {
$sanitizedName = preg_replace('/[^a-zA-Z0-9]+/', '', $method);
$className = "\\Espo\\Custom\\Core\\Utils\\Authentication\\" . $sanitizedName;
$className = "Espo\\Custom\\Core\\Utils\\Authentication\\" . $sanitizedName;
if (!class_exists($className)) {
$className = "\\Espo\\Core\\Utils\\Authentication\\" . $sanitizedName;
$className = "Espo\\Core\\Utils\\Authentication\\" . $sanitizedName;
}
}
+2 -2
View File
@@ -39,7 +39,7 @@ class Crypt
private $iv = null;
public function __construct($config)
public function __construct(Config $config)
{
$this->config = $config;
$this->cryptKey = $config->get('cryptKey', '');
@@ -97,6 +97,6 @@ class Crypt
public function generateKey()
{
return \Espo\Core\Utils\Util::generateSecretKey();
return Util::generateSecretKey();
}
}
@@ -29,8 +29,15 @@
namespace Espo\Core\Utils\Database\Schema;
use Doctrine\DBAL\Types\Type,
Espo\Core\Utils\Util;
use Doctrine\DBAL\Types\Type;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Metadata;
use Espo\Core\Utils\File\Manager as FileManager;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Utils\File\ClassParser;
use Espo\Core\Utils\Metadata\OrmMetadata;
use Espo\Core\Utils\Util;
class Schema
{
@@ -75,10 +82,13 @@ class Schema
protected $rebuildActionClasses = null;
public function __construct(
\Espo\Core\Utils\Config $config, \Espo\Core\Utils\Metadata $metadata,
\Espo\Core\Utils\File\Manager $fileManager, \Espo\Core\ORM\EntityManager $entityManager,
\Espo\Core\Utils\File\ClassParser $classParser, \Espo\Core\Utils\Metadata\OrmMetadata $ormMetadata)
{
Config $config,
Metadata $metadata,
FileManager $fileManager,
EntityManager $entityManager,
ClassParser $classParser,
OrmMetadata $ormMetadata
) {
$this->config = $config;
$this->metadata = $metadata;
$this->fileManager = $fileManager;
+6 -1
View File
@@ -29,13 +29,18 @@
namespace Espo\Core\Utils;
use Espo\Core\Utils\Config;
/**
* Hash a string. E.g. hash an email address to use it in opt-out URL to recognize a recipient who clicked opt-out.
*/
class Hasher
{
protected $config;
protected $secretKeyParam = 'hashSecretKey';
public function __construct(\Espo\Core\Utils\Config $config)
public function __construct(Config $config)
{
$this->config = $config;
}
+8 -12
View File
@@ -28,6 +28,7 @@
************************************************************************/
namespace Espo\Core\Utils;
use Espo\Core\Exceptions\Error;
class PasswordHash
@@ -52,12 +53,9 @@ class PasswordHash
}
/**
* Get hash of a pawword
*
* @param string $password
* @return string
* Hash a password.
*/
public function hash($password, $useMd5 = true)
public function hash(string $password, bool $useMd5 = true) : string
{
$salt = $this->getSalt();
@@ -72,7 +70,7 @@ class PasswordHash
}
/**
* Get a salt from config and normalize it
* Get a salt from config and normalize it.
*
* @return string
*/
@@ -89,7 +87,7 @@ class PasswordHash
}
/**
* Convert salt in format in accordance to $saltFormat
* Convert salt in format in accordance to $saltFormat.
*
* @param string $salt
* @return string
@@ -100,12 +98,10 @@ class PasswordHash
}
/**
* Generate a new salt
*
* @return string
* Generate a new salt.
*/
public function generateSalt()
public function generateSalt() : string
{
return substr(md5(uniqid()), 0, 16);
}
}
}
+23 -15
View File
@@ -31,10 +31,16 @@ namespace Espo\Core\Utils;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Container;
use Espo\Core\{
Utils\ClassFinder,
Utils\Language,
Utils\System,
ORM\EntityManager,
};
class ScheduledJob
{
private $container;
private $systemUtil;
protected $cronFile = 'cron.php';
@@ -53,10 +59,17 @@ class ScheduledJob
'default' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1',
];
public function __construct(\Espo\Core\Container $container)
protected $classFinder;
protected $language;
protected $entityManager;
public function __construct(ClassFinder $classFinder, EntityManager $entityManager, Language $language)
{
$this->container = $container;
$this->systemUtil = new \Espo\Core\Utils\System();
$this->classFinder = $classFinder;
$this->entityManager = $entityManager;
$this->language = $language;
$this->systemUtil = new System();
}
protected function getContainer()
@@ -64,11 +77,6 @@ class ScheduledJob
return $this->container;
}
protected function getEntityManager()
{
return $this->container->get('entityManager');
}
protected function getSystemUtil()
{
return $this->systemUtil;
@@ -76,7 +84,7 @@ class ScheduledJob
public function getAvailableList()
{
$map = $this->getContainer()->get('classFinder')->getMap('Jobs');
$map = $this->classFinder->getMap('Jobs');
$list = array_keys($map);
return $list;
}
@@ -84,13 +92,13 @@ class ScheduledJob
public function getJobClassName(string $name) : ?string
{
$name = ucfirst($name);
$className = $this->getContainer()->get('classFinder')->find('Jobs', $name);
$className = $this->classFinder->find('Jobs', $name);
return $className;
}
public function getSetupMessage()
{
$language = $this->getContainer()->get('language');
$language = $this->language;
$OS = $this->getSystemUtil()->getOS();
$desc = $language->translate('cronSetup', 'options', 'ScheduledJob');
@@ -143,12 +151,12 @@ class ScheduledJob
[
['executeTime>=' => $r1From->format($format)],
['executeTime<='=> $r1To->format($format)],
'scheduledJob.job' => 'Dummy'
'scheduledJob.job' => 'Dummy',
]
]
]
];
return !!$this->getEntityManager()->getRepository('Job')->findOne($selectParams);
return !!$this->entityManager->getRepository('Job')->findOne($selectParams);
}
}
@@ -29,11 +29,13 @@
namespace Espo\Core\WebSocket;
use Espo\Core\Utils\Config;
class Submission
{
protected $config;
public function __construct(\Espo\Core\Utils\Config $config)
public function __construct(Config $config)
{
$this->config = $config;
}
+11 -5
View File
@@ -29,7 +29,13 @@
namespace Espo\Core\Webhook;
use Espo\ORM\Entity;
use Espo\Core\{
Utils\Config,
Utils\File\Manager as FileManager,
Utils\FieldManagerUtil,
ORM\EntityManager,
ORM\Entity,
};
class Manager
{
@@ -45,10 +51,10 @@ class Manager
private $data = null;
public function __construct(
\Espo\Core\Utils\Config $config,
\Espo\Core\Utils\File\Manager $fileManager,
\Espo\ORM\EntityManager $entityManager,
\Espo\Core\Utils\FieldManagerUtil $fieldManager
Config $config,
FileManager $fileManager,
EntityManager $entityManager,
FieldManagerUtil $fieldManager
) {
$this->config = $config;
$this->fileManager = $fileManager;
@@ -1,4 +1,37 @@
{
"slim": {
"className": "Espo\\Core\\Utils\\Api\\Slim"
},
"output": {
"className": "Espo\\Core\\Utils\\Api\\Output"
},
"schema": {
"className": "Espo\\Core\\Utils\\Database\\Schema\\Schema"
},
"ormMetadata": {
"className": "Espo\\Core\\Utils\\Metadata\\OrmMetadata"
},
"classParser": {
"className": "Espo\\Core\\Utils\\File\\ClassParser"
},
"classFinder": {
"className": "Espo\\Core\\Utils\\ClassFinder"
},
"crypt": {
"className": "Espo\\Core\\Utils\\Crypt"
},
"number": {
"loaderClassName": "Espo\\Core\\Loaders\\NumberUtil"
},
"controllerManager": {
"className": "Espo\\Core\\ControllerManager"
},
"scheduledJob": {
"className": "Espo\\Core\\Utils\\ScheduledJob"
},
"hookManager": {
"className": "Espo\\Core\\HookManager"
},
"notificatorFactory": {
"className": "Espo\\Core\\NotificatorFactory"
},
@@ -11,6 +44,36 @@
"themeManager": {
"className": "Espo\\Core\\Utils\\ThemeManager"
},
"fieldManager": {
"className": "Espo\\Core\\Utils\\FieldManager"
},
"fieldManagerUtil": {
"className": "Espo\\Core\\Utils\\FieldManagerUtil"
},
"mailSender": {
"className": "Espo\\Core\\Mail\\Sender"
},
"htmlizerFactory": {
"className": "Espo\\Core\\Htmlizer\\Factory"
},
"fieldValidatorManager": {
"className": "Espo\\Core\\Utils\\FieldValidatorManager"
},
"hasher": {
"className": "Espo\\Core\\Utils\\Hasher"
},
"authenticationFactory": {
"className": "Espo\\Core\\Utils\\Authentication\\Utils\\AuthenticationFactory"
},
"auth2FAFactory": {
"className": "Espo\\Core\\Utils\\Authentication\\TwoFA\\Utils\\Factory"
},
"auth2FAUserFactory": {
"className": "Espo\\Core\\Utils\\Authentication\\TwoFA\\Utils\\UserFactory"
},
"totp": {
"className": "Espo\\Core\\Utils\\Authentication\\TwoFA\\Utils\\Totp"
},
"user": {
"settable": true
}