mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
grand impromenets for customization abilities
This commit is contained in:
@@ -29,11 +29,11 @@
|
||||
|
||||
namespace Espo\Core;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
use \Espo\Entities\User;
|
||||
use \Espo\Core\Utils\Util;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class AclManager
|
||||
{
|
||||
@@ -49,6 +49,8 @@ class AclManager
|
||||
|
||||
protected $userAclClassName = '\\Espo\\Core\\Acl';
|
||||
|
||||
protected $baseImplementationClassName = '\\Espo\\Core\\Acl\\Base';
|
||||
|
||||
protected $globalRestricton;
|
||||
|
||||
public function __construct(Container $container)
|
||||
@@ -77,31 +79,22 @@ class AclManager
|
||||
public function getImplementation($scope)
|
||||
{
|
||||
if (empty($this->implementationHashMap[$scope])) {
|
||||
$normalizedName = Util::normilizeClassName($scope);
|
||||
$className = $this->getContainer()->get('classFinder')->find('Acl', $scope);
|
||||
|
||||
if (!$className) {
|
||||
$className = $this->baseImplementationClassName;
|
||||
}
|
||||
|
||||
$className = '\\Espo\\Custom\\Acl\\' . $normalizedName;
|
||||
if (!class_exists($className)) {
|
||||
$moduleName = $this->metadata->getScopeModuleName($scope);
|
||||
if ($moduleName) {
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\Acl\\' . $normalizedName;
|
||||
} else {
|
||||
$className = '\\Espo\\Acl\\' . $normalizedName;
|
||||
}
|
||||
if (!class_exists($className)) {
|
||||
$className = '\\Espo\\Core\\Acl\\Base';
|
||||
}
|
||||
throw new Error("{$className} does not exist.");
|
||||
}
|
||||
|
||||
if (class_exists($className)) {
|
||||
$acl = new $className($scope);
|
||||
$dependencyList = $acl->getDependencyList();
|
||||
foreach ($dependencyList as $name) {
|
||||
$acl->inject($name, $this->getContainer()->get($name));
|
||||
}
|
||||
$this->implementationHashMap[$scope] = $acl;
|
||||
} else {
|
||||
throw new Error();
|
||||
$acl = new $className($scope);
|
||||
$dependencyList = $acl->getDependencyList();
|
||||
foreach ($dependencyList as $name) {
|
||||
$acl->inject($name, $this->getContainer()->get($name));
|
||||
}
|
||||
$this->implementationHashMap[$scope] = $acl;
|
||||
}
|
||||
|
||||
return $this->implementationHashMap[$scope];
|
||||
|
||||
@@ -29,9 +29,11 @@
|
||||
|
||||
namespace Espo\Core;
|
||||
|
||||
/**
|
||||
* DI container. Lazy initialization is used. See https://docs.espocrm.com/development/di/.
|
||||
*/
|
||||
class Container
|
||||
{
|
||||
|
||||
private $data = [];
|
||||
|
||||
public function __construct()
|
||||
@@ -49,6 +51,11 @@ class Container
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setUser(\Espo\Entities\User $user)
|
||||
{
|
||||
$this->set('user', $user);
|
||||
}
|
||||
|
||||
protected function set($name, $obj)
|
||||
{
|
||||
$this->data[$name] = $obj;
|
||||
@@ -88,7 +95,7 @@ class Container
|
||||
|
||||
if ($className && class_exists($className)) {
|
||||
|
||||
$dependencyList = $metadata->get(['app', 'containerServices', $name, 'dependencyList']) ?? [];
|
||||
$dependencyList = $this->getServiceDependencyList($name);
|
||||
$dependencyObjectList = [];
|
||||
foreach ($dependencyList as $item) {
|
||||
$dependencyObjectList[] = $this->get($item);
|
||||
@@ -110,7 +117,12 @@ class Container
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getServiceClassName(string $name, ?string $default = null)
|
||||
protected function getServiceDependencyList(string $name) : array
|
||||
{
|
||||
return $this->get('metadata')->get(['app', 'containerServices', $name, 'dependencyList']) ?? [];
|
||||
}
|
||||
|
||||
protected function getServiceClassName(string $name, ?string $default = null)
|
||||
{
|
||||
$metadata = $this->get('metadata');
|
||||
|
||||
@@ -221,20 +233,6 @@ class Container
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadServiceFactory()
|
||||
{
|
||||
return new \Espo\Core\ServiceFactory(
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadNotificatorFactory()
|
||||
{
|
||||
return new \Espo\Core\NotificatorFactory(
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadMetadata()
|
||||
{
|
||||
return new \Espo\Core\Utils\Metadata(
|
||||
@@ -243,15 +241,6 @@ class Container
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadLayout()
|
||||
{
|
||||
return new \Espo\Core\Utils\Layout(
|
||||
$this->get('fileManager'),
|
||||
$this->get('metadata'),
|
||||
$this->get('user')
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadAclManager()
|
||||
{
|
||||
$className = $this->getServiceClassName('acl', '\\Espo\\Core\\AclManager');
|
||||
@@ -386,9 +375,4 @@ class Container
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
public function setUser(\Espo\Entities\User $user)
|
||||
{
|
||||
$this->set('user', $user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,15 +29,11 @@
|
||||
|
||||
namespace Espo\Core;
|
||||
|
||||
use \Espo\Core\Utils\Util;
|
||||
use \Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
|
||||
class ControllerManager
|
||||
{
|
||||
private $config;
|
||||
|
||||
private $metadata;
|
||||
|
||||
private $container;
|
||||
|
||||
private $controllersHash = null;
|
||||
@@ -46,41 +42,27 @@ class ControllerManager
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
$this->config = $this->container->get('config');
|
||||
$this->metadata = $this->container->get('metadata');
|
||||
|
||||
$this->controllersHash = (object) [];
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->config;
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
protected function getControllerClassName(string $name) : string
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
$className = $this->getContainer()->get('classFinder')->find('Controllers', $name);
|
||||
|
||||
protected function getControllerClassName($controllerName)
|
||||
{
|
||||
$customClassName = '\\Espo\\Custom\\Controllers\\' . Util::normilizeClassName($controllerName);
|
||||
if (class_exists($customClassName)) {
|
||||
$controllerClassName = $customClassName;
|
||||
} else {
|
||||
$moduleName = $this->metadata->getScopeModuleName($controllerName);
|
||||
if ($moduleName) {
|
||||
$controllerClassName = '\\Espo\\Modules\\' . $moduleName . '\\Controllers\\' . Util::normilizeClassName($controllerName);
|
||||
} else {
|
||||
$controllerClassName = '\\Espo\\Controllers\\' . Util::normilizeClassName($controllerName);
|
||||
}
|
||||
if (!$className) {
|
||||
throw new NotFound("Controller '{$name}' does not exist.");
|
||||
}
|
||||
|
||||
if (!class_exists($controllerClassName)) {
|
||||
throw new NotFound("Controller '$controllerName' is not found");
|
||||
if (!class_exists($className)) {
|
||||
throw new NotFound("Class not found for controller '{$name}'.");
|
||||
}
|
||||
|
||||
return $controllerClassName;
|
||||
return $className;
|
||||
}
|
||||
|
||||
public function createController($name)
|
||||
@@ -129,9 +111,12 @@ class ControllerManager
|
||||
throw new NotFound("Action {$requestMethod} '{$actionName}' does not exist in controller '".$controller->getName()."'.");
|
||||
}
|
||||
|
||||
// TODO Remove in 5.1.0
|
||||
// TODO Remove in 6.0.0
|
||||
if ($data instanceof \stdClass) {
|
||||
if ($this->getMetadata()->get(['app', 'deprecatedControllerActions', $controller->getName(), $primaryActionMethodName])) {
|
||||
if (
|
||||
$this->container->get('metadata')->get(
|
||||
['app', 'deprecatedControllerActions', $controller->getName(), $primaryActionMethodName])
|
||||
) {
|
||||
$data = get_object_vars($data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ class CronManager
|
||||
{
|
||||
$jobName = $job->get('scheduledJobJob');
|
||||
|
||||
$className = $this->getScheduledJobUtil()->get($jobName);
|
||||
$className = $this->getScheduledJobUtil()->getJobClassName($jobName);
|
||||
|
||||
if ($className === false) throw new Error("No class name for job {$jobName}.");
|
||||
|
||||
@@ -386,7 +386,7 @@ class CronManager
|
||||
{
|
||||
$jobName = $job->get('job');
|
||||
|
||||
$className = $this->getScheduledJobUtil()->get($jobName);
|
||||
$className = $this->getScheduledJobUtil()->getJobClassName($jobName);
|
||||
|
||||
if ($className === false) throw new Error("No class name for job {$jobName}.");
|
||||
|
||||
@@ -430,7 +430,7 @@ class CronManager
|
||||
if ($existingJob) continue;
|
||||
}
|
||||
|
||||
$className = $this->getScheduledJobUtil()->get($scheduledJob->get('job'));
|
||||
$className = $this->getScheduledJobUtil()->getJobClassName($scheduledJob->get('job'));
|
||||
if ($className) {
|
||||
if (method_exists($className, 'prepare')) {
|
||||
$implementation = new $className($this->container);
|
||||
|
||||
@@ -36,29 +36,9 @@ class EntryPointManager
|
||||
{
|
||||
private $container;
|
||||
|
||||
private $fileManager;
|
||||
|
||||
protected $data = null;
|
||||
|
||||
protected $cacheFile = 'data/cache/application/entryPoints.php';
|
||||
|
||||
protected $allowedMethods = [
|
||||
'run',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array - path to entryPoint files
|
||||
*/
|
||||
private $paths = [
|
||||
'corePath' => 'application/Espo/EntryPoints',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/EntryPoints',
|
||||
'customPath' => 'custom/Espo/Custom/EntryPoints',
|
||||
];
|
||||
|
||||
public function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->fileManager = $container->get('fileManager');
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
@@ -66,21 +46,18 @@ class EntryPointManager
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
|
||||
public function checkAuthRequired($name)
|
||||
public function checkAuthRequired(string $name) : bool
|
||||
{
|
||||
$className = $this->getClassName($name);
|
||||
if (!$className) {
|
||||
echo $name;
|
||||
die;
|
||||
throw new NotFound();
|
||||
}
|
||||
return $className::$authRequired;
|
||||
}
|
||||
|
||||
public function checkNotStrictAuth($name)
|
||||
public function checkNotStrictAuth(string $name) : bool
|
||||
{
|
||||
$className = $this->getClassName($name);
|
||||
if (!$className) {
|
||||
@@ -89,7 +66,7 @@ class EntryPointManager
|
||||
return $className::$notStrictAuth;
|
||||
}
|
||||
|
||||
public function run($name, $data = array())
|
||||
public function run(string $name, array $data = [])
|
||||
{
|
||||
$className = $this->getClassName($name);
|
||||
if (!$className) {
|
||||
@@ -100,25 +77,9 @@ class EntryPointManager
|
||||
$entryPoint->run($data);
|
||||
}
|
||||
|
||||
protected function getClassName($name)
|
||||
protected function getClassName(string $name) : ?string
|
||||
{
|
||||
$name = Util::normilizeClassName($name);
|
||||
|
||||
if (!isset($this->data)) {
|
||||
$this->init();
|
||||
}
|
||||
|
||||
$name = ucfirst($name);
|
||||
if (isset($this->data[$name])) {
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$classParser = $this->getContainer()->get('classParser');
|
||||
$this->data = $classParser->getData($this->paths, $this->cacheFile, $this->allowedMethods);
|
||||
return $this->getContainer()->get('classFinder')->find('EntryPoints', $name);
|
||||
}
|
||||
}
|
||||
|
||||
40
application/Espo/Core/Loaders/NotificatorFactory.php
Normal file
40
application/Espo/Core/Loaders/NotificatorFactory.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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 NotificatorFactory extends Base
|
||||
{
|
||||
public function load()
|
||||
{
|
||||
return new \Espo\Core\NotificatorFactory(
|
||||
$this->getContainer()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,8 @@ class SelectManagerFactory extends Base
|
||||
$this->getContainer()->get('metadata'),
|
||||
$this->getContainer()->get('config'),
|
||||
$this->getContainer()->get('fieldManagerUtil'),
|
||||
$this->getContainer()->get('injectableFactory')
|
||||
$this->getContainer()->get('injectableFactory'),
|
||||
$this->getContainer()->get('classFinder')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
40
application/Espo/Core/Loaders/ServiceFactory.php
Normal file
40
application/Espo/Core/Loaders/ServiceFactory.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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 ServiceFactory extends Base
|
||||
{
|
||||
public function load()
|
||||
{
|
||||
return new \Espo\Core\ServiceFactory(
|
||||
$this->getContainer()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -29,28 +29,20 @@
|
||||
|
||||
namespace Espo\Core;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
|
||||
use \Espo\Core\Utils\Util;
|
||||
use \Espo\Core\InjectableFactory;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\Notificators\Base as BaseNotificator;
|
||||
|
||||
class NotificatorFactory extends InjectableFactory
|
||||
{
|
||||
public function create($entityType)
|
||||
{
|
||||
$normalizedName = Util::normilizeClassName($entityType);
|
||||
protected $baseClassName = '\\Espo\\Core\\Notificators\\Base';
|
||||
|
||||
$className = '\\Espo\\Custom\\Notificators\\' . $normalizedName;
|
||||
if (!class_exists($className)) {
|
||||
$moduleName = $this->getMetadata()->getScopeModuleName($entityType);
|
||||
if ($moduleName) {
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\Notificators\\' . $normalizedName;
|
||||
} else {
|
||||
$className = '\\Espo\\Notificators\\' . $normalizedName;
|
||||
}
|
||||
if (!class_exists($className)) {
|
||||
$className = '\\Espo\\Core\\Notificators\\Base';
|
||||
}
|
||||
public function create(string $entityType) : BaseNotificator
|
||||
{
|
||||
$className = $this->getContainer()->get('classFinder')->find('Notificators', $entityType);
|
||||
|
||||
if (!$className || !class_exists($className)) {
|
||||
$className = $this->baseClassName;
|
||||
}
|
||||
|
||||
$obj = $this->createByClassName($className);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace Espo\Core\ORM;
|
||||
|
||||
use \Espo\Core\Utils\Util;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class EntityManager extends \Espo\ORM\EntityManager
|
||||
{
|
||||
@@ -87,26 +87,18 @@ class EntityManager extends \Espo\ORM\EntityManager
|
||||
return $this->hookManager;
|
||||
}
|
||||
|
||||
public function normalizeRepositoryName($name)
|
||||
public function getRepositoryClassName($name)
|
||||
{
|
||||
if (empty($this->repositoryClassNameHash[$name])) {
|
||||
$className = '\\Espo\\Custom\\Repositories\\' . Util::normilizeClassName($name);
|
||||
if (!class_exists($className)) {
|
||||
$className = $this->espoMetadata->getRepositoryPath($name);
|
||||
}
|
||||
$this->repositoryClassNameHash[$name] = $className;
|
||||
if (!array_key_exists($name, $this->repositoryClassNameHash)) {
|
||||
$this->repositoryClassNameHash[$name] = $this->getContainer()->get('classFinder')->find('Repositories', $name);
|
||||
}
|
||||
return $this->repositoryClassNameHash[$name];
|
||||
}
|
||||
|
||||
public function normalizeEntityName($name)
|
||||
public function getEntityClassName($name)
|
||||
{
|
||||
if (empty($this->entityClassNameHash[$name])) {
|
||||
$className = '\\Espo\\Custom\\Entities\\' . Util::normilizeClassName($name);
|
||||
if (!class_exists($className)) {
|
||||
$className = $this->espoMetadata->getEntityPath($name);
|
||||
}
|
||||
$this->entityClassNameHash[$name] = $className;
|
||||
if (!array_key_exists($name, $this->entityClassNameHash)) {
|
||||
$this->entityClassNameHash[$name] = $this->getContainer()->get('classFinder')->find('Entities', $name);
|
||||
}
|
||||
return $this->entityClassNameHash[$name];
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
|
||||
namespace Espo\Core\Portal;
|
||||
|
||||
use \Espo\ORM\Entity;
|
||||
use \Espo\Entities\User;
|
||||
use \Espo\Core\Utils\Util;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class AclManager extends \Espo\Core\AclManager
|
||||
{
|
||||
@@ -43,34 +43,27 @@ class AclManager extends \Espo\Core\AclManager
|
||||
|
||||
protected $userAclClassName = '\\Espo\\Core\\Portal\\Acl';
|
||||
|
||||
protected $baseImplementationClassName = '\\Espo\\Core\\AclPortal\\Base';
|
||||
|
||||
public function getImplementation($scope)
|
||||
{
|
||||
if (empty($this->implementationHashMap[$scope])) {
|
||||
$normalizedName = Util::normilizeClassName($scope);
|
||||
$className = $this->getContainer()->get('classFinder')->find('AclPortal', $scope);
|
||||
|
||||
if (!$className) {
|
||||
$className = $this->baseImplementationClassName;
|
||||
}
|
||||
|
||||
$className = '\\Espo\\Custom\\AclPortal\\' . $normalizedName;
|
||||
if (!class_exists($className)) {
|
||||
$moduleName = $this->getMetadata()->getScopeModuleName($scope);
|
||||
if ($moduleName) {
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\AclPortal\\' . $normalizedName;
|
||||
} else {
|
||||
$className = '\\Espo\\AclPortal\\' . $normalizedName;
|
||||
}
|
||||
if (!class_exists($className)) {
|
||||
$className = '\\Espo\\Core\\AclPortal\\Base';
|
||||
}
|
||||
throw new Error("{$className} does not exist.");
|
||||
}
|
||||
|
||||
if (class_exists($className)) {
|
||||
$acl = new $className($scope);
|
||||
$dependencyList = $acl->getDependencyList();
|
||||
foreach ($dependencyList as $name) {
|
||||
$acl->inject($name, $this->getContainer()->get($name));
|
||||
}
|
||||
$this->implementationHashMap[$scope] = $acl;
|
||||
} else {
|
||||
throw new Error();
|
||||
$acl = new $className($scope);
|
||||
$dependencyList = $acl->getDependencyList();
|
||||
foreach ($dependencyList as $name) {
|
||||
$acl->inject($name, $this->getContainer()->get($name));
|
||||
}
|
||||
$this->implementationHashMap[$scope] = $acl;
|
||||
}
|
||||
|
||||
return $this->implementationHashMap[$scope];
|
||||
@@ -113,7 +106,8 @@ class AclManager extends \Espo\Core\AclManager
|
||||
$fieldManager = $this->getContainer()->get('fieldManagerUtil');
|
||||
$portal = $this->getPortal();
|
||||
|
||||
$this->tableHashMap[$key] = new $this->tableClassName($user, $portal, $config, $fileManager, $metadata, $fieldManager);
|
||||
$this->tableHashMap[$key] = new $this->tableClassName(
|
||||
$user, $portal, $config, $fileManager, $metadata, $fieldManager);
|
||||
}
|
||||
|
||||
return $this->tableHashMap[$key];
|
||||
|
||||
@@ -31,12 +31,24 @@ namespace Espo\Core\Portal;
|
||||
|
||||
class Container extends \Espo\Core\Container
|
||||
{
|
||||
public function getServicePortalClassName(string $name, ?string $default = null)
|
||||
protected function getServiceClassName(string $name, ?string $default = null)
|
||||
{
|
||||
return $this->get('metadata')->get(['app', 'portalContainerServices', $name, 'className']) ??
|
||||
parent::getServiceClassName($name, $default);
|
||||
}
|
||||
|
||||
protected function getServicePortalClassName(string $name, ?string $default = null)
|
||||
{
|
||||
$metadata = $this->get('metadata');
|
||||
return $metadata->get(['app', 'portalContainerServices', $name, 'className'], $default);
|
||||
}
|
||||
|
||||
protected function getServiceDependencyList(string $name) : array
|
||||
{
|
||||
return $this->get('metadata')->get(['app', 'portalContainerServices', $name, 'dependencyList']) ??
|
||||
parent::getServiceDependencyList($name);
|
||||
}
|
||||
|
||||
protected function getServiceMainClassName(string $name, ?string $default = null)
|
||||
{
|
||||
return parent::getServiceClassName($name, $default);
|
||||
@@ -76,15 +88,6 @@ class Container extends \Espo\Core\Container
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadLayout()
|
||||
{
|
||||
return new \Espo\Core\Portal\Utils\Layout(
|
||||
$this->get('fileManager'),
|
||||
$this->get('metadata'),
|
||||
$this->get('user')
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadLanguage()
|
||||
{
|
||||
$language = new \Espo\Core\Portal\Utils\Language(
|
||||
|
||||
@@ -29,10 +29,13 @@
|
||||
|
||||
namespace Espo\Core;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use \Espo\Core\Utils\Util;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
use \Espo\Core\InjectableFactory;
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\SelectManagers\Base as BaseSelectManager;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
|
||||
class SelectManagerFactory
|
||||
{
|
||||
@@ -46,18 +49,22 @@ class SelectManagerFactory
|
||||
|
||||
private $injectableFactory;
|
||||
|
||||
private $FieldManagerUtil;
|
||||
private $fieldManagerUtil;
|
||||
|
||||
private $classFinder;
|
||||
|
||||
protected $baseClassName = '\\Espo\\Core\\SelectManagers\\Base';
|
||||
|
||||
public function __construct(
|
||||
$entityManager,
|
||||
\Espo\Entities\User $user,
|
||||
EntityManager $entityManager,
|
||||
User $user,
|
||||
Acl $acl,
|
||||
AclManager $aclManager,
|
||||
Utils\Metadata $metadata,
|
||||
Utils\Config $config,
|
||||
Utils\FieldManagerUtil $fieldManagerUtil,
|
||||
InjectableFactory $injectableFactory
|
||||
)
|
||||
InjectableFactory $injectableFactory,
|
||||
Utils\ClassFinder $classFinder)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->user = $user;
|
||||
@@ -67,23 +74,15 @@ class SelectManagerFactory
|
||||
$this->config = $config;
|
||||
$this->fieldManagerUtil = $fieldManagerUtil;
|
||||
$this->injectableFactory = $injectableFactory;
|
||||
$this->classFinder = $classFinder;
|
||||
}
|
||||
|
||||
public function create(string $entityType, ?\Espo\Entities\User $user = null) : \Espo\Core\SelectManagers\Base
|
||||
public function create(string $entityType, ?User $user = null) : BaseSelectManager
|
||||
{
|
||||
$normalizedName = Util::normilizeClassName($entityType);
|
||||
$className = $this->classFinder->find('SelectManagers', $entityType);
|
||||
|
||||
$className = '\\Espo\\Custom\\SelectManagers\\' . $normalizedName;
|
||||
if (!class_exists($className)) {
|
||||
$moduleName = $this->metadata->getScopeModuleName($entityType);
|
||||
if ($moduleName) {
|
||||
$className = '\\Espo\\Modules\\' . $moduleName . '\\SelectManagers\\' . $normalizedName;
|
||||
} else {
|
||||
$className = '\\Espo\\SelectManagers\\' . $normalizedName;
|
||||
}
|
||||
if (!class_exists($className)) {
|
||||
$className = '\\Espo\\Core\\SelectManagers\\Base';
|
||||
}
|
||||
if (!$className || !class_exists($className)) {
|
||||
$className = $this->baseClassName;
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
|
||||
@@ -51,17 +51,29 @@ class ClassFinder
|
||||
*/
|
||||
public function find(string $category, string $name) : ?string
|
||||
{
|
||||
if (!array_key_exists($category, $this->dataHash)) {
|
||||
$path = $this->buildPaths($category);
|
||||
$cacheFile = $this->buildCacheFilePath($category);
|
||||
$this->dataHash[$category] = $this->classParser->getData($path, $cacheFile);
|
||||
}
|
||||
|
||||
$className = $this->dataHash[$category][$name] ?? null;
|
||||
|
||||
$map = $this->getMap($category);
|
||||
$className = $map[$name] ?? null;
|
||||
return $className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [name => class-name] map.
|
||||
*/
|
||||
public function getMap(string $category) : array
|
||||
{
|
||||
if (!array_key_exists($category, $this->dataHash)) {
|
||||
$this->load($category);
|
||||
}
|
||||
return $this->dataHash[$category] ?? [];
|
||||
}
|
||||
|
||||
protected function load(string $category)
|
||||
{
|
||||
$path = $this->buildPaths($category);
|
||||
$cacheFile = $this->buildCacheFilePath($category);
|
||||
$this->dataHash[$category] = $this->classParser->getData($path, $cacheFile);
|
||||
}
|
||||
|
||||
protected function buildPaths(string $category) : array
|
||||
{
|
||||
$paths = [];
|
||||
@@ -73,7 +85,7 @@ class ClassFinder
|
||||
|
||||
protected function buildCacheFilePath(string $category) : string
|
||||
{
|
||||
$path = 'data/cache/application/' . str_replace('/', '_', strtolower($category)) . '.php';
|
||||
$path = 'data/cache/application/classmap_' . str_replace('/', '_', strtolower($category)) . '.php';
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,28 +567,6 @@ class Metadata
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Entity path, ex. Espo.Entities.Account or Modules\Crm\Entities\MyModule
|
||||
*
|
||||
* @param string $entityName
|
||||
* @param bool $delim - delimiter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEntityPath($entityName, $delim = '\\')
|
||||
{
|
||||
$path = $this->getScopePath($entityName, $delim);
|
||||
|
||||
return implode($delim, array($path, 'Entities', Util::normilizeClassName(ucfirst($entityName))));
|
||||
}
|
||||
|
||||
public function getRepositoryPath($entityName, $delim = '\\')
|
||||
{
|
||||
$path = $this->getScopePath($entityName, $delim);
|
||||
|
||||
return implode($delim, array($path, 'Repositories', Util::normilizeClassName(ucfirst($entityName))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load modules
|
||||
*
|
||||
@@ -638,27 +616,6 @@ class Metadata
|
||||
return $this->get('scopes.' . $scopeName . '.module', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Scope path, ex. "Modules/Crm" for Account
|
||||
*
|
||||
* @param string $scopeName
|
||||
* @param string $delim - delimiter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getScopePath($scopeName, $delim = '/')
|
||||
{
|
||||
$moduleName = $this->getScopeModuleName($scopeName);
|
||||
|
||||
$path = ($moduleName !== false) ? 'Espo/Modules/'.$moduleName : 'Espo';
|
||||
|
||||
if ($delim != '/') {
|
||||
$path = str_replace('/', $delim, $path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear metadata variables when reload meta
|
||||
*
|
||||
|
||||
@@ -37,14 +37,8 @@ class ScheduledJob
|
||||
|
||||
private $systemUtil;
|
||||
|
||||
protected $data = null;
|
||||
|
||||
protected $cacheFile = 'data/cache/application/jobs.php';
|
||||
|
||||
protected $cronFile = 'cron.php';
|
||||
|
||||
protected $allowedMethod = 'run';
|
||||
|
||||
/**
|
||||
* Period to check if crontab is configured properly
|
||||
*
|
||||
@@ -52,15 +46,6 @@ class ScheduledJob
|
||||
*/
|
||||
protected $checkingCronPeriod = '25 hours';
|
||||
|
||||
/**
|
||||
* @var array - path to cron job files
|
||||
*/
|
||||
private $paths = [
|
||||
'corePath' => 'application/Espo/Jobs',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/Jobs',
|
||||
'customPath' => 'custom/Espo/Custom/Jobs',
|
||||
];
|
||||
|
||||
protected $cronSetup = [
|
||||
'linux' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1',
|
||||
'windows' => '{PHP-BINARY} -f {FULL-CRON-PATH}',
|
||||
@@ -89,87 +74,18 @@ class ScheduledJob
|
||||
return $this->systemUtil;
|
||||
}
|
||||
|
||||
public function getMethodName()
|
||||
{
|
||||
return $this->allowedMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of all jobs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
if (!isset($this->data)) {
|
||||
$this->init();
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class name of a job by name
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
return $this->getClassName($name);
|
||||
}
|
||||
|
||||
public function getAvailableList()
|
||||
{
|
||||
$data = $this->getAll();
|
||||
|
||||
$list = array_keys($data);
|
||||
|
||||
$map = $this->getContainer()->get('classFinder')->getMap('Jobs');
|
||||
$list = array_keys($map);
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of all job names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllNamesOnly()
|
||||
public function getJobClassName(string $name) : ?string
|
||||
{
|
||||
$data = $this->getAll();
|
||||
|
||||
$namesOnly = array_keys($data);
|
||||
|
||||
return $namesOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class name of a job
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function getClassName($name)
|
||||
{
|
||||
$name = Util::normilizeClassName($name);
|
||||
|
||||
$data = $this->getAll();
|
||||
|
||||
$name = ucfirst($name);
|
||||
if (isset($data[$name])) {
|
||||
return $data[$name];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load scheduler classes. It loads from ...Jobs, ex. \Espo\Jobs
|
||||
* @return null
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$classParser = $this->getContainer()->get('classParser');
|
||||
$this->data = $classParser->getData($this->paths, $this->cacheFile, [$this->allowedMethod]);
|
||||
$className = $this->getContainer()->get('classFinder')->find('Jobs', $name);
|
||||
return $className;
|
||||
}
|
||||
|
||||
public function getSetupMessage()
|
||||
@@ -194,14 +110,14 @@ class ScheduledJob
|
||||
$command = str_replace('{'.$name.'}', $value, $command);
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
'message' => $message,
|
||||
'command' => $command,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if crontab is configured properly
|
||||
* Check if crontab is configured properly.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@@ -233,7 +149,6 @@ class ScheduledJob
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
return !!$this->getEntityManager()->getRepository('Job')->findOne($selectParams);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,10 @@ class EntityFactory
|
||||
$this->entityManager = $entityManager;
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
|
||||
public function create($name)
|
||||
{
|
||||
$className = $this->entityManager->normalizeEntityName($name);
|
||||
$className = $this->entityManager->getEntityClassName($name);
|
||||
if (!class_exists($className)) {
|
||||
return null;
|
||||
}
|
||||
@@ -53,6 +54,4 @@ class EntityFactory
|
||||
$entity = new $className($defs, $this->entityManager);
|
||||
return $entity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace Espo\ORM;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class EntityManager
|
||||
{
|
||||
@@ -234,12 +234,12 @@ class EntityManager
|
||||
return $this->pdo;
|
||||
}
|
||||
|
||||
public function normalizeRepositoryName($name)
|
||||
public function getRepositoryClassName($name)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function normalizeEntityName($name)
|
||||
public function getEntityClassName($name)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class RepositoryFactory
|
||||
|
||||
public function create($name)
|
||||
{
|
||||
$className = $this->entityManager->normalizeRepositoryName($name);
|
||||
$className = $this->entityManager->getRepositoryClassName($name);
|
||||
|
||||
if (!class_exists($className)) {
|
||||
$className = $this->defaultRepositoryClassName;
|
||||
@@ -55,11 +55,6 @@ class RepositoryFactory
|
||||
return $repository;
|
||||
}
|
||||
|
||||
protected function normalizeName($name)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function setDefaultRepositoryClassName($defaultRepositoryClassName)
|
||||
{
|
||||
$this->defaultRepositoryClassName = $defaultRepositoryClassName;
|
||||
|
||||
@@ -2,5 +2,9 @@
|
||||
"clientManager": {
|
||||
"className": "\\Espo\\Core\\Utils\\ClientManager",
|
||||
"dependencyList": ["config", "themeManager", "metadata"]
|
||||
},
|
||||
"layout": {
|
||||
"className": "\\Espo\\Core\\Utils\\Layout",
|
||||
"dependencyList": ["fileManager", "metadata", "user"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"layout": {
|
||||
"className": "\\Espo\\Core\\Portal\\Utils\\Layout",
|
||||
"dependencyList": ["fileManager", "metadata", "user"]
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,6 @@ class ClassFinder extends \tests\integration\Core\BaseTestCase
|
||||
$classFinder->find('Services', 'Record')
|
||||
);
|
||||
|
||||
$this->assertTrue(file_exists('data/cache/application/services.php'));
|
||||
$this->assertTrue(file_exists('data/cache/application/classmap_services.php'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user