This commit is contained in:
Yuri Kuznetsov
2023-02-17 17:32:17 +02:00
parent 2615869691
commit 4c265dbae1
20 changed files with 99 additions and 186 deletions
+10 -14
View File
@@ -29,24 +29,20 @@
namespace Espo\Core\Action;
use Espo\Core\{
Exceptions\NotFound,
Exceptions\Forbidden,
Utils\Metadata,
InjectableFactory,
};
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\Metadata;
class ActionFactory
{
private Metadata $metadata;
private InjectableFactory $injectableFactory;
public function __construct(Metadata $metadata, InjectableFactory $injectableFactory)
{
$this->metadata = $metadata;
$this->injectableFactory = $injectableFactory;
}
public function __construct(private Metadata $metadata, private InjectableFactory $injectableFactory)
{}
/**
* @throws Forbidden
* @throws NotFound
*/
public function create(string $action, ?string $entityType = null): Action
{
$className = $this->getClassName($action, $entityType);
@@ -42,7 +42,6 @@ use stdClass;
class Merge implements Action
{
public function __construct(private Acl $acl, private Merger $merger)
{}
@@ -29,48 +29,31 @@
namespace Espo\Core\Action\Actions\Merge;
use Espo\Core\{
Exceptions\Forbidden,
Exceptions\NotFound,
Action\Params,
Acl,
Acl\Table,
ORM\EntityManager,
Utils\Metadata,
Utils\ObjectUtil,
Record\ServiceContainer,
};
use Espo\Core\Acl;
use Espo\Core\Acl\Table;
use Espo\Core\Action\Params;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Record\ServiceContainer;
use Espo\Core\Utils\Metadata;
use Espo\Core\Utils\ObjectUtil;
use Espo\ORM\Entity;
use Espo\Entities\{
PhoneNumber,
EmailAddress,
};
use Espo\Entities\EmailAddress;
use Espo\Entities\PhoneNumber;
use stdClass;
class Merger
{
private Acl $acl;
private Metadata $metadata;
private EntityManager $entityManager;
private ServiceContainer $serviceContainer;
public function __construct(
Acl $acl,
Metadata $metadata,
EntityManager $entityManager,
ServiceContainer $serviceContainer
) {
$this->acl = $acl;
$this->metadata = $metadata;
$this->entityManager = $entityManager;
$this->serviceContainer = $serviceContainer;
}
private Acl $acl,
private Metadata $metadata,
private EntityManager $entityManager,
private ServiceContainer $serviceContainer
) {}
/**
* @param string[] $sourceIdList
+1 -1
View File
@@ -35,7 +35,7 @@ use stdClass;
class Data
{
private $data;
private stdClass $data;
private function __construct()
{
+1 -9
View File
@@ -36,16 +36,8 @@ use RuntimeException;
*/
class Params
{
private string $entityType;
private string $id;
/**
* @throws RuntimeException
*/
public function __construct(string $entityType, string $id)
public function __construct(private string $entityType, private string $id)
{
$this->entityType = $entityType;
$this->id = $id;
if (!$entityType || !$id) {
throw new RuntimeException();
+12 -26
View File
@@ -29,15 +29,13 @@
namespace Espo\Core\Action;
use Espo\Core\{
Exceptions\Forbidden,
Exceptions\ForbiddenSilent,
Exceptions\BadRequest,
Exceptions\NotFound,
Record\ServiceContainer as RecordServiceContainer,
Record\ReadParams,
Acl,
};
use Espo\Core\Acl;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\ForbiddenSilent;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Record\ReadParams;
use Espo\Core\Record\ServiceContainer as RecordServiceContainer;
use Espo\ORM\Entity;
@@ -45,21 +43,11 @@ use stdClass;
class Service
{
private $factory;
private $acl;
private $recordServiceContainer;
public function __construct(
ActionFactory $factory,
Acl $acl,
RecordServiceContainer $recordServiceContainer
) {
$this->factory = $factory;
$this->acl = $acl;
$this->recordServiceContainer = $recordServiceContainer;
}
private ActionFactory $factory,
private Acl $acl,
private RecordServiceContainer $recordServiceContainer
) {}
/**
* Perform an action.
@@ -89,8 +77,6 @@ class Service
$service = $this->recordServiceContainer->get($entityType);
$entity = $service->read($id, ReadParams::create());
return $entity;
return $service->read($id, ReadParams::create());
}
}
@@ -33,12 +33,9 @@ use Espo\Core\InjectableFactory;
class AuthBuilderFactory
{
private InjectableFactory $injectableFactory;
public function __construct(InjectableFactory $injectableFactory)
{
$this->injectableFactory = $injectableFactory;
}
public function __construct(private InjectableFactory $injectableFactory)
{}
public function create(): AuthBuilder
{
+4 -7
View File
@@ -31,14 +31,11 @@ namespace Espo\Core\Api;
use Espo\Core\Utils\Json;
use Espo\Core\Exceptions\BadRequest;
use Psr\Http\Message\{
ServerRequestInterface as Psr7Request,
UriInterface,
};
use Espo\Core\Api\Request as ApiRequest;
use Psr\Http\Message\ServerRequestInterface as Psr7Request;
use Psr\Http\Message\UriInterface;
use stdClass;
/**
@@ -53,7 +50,7 @@ class RequestWrapper implements ApiRequest
private array $routeParams;
/**
* @param array<string,string> $routeParams
* @param array<string, string> $routeParams
*/
public function __construct(Psr7Request $request, string $basePath = '', array $routeParams = [])
{
@@ -29,10 +29,8 @@
namespace Espo\Core\Api;
use Psr\Http\Message\{
ResponseInterface as Psr7Response,
StreamInterface,
};
use Psr\Http\Message\ResponseInterface as Psr7Response;
use Psr\Http\Message\StreamInterface;
use Espo\Core\Api\Response as ApiResponse;
@@ -41,12 +39,8 @@ use Espo\Core\Api\Response as ApiResponse;
*/
class ResponseWrapper implements ApiResponse
{
private Psr7Response $response;
public function __construct(Psr7Response $response)
public function __construct(private Psr7Response $response)
{
$this->response = $response;
// Slim adds Authorization header. It's not needed.
$this->response = $this->response->withoutHeader('Authorization');
}
@@ -34,8 +34,8 @@ use Espo\Core\Api\Route;
class RouteParamsFetcher
{
/**
* @param array<string,mixed> $args
* @return array<string,mixed>
* @param array<string, mixed> $args
* @return array<string, mixed>
*/
public function fetch(Route $item, array $args): array
{
+1 -3
View File
@@ -35,7 +35,7 @@ use stdClass;
class Data
{
private $data;
private stdClass $data;
private function __construct()
{
@@ -68,7 +68,6 @@ class Data
public static function fromRaw(stdClass $data): self
{
$obj = new self();
$obj->data = $data;
return $obj;
@@ -82,7 +81,6 @@ class Data
public function with(string $name, $value): self
{
$obj = clone $this;
$obj->data->$name = $value;
return $obj;
@@ -37,22 +37,20 @@ use Espo\Core\Utils\Metadata;
use Espo\Core\InjectableFactory;
use Espo\Core\AclManager;
use Espo\Core\Acl;
use Espo\Core\Binding\BindingContainerBuilder;
class MassActionFactory
{
private Metadata $metadata;
private InjectableFactory $injectableFactory;
private AclManager $aclManager;
public function __construct(Metadata $metadata, InjectableFactory $injectableFactory, AclManager $aclManager)
{
$this->metadata = $metadata;
$this->injectableFactory = $injectableFactory;
$this->aclManager = $aclManager;
}
public function __construct(
private Metadata $metadata,
private InjectableFactory $injectableFactory,
private AclManager $aclManager
) {}
/**
* @throws Forbidden
* @throws NotFound
*/
public function create(string $action, string $entityType): MassAction
{
$className = $this->getClassName($action, $entityType);
+1 -3
View File
@@ -39,9 +39,7 @@ use RuntimeException;
class Params
{
private string $entityType;
/**
* @var ?string[]
*/
/** @var ?string[] */
private $ids = null;
private ?SearchParams $searchParams = null;
@@ -29,21 +29,23 @@
namespace Espo\Core\MassAction;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\Forbidden;
use Espo\ORM\Query\Select;
use Espo\Core\Select\SelectBuilderFactory;
use Espo\Entities\User;
class QueryBuilder
{
private SelectBuilderFactory $selectBuilderFactory;
private User $user;
public function __construct(SelectBuilderFactory $selectBuilderFactory, User $user)
{
$this->selectBuilderFactory = $selectBuilderFactory;
$this->user = $user;
}
public function __construct(private SelectBuilderFactory $selectBuilderFactory, private User $user)
{}
/**
* @throws BadRequest
* @throws Forbidden
* @throws Error
*/
public function build(Params $params): Select
{
$builder = $this->selectBuilderFactory
@@ -31,6 +31,9 @@ namespace Espo\Core\MassAction;
use RuntimeException;
/**
* @immutable
*/
class Result
{
private ?int $count = null;
@@ -29,22 +29,15 @@
namespace Espo\Core\MassAction;
/**
* @immutable
*/
class ServiceParams
{
/**
* @var Params
*/
private $params;
private bool $isIdle = false;
/**
* @var bool
*/
private $isIdle = false;
private function __construct(Params $params)
{
$this->params = $params;
}
private function __construct(private Params $params)
{}
public static function create(Params $params): self
{
@@ -64,7 +57,6 @@ class ServiceParams
public function withIsIdle(bool $isIdle = true): self
{
$obj = clone $this;
$obj->isIdle = $isIdle;
return $obj;
@@ -29,17 +29,13 @@
namespace Espo\Core\MassAction;
/**
* @immutable
*/
class ServiceResult
{
/**
* @var ?Result
*/
private $result = null;
/**
* @var ?string
*/
private $id = null;
private ?Result $result = null;
private ?string $id = null;
private function __construct() {}
@@ -61,7 +57,6 @@ class ServiceResult
public static function createWithId(string $id): self
{
$obj = new self;
$obj->id = $id;
return $obj;
@@ -70,7 +65,6 @@ class ServiceResult
public static function createWithResult(Result $result): self
{
$obj = new self;
$obj->result = $result;
return $obj;
@@ -40,16 +40,11 @@ class AssignmentNotificatorFactory
/** @var class-string<AssignmentNotificator<Entity>> */
protected string $defaultClassName = DefaultAssignmentNotificator::class;
private InjectableFactory $injectableFactory;
private ClassFinder $classFinder;
private Metadata $metadata;
public function __construct(InjectableFactory $injectableFactory, ClassFinder $classFinder, Metadata $metadata)
{
$this->injectableFactory = $injectableFactory;
$this->classFinder = $classFinder;
$this->metadata = $metadata;
}
public function __construct(
private InjectableFactory $injectableFactory,
private ClassFinder $classFinder,
private Metadata $metadata
) {}
/**
* @template T of Entity
@@ -41,16 +41,11 @@ use Espo\Core\Notification\AssignmentNotificator\Params;
*/
class DefaultAssignmentNotificator implements AssignmentNotificator
{
protected User $user;
protected EntityManager $entityManager;
protected UserEnabledChecker $userChecker;
public function __construct(User $user, EntityManager $entityManager, UserEnabledChecker $userChecker)
{
$this->user = $user;
$this->entityManager = $entityManager;
$this->userChecker = $userChecker;
}
public function __construct(
protected User $user,
protected EntityManager $entityManager,
protected UserEnabledChecker $userChecker
) {}
public function process(Entity $entity, Params $params): void
{
@@ -33,17 +33,11 @@ use Espo\Core\ORM\EntityManager;
class UserEnabledChecker
{
/**
* @var array<string,bool>
*/
/** @var array<string, bool> */
private $assignmentCache = [];
private EntityManager $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function __construct(private EntityManager $entityManager)
{}
public function checkAssignment(string $entityType, string $userId): bool
{