remove deprecated injectable and base classes

This commit is contained in:
Yuri Kuznetsov
2024-11-09 13:32:41 +02:00
parent 7a09f08484
commit 39f018d99b
13 changed files with 1 additions and 1197 deletions
-37
View File
@@ -1,37 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Acl;
/**
* @deprecated As of v7.0. Use AccessChecker interfaces instead.
* @see https://docs.espocrm.com/development/metadata/acl-defs/
*/
class Acl extends Base
{}
-188
View File
@@ -1,188 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Acl;
use Espo\Core\Interfaces\Injectable;
use Espo\ORM\Entity;
use Espo\Entities\User;
use Espo\Core\Acl\AccessChecker\ScopeChecker;
use Espo\Core\Acl\AccessChecker\ScopeCheckerData;
use Espo\Core\AclManager;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Utils\Config;
/**
* @deprecated As of v6.0. Use AccessChecker interfaces instead.
* @see https://docs.espocrm.com/development/metadata/acl-defs/
*/
class Base implements AccessChecker, Injectable
{
protected $dependencyList = []; /** @phpstan-ignore-line */
protected $dependencies = []; /** @phpstan-ignore-line */
protected $injections = []; /** @phpstan-ignore-line */
protected $entityManager; /** @phpstan-ignore-line */
protected $aclManager; /** @phpstan-ignore-line */
protected $config; /** @phpstan-ignore-line */
protected $defaultChecker; /** @phpstan-ignore-line */
protected $scopeChecker; /** @phpstan-ignore-line */
public function __construct(
EntityManager $entityManager,
AclManager $aclManager,
Config $config,
DefaultAccessChecker $defaultChecker,
ScopeChecker $scopeChecker
) {
$this->entityManager = $entityManager;
$this->aclManager = $aclManager;
$this->config = $config;
$this->defaultChecker = $defaultChecker;
$this->scopeChecker = $scopeChecker;
$this->init();
}
public function check(User $user, ScopeData $data): bool
{
return $this->defaultChecker->check($user, $data);
}
public function checkEntity(User $user, Entity $entity, ScopeData $data, string $action): bool
{
$checkerData = ScopeCheckerData
::createBuilder()
->setIsOwnChecker(
function () use ($user, $entity): bool {
return (bool) $this->checkIsOwner($user, $entity);
}
)
->setInTeamChecker(
function () use ($user, $entity): bool {
return (bool) $this->checkInTeam($user, $entity);
}
)
->build();
return $this->scopeChecker->check($data, $action, $checkerData);
}
public function checkScope(User $user, ScopeData $data, ?string $action = null): bool
{
if (!$action) {
return $this->defaultChecker->check($user, $data);
}
if ($action === Table::ACTION_CREATE) {
return $this->defaultChecker->checkCreate($user, $data);
}
if ($action === Table::ACTION_READ) {
return $this->defaultChecker->checkRead($user, $data);
}
if ($action === Table::ACTION_EDIT) {
return $this->defaultChecker->checkEdit($user, $data);
}
if ($action === Table::ACTION_DELETE) {
return $this->defaultChecker->checkDelete($user, $data);
}
if ($action === Table::ACTION_STREAM) {
return $this->defaultChecker->checkStream($user, $data);
}
return false;
}
public function checkIsOwner(User $user, Entity $entity) /** @phpstan-ignore-line */
{
return $this->aclManager->checkOwnershipOwn($user, $entity);
}
public function checkInTeam(User $user, Entity $entity) /** @phpstan-ignore-line */
{
return $this->aclManager->checkOwnershipTeam($user, $entity);
}
public function inject($name, $object) /** @phpstan-ignore-line */
{
$this->injections[$name] = $object;
}
protected function init() /** @phpstan-ignore-line */
{
}
protected function getInjection($name) /** @phpstan-ignore-line */
{
return $this->injections[$name] ?? $this->$name ?? null;
}
protected function addDependencyList(array $list) /** @phpstan-ignore-line */
{
foreach ($list as $item) {
$this->addDependency($item);
}
}
protected function addDependency($name) /** @phpstan-ignore-line */
{
$this->dependencyList[] = $name;
}
public function getDependencyList() /** @phpstan-ignore-line */
{
return array_merge($this->dependencyList, $this->dependencies);
}
protected function getConfig(): Config
{
return $this->config;
}
protected function getEntityManager(): EntityManager
{
return $this->entityManager;
}
protected function getAclManager(): AclManager
{
return $this->aclManager;
}
}
-38
View File
@@ -1,38 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\AclPortal;
/**
* @deprecated Use AccessChecker interfaces instead.
*/
class Acl extends Base
{
}
-201
View File
@@ -1,201 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\AclPortal;
use Espo\Core\Interfaces\Injectable;
use Espo\ORM\Entity;
use Espo\Entities\User;
use Espo\Core\AclManager;
use Espo\Core\Acl\AccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Portal\Acl\AccessChecker\ScopeChecker;
use Espo\Core\Portal\Acl\AccessChecker\ScopeCheckerData;
use Espo\Core\Portal\Acl\DefaultAccessChecker;
use Espo\Core\Portal\Acl\Table;
use Espo\Core\Portal\AclManager as PortalAclManager;
use Espo\Core\Utils\Config;
/**
* @deprecated Use AccessChecker interfaces instead.
*/
class Base implements AccessChecker, Injectable
{
protected $dependencyList = []; /** @phpstan-ignore-line */
protected $dependencies = []; /** @phpstan-ignore-line */
protected $injections = []; /** @phpstan-ignore-line */
protected $entityManager; /** @phpstan-ignore-line */
protected $aclManager; /** @phpstan-ignore-line */
protected $config; /** @phpstan-ignore-line */
protected $scopeChecker; /** @phpstan-ignore-line */
protected $defaultChecker; /** @phpstan-ignore-line */
public function __construct(
EntityManager $entityManager,
PortalAclManager $aclManager,
Config $config,
ScopeChecker $scopeChecker,
DefaultAccessChecker $defaultChecker
) {
$this->entityManager = $entityManager;
$this->aclManager = $aclManager;
$this->config = $config;
$this->scopeChecker = $scopeChecker;
$this->defaultChecker = $defaultChecker;
$this->init();
}
public function check(User $user, ScopeData $data): bool
{
return $this->defaultChecker->check($user, $data);
}
public function checkEntity(User $user, Entity $entity, ScopeData $data, string $action): bool
{
$checkerData = ScopeCheckerData
::createBuilder()
->setIsOwnChecker(
function () use ($user, $entity): bool {
return (bool) $this->checkIsOwner($user, $entity);
}
)
->setInAccountChecker(
function () use ($user, $entity): bool {
return (bool) $this->checkInAccount($user, $entity);
}
)
->setInContactChecker(
function () use ($user, $entity): bool {
return (bool) $this->checkIsOwnContact($user, $entity);
}
)
->build();
return $this->scopeChecker->check($data, $action, $checkerData);
}
public function checkScope(User $user, ScopeData $data, ?string $action = null): bool
{
if (!$action) {
return $this->defaultChecker->check($user, $data);
}
if ($action === Table::ACTION_CREATE) {
return $this->defaultChecker->checkCreate($user, $data);
}
if ($action === Table::ACTION_READ) {
return $this->defaultChecker->checkRead($user, $data);
}
if ($action === Table::ACTION_EDIT) {
return $this->defaultChecker->checkEdit($user, $data);
}
if ($action === Table::ACTION_DELETE) {
return $this->defaultChecker->checkDelete($user, $data);
}
if ($action === Table::ACTION_STREAM) {
return $this->defaultChecker->checkStream($user, $data);
}
return false;
}
public function checkIsOwner(User $user, Entity $entity) /** @phpstan-ignore-line */
{
return $this->aclManager->checkOwnershipOwn($user, $entity);
}
public function checkInAccount(User $user, Entity $entity) /** @phpstan-ignore-line */
{
return $this->aclManager->checkOwnershipAccount($user, $entity);
}
public function checkIsOwnContact(User $user, Entity $entity) /** @phpstan-ignore-line */
{
return $this->aclManager->checkOwnershipContact($user, $entity);
}
protected function getConfig(): Config
{
return $this->config;
}
protected function getEntityManager(): EntityManager
{
return $this->entityManager;
}
protected function getAclManager(): AclManager
{
return $this->aclManager;
}
public function inject($name, $object) /** @phpstan-ignore-line */
{
$this->injections[$name] = $object;
}
protected function init() /** @phpstan-ignore-line */
{
}
protected function getInjection($name) /** @phpstan-ignore-line */
{
return $this->injections[$name] ?? $this->$name ?? null;
}
protected function addDependencyList(array $list) /** @phpstan-ignore-line */
{
foreach ($list as $item) {
$this->addDependency($item);
}
}
protected function addDependency($name) /** @phpstan-ignore-line */
{
$this->dependencyList[] = $name;
}
public function getDependencyList() /** @phpstan-ignore-line */
{
return array_merge($this->dependencyList, $this->dependencies);
}
}
-64
View File
@@ -1,64 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Cleanup;
/** @deprecated */
abstract class Base extends \Espo\Core\Injectable
{
protected function init() /** @phpstan-ignore-line */
{
$this->addDependency('config');
$this->addDependency('metadata');
$this->addDependency('entityManager');
$this->addDependency('fileManager');
}
protected function getConfig() /** @phpstan-ignore-line */
{
return $this->getInjection('config');
}
protected function getMetadata() /** @phpstan-ignore-line */
{
return $this->getInjection('metadata');
}
protected function getEntityManager() /** @phpstan-ignore-line */
{
return $this->getInjection('entityManager');
}
protected function getFileManager() /** @phpstan-ignore-line */
{
return $this->getInjection('fileManager');
}
abstract public function process(); /** @phpstan-ignore-line */
}
@@ -29,11 +29,8 @@
namespace Espo\Core\Formula\Functions;
use Espo\Core\Formula\Exceptions\Error;
use Espo\Core\Interfaces\Injectable;
use Espo\ORM\Entity;
use Espo\Core\Formula\Processor;
use Espo\Core\Formula\Argument;
@@ -42,7 +39,7 @@ use stdClass;
/**
* @deprecated Use BaseFunction instead.
*/
abstract class Base implements Injectable
abstract class Base
{
/**
* @var ?string
@@ -64,49 +61,12 @@ abstract class Base implements Injectable
*/
private $variables;
protected $dependencyList = []; /** @phpstan-ignore-line */
protected $injections = []; /** @phpstan-ignore-line */
public function inject($name, $object) /** @phpstan-ignore-line */
{
$this->injections[$name] = $object;
}
protected function getInjection($name) /** @phpstan-ignore-line */
{
return $this->injections[$name] ?? $this->$name ?? null;
}
protected function addDependency($name) /** @phpstan-ignore-line */
{
$this->dependencyList[] = $name;
}
protected function addDependencyList(array $list) /** @phpstan-ignore-line */
{
foreach ($list as $item) {
$this->addDependency($item);
}
}
public function getDependencyList() /** @phpstan-ignore-line */
{
return $this->dependencyList;
}
public function __construct(string $name, Processor $processor, ?Entity $entity = null, ?stdClass $variables = null)
{
$this->name = $name;
$this->processor = $processor;
$this->entity = $entity;
$this->variables = $variables;
$this->init();
}
protected function init() /** @phpstan-ignore-line */
{
}
protected function getVariables(): stdClass
-131
View File
@@ -1,131 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Hooks;
use Espo\Core\Interfaces\Injectable;
/**
* @deprecated As of v6.0. Not to be extended. Create plain classes with needed dependencies.
*/
abstract class Base implements Injectable
{
protected $injections = []; /** @phpstan-ignore-line */
public static $order = 9; /** @phpstan-ignore-line */
/** @phpstan-ignore-next-line */
protected $dependencyList = [
'container',
'entityManager',
'config',
'metadata',
'aclManager',
'user',
'serviceFactory',
];
protected $dependencies = []; /** @phpstan-ignore-line */
public function __construct()
{
$this->init();
}
protected function init() /** @phpstan-ignore-line */
{
}
public function getDependencyList() /** @phpstan-ignore-line */
{
return array_merge($this->dependencyList, $this->dependencies);
}
protected function addDependencyList(array $list) /** @phpstan-ignore-line */
{
foreach ($list as $item) {
$this->addDependency($item);
}
}
protected function addDependency($name) /** @phpstan-ignore-line */
{
$this->dependencyList[] = $name;
}
protected function getInjection($name) /** @phpstan-ignore-line */
{
return $this->injections[$name] ?? $this->$name ?? null;
}
public function inject($name, $object) /** @phpstan-ignore-line */
{
$this->injections[$name] = $object;
}
protected function getContainer() /** @phpstan-ignore-line */
{
return $this->getInjection('container');
}
protected function getEntityManager() /** @phpstan-ignore-line */
{
return $this->getInjection('entityManager');
}
protected function getUser() /** @phpstan-ignore-line */
{
return $this->getInjection('user');
}
protected function getAcl() /** @phpstan-ignore-line */
{
return $this->getContainer()->get('acl');
}
protected function getAclManager() /** @phpstan-ignore-line */
{
return $this->getInjection('aclManager');
}
protected function getConfig() /** @phpstan-ignore-line */
{
return $this->getInjection('config');
}
protected function getMetadata() /** @phpstan-ignore-line */
{
return $this->getInjection('metadata');
}
protected function getServiceFactory() /** @phpstan-ignore-line */
{
return $this->getInjection('serviceFactory');
}
}
-88
View File
@@ -1,88 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core;
/**
* @deprecated As of v6.0. Use the dependency injection framework.
*/
abstract class Injectable implements \Espo\Core\Interfaces\Injectable
{
protected $dependencyList = []; /** @phpstan-ignore-line */
protected $injections = []; /** @phpstan-ignore-line */
public function inject($name, $object) /** @phpstan-ignore-line */
{
$this->injections[$name] = $object;
}
public function __construct() /** @phpstan-ignore-line */
{
$this->init();
}
protected function init() /** @phpstan-ignore-line */
{
}
public function __call($methodName, $args) /** @phpstan-ignore-line */
{
if (strpos($methodName, 'get') === 0) {
$injectionName = lcfirst(substr($methodName, 3));
if (in_array($injectionName, $this->dependencyList)) {
return $this->getInjection($injectionName);
}
}
throw new \BadMethodCallException('Method ' . $methodName . ' does not exist');
}
protected function getInjection($name) /** @phpstan-ignore-line */
{
return $this->injections[$name] ?? $this->$name ?? null;
}
protected function addDependency($name) /** @phpstan-ignore-line */
{
if (in_array($name, $this->dependencyList)) return;
$this->dependencyList[] = $name;
}
protected function addDependencyList(array $list) /** @phpstan-ignore-line */
{
foreach ($list as $item) {
$this->addDependency($item);
}
}
public function getDependencyList() /** @phpstan-ignore-line */
{
return $this->dependencyList;
}
}
@@ -34,7 +34,6 @@ use Psr\Container\NotFoundExceptionInterface;
use Espo\Core\Binding\BindingContainer;
use Espo\Core\Binding\Binding;
use Espo\Core\Binding\Factory;
use Espo\Core\Interfaces\Injectable;
use ReflectionClass;
use ReflectionParameter;
@@ -171,13 +170,6 @@ class InjectableFactory
$obj = $class->newInstanceArgs($injectionList);
// @todo Remove in v9.0.
if ($class->implementsInterface(Injectable::class)) {
$this->applyInjectable($class, $obj);
return $obj;
}
$this->applyAwareInjections($class, $obj);
return $obj;
@@ -457,45 +449,4 @@ class InjectableFactory
return false;
}
/**
* @deprecated As of v6.0. Use create or createWith methods instead.
*
* @template T of object
* @param class-string<T> $className
* @param ?array<string, mixed> $with
* @return T
*/
public function createByClassName(string $className, ?array $with = null): object
{
return $this->createInternal($className, $with);
}
/**
* @deprecated
* @param ReflectionClass<object> $class
* @todo Remove in v9.0.
*/
private function applyInjectable(ReflectionClass $class, object $obj): void
{
$setList = [];
assert($obj instanceof Injectable);
$dependencyList = $obj->getDependencyList();
foreach ($dependencyList as $name) {
$injection = $this->container->get($name);
if ($this->classHasDependencySetter($class, $name)) {
$methodName = 'set' . ucfirst($name);
$obj->$methodName($injection);
$setList[] = $name;
}
$obj->inject($name, $injection);
}
$this->applyAwareInjections($class, $obj, $setList);
}
}
@@ -1,40 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Interfaces;
/**
* @deprecated As of v6.0. Use the DI framework.
*/
interface Injectable
{
public function getDependencyList(); /** @phpstan-ignore-line */
public function inject($name, $object); /** @phpstan-ignore-line */
}
@@ -1,122 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\ORM\Repositories;
use Espo\Core\ORM\EntityManager;
use Espo\Core\ORM\EntityFactory;
use Espo\Core\Interfaces\Injectable;
use Espo\Core\ApplicationState;
use Espo\Core\HookManager;
use Espo\Core\Utils\Id\RecordIdGenerator;
use Espo\Core\Utils\Metadata;
use Espo\Core\Utils\SystemUser;
use Espo\ORM\Relation\RelationsMap;
/**
* @deprecated As of v6.0. Not to be extended. Extend Espo\Core\Repositories\Database, or better
* don't extend repositories at all. Use hooks.
*/
class RDB extends \Espo\Core\Repositories\Database implements Injectable /** @phpstan-ignore-line */
{
protected $dependencyList = [ /** @phpstan-ignore-line */
'config',
];
protected $dependencies = []; /** @phpstan-ignore-line */
protected $injections = []; /** @phpstan-ignore-line */
protected function addDependency($name) /** @phpstan-ignore-line */
{
$this->dependencyList[] = $name;
}
protected function addDependencyList(array $list) /** @phpstan-ignore-line */
{
foreach ($list as $item) {
$this->addDependency($item);
}
}
public function inject($name, $object) /** @phpstan-ignore-line */
{
$this->injections[$name] = $object;
}
protected function getInjection($name) /** @phpstan-ignore-line */
{
return $this->injections[$name] ?? $this->$name ?? null;
}
public function getDependencyList() /** @phpstan-ignore-line */
{
return array_merge($this->dependencyList, $this->dependencies);
}
protected function getMetadata() /** @phpstan-ignore-line */
{
return $this->getInjection('metadata');
}
protected function getConfig() /** @phpstan-ignore-line */
{
return $this->getInjection('config');
}
public function __construct(
string $entityType,
EntityManager $entityManager,
EntityFactory $entityFactory,
Metadata $metadata,
HookManager $hookManager,
ApplicationState $applicationState,
RecordIdGenerator $recordIdGenerator,
SystemUser $systemUser,
?RelationsMap $relationsMap,
) {
parent::__construct(
$entityType,
$entityManager,
$entityFactory,
$metadata,
$hookManager,
$applicationState,
$recordIdGenerator,
$systemUser,
$relationsMap
);
$this->init();
}
protected function init() /** @phpstan-ignore-line */
{
}
}
-91
View File
@@ -1,91 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\ORM;
use Espo\Core\Interfaces\Injectable;
use Espo\ORM\{
EntityFactory,
Repository\RDBRepository as RDBRepository,
};
/**
* @deprecated As of v6.0. Not to be extended. Extend Espo\Core\Repositories\Database, or better
* don't extend repositories at all. Use hooks.
* @extends RDBRepository<Entity>
*/
abstract class Repository extends RDBRepository implements Injectable
{
protected $dependencyList = []; /** @phpstan-ignore-line */
protected $dependencies = []; /** @phpstan-ignore-line */
protected $injections = []; /** @phpstan-ignore-line */
protected function init() /** @phpstan-ignore-line */
{
}
public function inject($name, $object) /** @phpstan-ignore-line */
{
$this->injections[$name] = $object;
}
protected function getInjection($name) /** @phpstan-ignore-line */
{
return $this->injections[$name];
}
public function getDependencyList() /** @phpstan-ignore-line */
{
return array_merge($this->dependencyList, $this->dependencies);
}
protected function addDependencyList(array $list) /** @phpstan-ignore-line */
{
foreach ($list as $item) {
$this->addDependency($item);
}
}
protected function addDependency($name) /** @phpstan-ignore-line */
{
$this->dependencyList[] = $name;
}
/**
* @param string $entityType
*/
public function __construct($entityType, EntityManager $entityManager, EntityFactory $entityFactory)
{
parent::__construct($entityType, $entityManager, $entityFactory);
$this->init();
}
}
-107
View File
@@ -1,107 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Services;
use Espo\Core\Interfaces\Injectable;
/**
* @deprecated As of v6.0. Create plain classes with dependencies passed via constrictor.
*/
abstract class Base implements Injectable
{
protected $dependencyList = [ /** @phpstan-ignore-line */
'config',
'entityManager',
'user',
'serviceFactory',
];
protected $injections = []; /** @phpstan-ignore-line */
public function inject($name, $object) /** @phpstan-ignore-line */
{
$this->injections[$name] = $object;
}
public function __construct() /** @phpstan-ignore-line */
{
$this->init();
}
protected function init() /** @phpstan-ignore-line */
{
}
public function prepare() /** @phpstan-ignore-line */
{
}
protected function getInjection($name) /** @phpstan-ignore-line */
{
return $this->injections[$name] ?? $this->$name ?? null;
}
protected function addDependency($name) /** @phpstan-ignore-line */
{
$this->dependencyList[] = $name;
}
protected function addDependencyList(array $list) /** @phpstan-ignore-line */
{
foreach ($list as $item) {
$this->addDependency($item);
}
}
public function getDependencyList() /** @phpstan-ignore-line */
{
return $this->dependencyList;
}
protected function getEntityManager() /** @phpstan-ignore-line */
{
return $this->getInjection('entityManager');
}
protected function getConfig() /** @phpstan-ignore-line */
{
return $this->getInjection('config');
}
protected function getUser() /** @phpstan-ignore-line */
{
return $this->getInjection('user');
}
protected function getServiceFactory() /** @phpstan-ignore-line */
{
return $this->getInjection('serviceFactory');
}
}