cs
This commit is contained in:
@@ -36,7 +36,7 @@ use stdClass;
|
||||
* A collection of entities.
|
||||
*
|
||||
* @template TEntity of Entity
|
||||
* @extends Traversable<int,TEntity>
|
||||
* @extends Traversable<int, TEntity>
|
||||
*/
|
||||
interface Collection extends Traversable
|
||||
{
|
||||
|
||||
@@ -34,19 +34,15 @@ namespace Espo\ORM\Defs;
|
||||
*/
|
||||
class AttributeDefs
|
||||
{
|
||||
/**
|
||||
* @var array<string,mixed>
|
||||
*/
|
||||
/** @var array<string, mixed> */
|
||||
private array $data;
|
||||
|
||||
private string $name;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $raw
|
||||
* @param array<string, mixed> $raw
|
||||
*/
|
||||
public static function fromRaw(array $raw, string $name): self
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ class IndexDefs
|
||||
{}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $raw
|
||||
* @param array<string, mixed> $raw
|
||||
*/
|
||||
public static function fromRaw(array $raw, string $name): self
|
||||
{
|
||||
|
||||
@@ -42,7 +42,6 @@ use RuntimeException;
|
||||
*/
|
||||
class MysqlLocker implements Locker
|
||||
{
|
||||
private PDO $pdo;
|
||||
private MysqlQueryComposer $queryComposer;
|
||||
/** @phpstan-ignore-next-line */
|
||||
private TransactionManager $transactionManager;
|
||||
@@ -50,17 +49,17 @@ class MysqlLocker implements Locker
|
||||
private bool $isLocked = false;
|
||||
|
||||
public function __construct(
|
||||
PDO $pdo,
|
||||
private PDO $pdo,
|
||||
QueryComposer $queryComposer,
|
||||
TransactionManager $transactionManager
|
||||
) {
|
||||
$this->transactionManager = $transactionManager;
|
||||
|
||||
if (!$queryComposer instanceof MysqlQueryComposer) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
$this->pdo = $pdo;
|
||||
$this->queryComposer = $queryComposer;
|
||||
$this->transactionManager = $transactionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,35 +59,16 @@ class BaseMapper implements RDBMapper
|
||||
{
|
||||
protected const ATTRIBUTE_DELETED = 'deleted';
|
||||
|
||||
protected PDO $pdo;
|
||||
|
||||
protected EntityFactory $entityFactory;
|
||||
|
||||
protected CollectionFactory $collectionFactory;
|
||||
|
||||
protected QueryComposer $queryComposer;
|
||||
|
||||
protected Metadata $metadata;
|
||||
|
||||
protected SqlExecutor $sqlExecutor;
|
||||
|
||||
protected Helper $helper;
|
||||
|
||||
public function __construct(
|
||||
PDO $pdo,
|
||||
EntityFactory $entityFactory,
|
||||
CollectionFactory $collectionFactory,
|
||||
QueryComposer $queryComposer,
|
||||
Metadata $metadata,
|
||||
SqlExecutor $sqlExecutor
|
||||
protected PDO $pdo,
|
||||
protected EntityFactory $entityFactory,
|
||||
protected CollectionFactory $collectionFactory,
|
||||
protected QueryComposer $queryComposer,
|
||||
protected Metadata $metadata,
|
||||
protected SqlExecutor $sqlExecutor
|
||||
) {
|
||||
$this->pdo = $pdo;
|
||||
$this->queryComposer = $queryComposer;
|
||||
$this->entityFactory = $entityFactory;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
$this->metadata = $metadata;
|
||||
$this->sqlExecutor = $sqlExecutor;
|
||||
|
||||
$this->helper = new Helper($metadata);
|
||||
}
|
||||
|
||||
@@ -295,7 +276,6 @@ class BaseMapper implements RDBMapper
|
||||
}
|
||||
|
||||
$entityType = $entity->getEntityType();
|
||||
|
||||
$relType = $entity->getRelationType($relationName);
|
||||
|
||||
$relEntityType = $this->getRelationParam($entity, $relationName, 'entity');
|
||||
@@ -311,8 +291,7 @@ class BaseMapper implements RDBMapper
|
||||
if ($relType !== Entity::BELONGS_TO_PARENT) {
|
||||
if (!$relEntityType) {
|
||||
throw new LogicException(
|
||||
"Missing 'entity' in definition for relationship '{$relationName}' in {entityType} entity."
|
||||
);
|
||||
"Missing 'entity' in definition for relationship '{$relationName}' in {entityType} entity.");
|
||||
}
|
||||
|
||||
$relEntity = $this->entityFactory->create($relEntityType);
|
||||
@@ -1326,7 +1305,7 @@ class BaseMapper implements RDBMapper
|
||||
$update = null;
|
||||
|
||||
if ($onDuplicateUpdateAttributeList !== null && count($onDuplicateUpdateAttributeList)) {
|
||||
$update = $onDuplicateSetMap = $this->getInsertOnDuplicateSetMap($entity, $onDuplicateUpdateAttributeList);
|
||||
$update = $this->getInsertOnDuplicateSetMap($entity, $onDuplicateUpdateAttributeList);
|
||||
}
|
||||
|
||||
$sql = $this->queryComposer->composeInsert(
|
||||
@@ -1660,8 +1639,8 @@ class BaseMapper implements RDBMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed>|null $conditions
|
||||
* @return array{string,string,array<mixed,mixed>}
|
||||
* @param array<string, mixed>|null $conditions
|
||||
* @return array{string, string, array<string|int, mixed>}
|
||||
*/
|
||||
protected function getManyManyJoin(Entity $entity, string $relationName, ?array $conditions = null): array
|
||||
{
|
||||
@@ -1708,7 +1687,7 @@ class BaseMapper implements RDBMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array{string,string}>
|
||||
* @return array<array{string, string}>
|
||||
*/
|
||||
protected function getManyManyAdditionalSelect(Entity $entity, string $relationName): array
|
||||
{
|
||||
|
||||
@@ -36,12 +36,8 @@ use RuntimeException;
|
||||
|
||||
class Helper
|
||||
{
|
||||
private Metadata $metadata;
|
||||
|
||||
public function __construct(Metadata $metadata)
|
||||
{
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
public function __construct(private Metadata $metadata)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @return array{
|
||||
|
||||
@@ -36,7 +36,7 @@ trait BaseBuilderTrait
|
||||
/**
|
||||
* Must be protected for compatibility reasons.
|
||||
*
|
||||
* @var array<string,mixed>
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected $params = [];
|
||||
|
||||
|
||||
@@ -32,14 +32,14 @@ namespace Espo\ORM\Query;
|
||||
trait BaseTrait
|
||||
{
|
||||
/**
|
||||
* @var array<string,mixed>
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
private $params = [];
|
||||
|
||||
/**
|
||||
* Get parameters in RAW format.
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getRaw(): array
|
||||
{
|
||||
@@ -49,7 +49,7 @@ trait BaseTrait
|
||||
/**
|
||||
* Create from RAW params.
|
||||
*
|
||||
* @param array<string,mixed> $params
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
public static function fromRaw(array $params): self
|
||||
{
|
||||
@@ -63,9 +63,8 @@ trait BaseTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $params
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
private function validateRawParams(array $params): void
|
||||
{
|
||||
}
|
||||
{}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class Delete implements Query
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $params
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
private function validateRawParams(array $params): void
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@ class Insert implements Query
|
||||
use BaseTrait;
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $params
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
private function validateRawParams(array $params): void
|
||||
{
|
||||
|
||||
@@ -44,7 +44,7 @@ class LockTable implements Query
|
||||
public const MODE_EXCLUSIVE = 'EXCLUSIVE';
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $params
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
protected function validateRawParams(array $params): void
|
||||
{
|
||||
|
||||
@@ -37,7 +37,7 @@ interface Query
|
||||
/**
|
||||
* Get parameters in RAW format.
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getRaw(): array;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ trait SelectingBuilderTrait
|
||||
* * `where(array $clause)`
|
||||
* * `where(string $key, string $value)`
|
||||
*
|
||||
* @param WhereItem|array<mixed, mixed>|string $clause A key or where clause.
|
||||
* @param WhereItem|array<string|int, mixed>|string $clause A key or where clause.
|
||||
* @param mixed[]|scalar|null $value A value. Omitted if the first argument is not string.
|
||||
*/
|
||||
public function where($clause, $value = null): self
|
||||
@@ -60,7 +60,7 @@ trait SelectingBuilderTrait
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WhereItem|array<mixed, mixed>|string $clause A key or where clause.
|
||||
* @param WhereItem|array<string|int, mixed>|string $clause A key or where clause.
|
||||
* @param mixed[]|scalar|null $value A value. Omitted if the first argument is not string.
|
||||
*/
|
||||
private function applyWhereClause(string $type, $clause, $value): void
|
||||
@@ -159,7 +159,7 @@ trait SelectingBuilderTrait
|
||||
* @param Join|string $target
|
||||
* A relation name or table. A relation name should be in camelCase, a table in CamelCase.
|
||||
* @param ?string $alias An alias.
|
||||
* @param WhereItem|array<mixed, mixed>|null $conditions Join conditions.
|
||||
* @param WhereItem|array<string|int, mixed>|null $conditions Join conditions.
|
||||
*/
|
||||
public function join($target, ?string $alias = null, $conditions = null): self
|
||||
{
|
||||
@@ -172,7 +172,7 @@ trait SelectingBuilderTrait
|
||||
* @param Join|string $target
|
||||
* A relation name or table. A relation name should be in camelCase, a table in CamelCase.
|
||||
* @param ?string $alias An alias.
|
||||
* @param WhereItem|array<mixed, mixed>|null $conditions Join conditions.
|
||||
* @param WhereItem|array<string|int, mixed>|null $conditions Join conditions.
|
||||
*/
|
||||
public function leftJoin($target, ?string $alias = null, $conditions = null): self
|
||||
{
|
||||
@@ -302,7 +302,7 @@ trait SelectingBuilderTrait
|
||||
|
||||
/**
|
||||
* @param array<Expression|mixed[]> $itemList
|
||||
* @return array<array{0:string,1?:string}|string>
|
||||
* @return array<array{0: string, 1?: string}|string>
|
||||
*/
|
||||
private function normalizeExpressionItemArray(array $itemList): array
|
||||
{
|
||||
@@ -316,7 +316,7 @@ trait SelectingBuilderTrait
|
||||
}
|
||||
|
||||
if (!is_array($item) || !count($item) || !$item[0] instanceof Expression) {
|
||||
/** @var array{0:string,1?:string} $item */
|
||||
/** @var array{0:string, 1?:string} $item */
|
||||
$resultList[] = $item;
|
||||
|
||||
continue;
|
||||
|
||||
@@ -30,6 +30,4 @@
|
||||
namespace Espo\ORM\Query;
|
||||
|
||||
interface SelectingQuery extends Query
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Union implements SelectingQuery
|
||||
use BaseTrait;
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $params
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
private function validateRawParams(array $params): void
|
||||
{
|
||||
|
||||
@@ -29,17 +29,14 @@
|
||||
|
||||
namespace Espo\ORM;
|
||||
|
||||
use Espo\ORM\{
|
||||
Query\SelectBuilder,
|
||||
Query\UpdateBuilder,
|
||||
Query\DeleteBuilder,
|
||||
Query\InsertBuilder,
|
||||
Query\UnionBuilder,
|
||||
Query\Query,
|
||||
Query\Builder,
|
||||
Query\Part\Expression,
|
||||
Query\Part\Selection,
|
||||
};
|
||||
use Espo\ORM\Query\DeleteBuilder;
|
||||
use Espo\ORM\Query\InsertBuilder;
|
||||
use Espo\ORM\Query\Part\Expression;
|
||||
use Espo\ORM\Query\Part\Selection;
|
||||
use Espo\ORM\Query\Query;
|
||||
use Espo\ORM\Query\SelectBuilder;
|
||||
use Espo\ORM\Query\UnionBuilder;
|
||||
use Espo\ORM\Query\UpdateBuilder;
|
||||
|
||||
use ReflectionClass;
|
||||
use RuntimeException;
|
||||
@@ -112,7 +109,7 @@ class QueryBuilder
|
||||
* @return SelectBuilder|UpdateBuilder|DeleteBuilder|InsertBuilder|UnionBuilder
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function clone(Query $query): Builder
|
||||
public function clone(Query $query): SelectBuilder|UpdateBuilder|DeleteBuilder|InsertBuilder|UnionBuilder
|
||||
{
|
||||
$class = new ReflectionClass($query);
|
||||
|
||||
|
||||
@@ -29,10 +29,8 @@
|
||||
|
||||
namespace Espo\ORM\Repository;
|
||||
|
||||
use Espo\ORM\{
|
||||
Entity,
|
||||
Query\Select,
|
||||
};
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Query\Select;
|
||||
|
||||
class EmptyHookMediator implements HookMediator
|
||||
{
|
||||
|
||||
@@ -33,13 +33,11 @@ use stdClass;
|
||||
|
||||
class GeneralAttributeExtractor
|
||||
{
|
||||
/**
|
||||
* @var AttributeExtractorFactory<object>
|
||||
*/
|
||||
/** @var AttributeExtractorFactory<object> */
|
||||
private AttributeExtractorFactory $factory;
|
||||
|
||||
/**
|
||||
* @var array<string,AttributeExtractor<object>>
|
||||
* @var array<string, AttributeExtractor<object>>
|
||||
*/
|
||||
private $cache = [];
|
||||
|
||||
|
||||
@@ -35,17 +35,11 @@ use RuntimeException;
|
||||
|
||||
class GeneralValueFactory
|
||||
{
|
||||
private ValueFactoryFactory $valueFactoryFactory;
|
||||
|
||||
/**
|
||||
* @var array<string,?ValueFactory>
|
||||
*/
|
||||
/** @var array<string,?ValueFactory> */
|
||||
private array $factoryCache = [];
|
||||
|
||||
public function __construct(ValueFactoryFactory $valueFactoryFactory)
|
||||
{
|
||||
$this->valueFactoryFactory = $valueFactoryFactory;
|
||||
}
|
||||
public function __construct(private ValueFactoryFactory $valueFactoryFactory)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Whether a field value object can be created from an entity.
|
||||
|
||||
@@ -29,29 +29,15 @@
|
||||
|
||||
namespace Espo\ORM\Value;
|
||||
|
||||
use Espo\ORM\{
|
||||
Entity,
|
||||
Value\GeneralValueFactory,
|
||||
Value\GeneralAttributeExtractor,
|
||||
};
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class ValueAccessor
|
||||
{
|
||||
private $entity;
|
||||
|
||||
private $valueFactory;
|
||||
|
||||
private $extractor;
|
||||
|
||||
public function __construct(
|
||||
Entity $entity,
|
||||
GeneralValueFactory $valueFactory,
|
||||
GeneralAttributeExtractor $extractor
|
||||
) {
|
||||
$this->entity = $entity;
|
||||
$this->valueFactory = $valueFactory;
|
||||
$this->extractor = $extractor;
|
||||
}
|
||||
private Entity $entity,
|
||||
private GeneralValueFactory $valueFactory,
|
||||
private GeneralAttributeExtractor $extractor
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get a field value object.
|
||||
|
||||
@@ -35,29 +35,16 @@ use Espo\ORM\EventDispatcher;
|
||||
class ValueAccessorFactory
|
||||
{
|
||||
private ?GeneralValueFactory $generalValueFactory = null;
|
||||
|
||||
private ?GeneralAttributeExtractor $generalAttributeExtractor = null;
|
||||
|
||||
private ValueFactoryFactory $valueFactoryFactory;
|
||||
|
||||
/**
|
||||
* @var AttributeExtractorFactory<object>
|
||||
*/
|
||||
private AttributeExtractorFactory $attributeExtractorFactory;
|
||||
|
||||
private EventDispatcher $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @param AttributeExtractorFactory<object> $attributeExtractorFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ValueFactoryFactory $valueFactoryFactory,
|
||||
AttributeExtractorFactory $attributeExtractorFactory,
|
||||
EventDispatcher $eventDispatcher
|
||||
private ValueFactoryFactory $valueFactoryFactory,
|
||||
private AttributeExtractorFactory $attributeExtractorFactory,
|
||||
private EventDispatcher $eventDispatcher
|
||||
) {
|
||||
$this->valueFactoryFactory = $valueFactoryFactory;
|
||||
$this->attributeExtractorFactory = $attributeExtractorFactory;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
|
||||
$this->subscribeToMetadataUpdate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user