select refactoring

This commit is contained in:
Yuri Kuznetsov
2021-03-28 13:43:16 +03:00
parent 29c5717e79
commit c9c7794e73
54 changed files with 181 additions and 94 deletions
@@ -42,6 +42,7 @@ use Espo\{
class OnlyOwn implements AccessControlFilter
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -42,6 +42,7 @@ use Espo\{
class OnlyTeam implements AccessControlFilter
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -42,6 +42,7 @@ use Espo\{
class PortalOnlyAccount implements AccessControlFilter
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -42,6 +42,7 @@ use Espo\{
class PortalOnlyContact implements AccessControlFilter
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -43,6 +43,7 @@ use Espo\{
class AdditionalApplier extends AdditionalApplierBase
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -40,6 +40,7 @@ use Espo\{
class OnlyMy implements BoolFilter
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -35,6 +35,8 @@ use Espo\{
class EmailAddressHelper
{
private $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
@@ -45,6 +45,7 @@ use Espo\{
class EmailAddressEquals implements ItemConverter
{
protected $emailAddressHelper;
protected $randomStringGenerator;
public function __construct(
@@ -45,7 +45,9 @@ use Espo\{
class FromEquals implements ItemConverter
{
protected $entityManager;
protected $emailAddressHelper;
protected $randomStringGenerator;
public function __construct(
@@ -46,7 +46,9 @@ use Espo\{
class InFolder implements ItemConverter
{
protected $user;
protected $entityManager;
protected $joinHelper;
public function __construct(User $user, EntityManager $entityManager, JoinHelper $joinHelper)
@@ -45,6 +45,7 @@ use Espo\{
class IsImportantIsFalse implements ItemConverter
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -45,6 +45,7 @@ use Espo\{
class IsImportantIsTrue implements ItemConverter
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -45,6 +45,7 @@ use Espo\{
class IsNotReadIsFalse implements ItemConverter
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -45,6 +45,7 @@ use Espo\{
class IsNotReadIsTrue implements ItemConverter
{
protected $user;
protected $joinHelper;
public function __construct(User $user, JoinHelper $joinHelper)
@@ -45,6 +45,7 @@ use Espo\{
class ToEquals implements ItemConverter
{
protected $emailAddressHelper;
protected $randomStringGenerator;
public function __construct(
@@ -43,8 +43,9 @@ use Espo\{
class FilterFactory
{
protected $injectableFactory;
protected $metadata;
private $injectableFactory;
private $metadata;
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
{
@@ -76,7 +77,7 @@ class FilterFactory
return (bool) $this->getClassName($entityType, $name);
}
protected function getClassName(string $entityType, string $name) : ?string
private function getClassName(string $entityType, string $name) : ?string
{
if (!$name) {
throw new Error("Empty access control filter name.");
@@ -104,7 +105,7 @@ class FilterFactory
return $className;
}
protected function getDefaultClassName(string $name) : string
private function getDefaultClassName(string $name) : string
{
$className = 'Espo\\Core\\Select\\AccessControlFilters\\' . ucfirst($name);
@@ -34,10 +34,15 @@ use Espo\{
Entities\User,
};
/**
* @todo Use interface.
*/
class FilterResolver
{
protected $entityType;
protected $user;
protected $acl;
public function __construct(string $entityType, User $user, Acl $acl)
@@ -41,9 +41,11 @@ use Espo\{
class FilterResolverFactory
{
protected $injectableFactory;
protected $metadata;
protected $aclManager;
private $injectableFactory;
private $metadata;
private $aclManager;
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata, AclManager $aclManager)
{
@@ -65,7 +67,7 @@ class FilterResolverFactory
]);
}
protected function getClassName(string $entityType) : string
private function getClassName(string $entityType) : string
{
return $this->metadata->get([
'selectDefs', $entityType, 'accessControlFilterResolverClassName'
@@ -39,7 +39,9 @@ use Espo\{
class OnlyOwn implements AccessControlFilter
{
protected $entityType;
protected $user;
protected $fieldHelper;
public function __construct(string $entityType, User $user, FieldHelper $fieldHelper)
@@ -39,7 +39,9 @@ use Espo\{
class OnlyTeam implements AccessControlFilter
{
protected $entityType;
protected $user;
protected $fieldHelper;
public function __construct(string $entityType, User $user, FieldHelper $fieldHelper)
@@ -39,7 +39,9 @@ use Espo\{
class PortalOnlyAccount implements AccessControlFilter
{
protected $entityType;
protected $user;
protected $fieldHelper;
public function __construct(string $entityType, User $user, FieldHelper $fieldHelper)
@@ -39,7 +39,9 @@ use Espo\{
class PortalOnlyContact implements AccessControlFilter
{
protected $entityType;
protected $user;
protected $fieldHelper;
public function __construct(string $entityType, User $user, FieldHelper $fieldHelper)
@@ -39,7 +39,9 @@ use Espo\{
class PortalOnlyOwn implements AccessControlFilter
{
protected $entityType;
protected $user;
protected $fieldHelper;
public function __construct(string $entityType, User $user, FieldHelper $fieldHelper)
@@ -47,10 +47,15 @@ class AccessControlFilterApplier
protected $acl;
protected $entityType;
protected $user;
protected $accessControlFilterFactory;
protected $accessControlFilterResolverFactory;
protected $aclManager;
protected $selectManager;
public function __construct(
@@ -45,8 +45,11 @@ use Espo\{
class BoolFilterListApplier
{
protected $entityType;
protected $user;
protected $selectManager;
protected $boolFilterFactory;
public function __construct(
@@ -49,7 +49,9 @@ class OrderApplier
protected $entityType;
protected $user;
protected $metadataProvider;
protected $itemConverterFactory;
public function __construct(
@@ -43,8 +43,11 @@ use Espo\{
class PrimaryFilterApplier
{
protected $entityType;
protected $user;
protected $selectManager;
protected $primaryFilterFactory;
public function __construct(
@@ -60,7 +60,9 @@ class SelectApplier
protected $entityType;
protected $user;
protected $fieldUtil;
protected $metadataProvider;
public function __construct(
@@ -66,8 +66,11 @@ class TextFilterApplier
protected $entityType;
protected $user;
protected $config;
protected $metadataProvider;
protected $fullTextSearchDataComposerFactory;
public function __construct(
@@ -44,8 +44,11 @@ use Espo\{
class WhereApplier
{
protected $entityType;
protected $user;
protected $converterFactory;
protected $checkerFactory;
public function __construct(
@@ -39,6 +39,7 @@ use Espo\{
class Followed implements BoolFilter
{
protected $entityType;
protected $user;
public function __construct(string $entityType, User $user)
@@ -51,9 +51,11 @@ class ApplierFactory
const BOOL_FILTER_LIST = 'boolFilterList';
const ADDITIONAL = 'additional';
protected $injectableFactory;
protected $metadata;
protected $selectManagerFactory;
private $injectableFactory;
private $metadata;
private $selectManagerFactory;
public function __construct(
InjectableFactory $injectableFactory, Metadata $metadata, SelectManagerFactory $selectManagerFactory
@@ -42,8 +42,9 @@ use Espo\{
class BoolFilterFactory
{
protected $injectableFactory;
protected $metadata;
private $injectableFactory;
private $metadata;
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
{
@@ -42,8 +42,9 @@ use Espo\{
class PrimaryFilterFactory
{
protected $injectableFactory;
protected $metadata;
private $injectableFactory;
private $metadata;
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
{
@@ -41,9 +41,9 @@ class FieldHelper
{
private $seed = null;
protected $entityType;
private $entityType;
protected $entityManager;
private $entityManager;
public function __construct(string $entityType, EntityManager $entityManager)
{
@@ -51,7 +51,7 @@ class FieldHelper
$this->entityManager = $entityManager;
}
protected function getSeed() : Entity
private function getSeed() : Entity
{
return $this->seed ?? $this->entityManager->getEntity($this->entityType);
}
@@ -37,8 +37,9 @@ use Espo\Core\{
class ItemConverterFactory
{
protected $injectableFactory;
protected $metadata;
private $injectableFactory;
private $metadata;
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
{
@@ -64,7 +65,7 @@ class ItemConverterFactory
]);
}
protected function getClassName(string $entityType, string $field) : ?string
private function getClassName(string $entityType, string $field) : ?string
{
$className = $this->metadata->get([
'selectDefs', $entityType, 'orderItemConverterClassNameMap', $field
@@ -38,9 +38,9 @@ use Espo\Core\{
class EnumType implements ItemConverter
{
protected $entityType;
private $entityType;
protected $metadata;
private $metadata;
public function __construct(
string $entityType,
@@ -39,8 +39,9 @@ use Espo\{
class MetadataProvider
{
protected $metadata;
protected $entityManager;
private $metadata;
private $entityManager;
public function __construct(Metadata $metadata, EntityManager $entityManager)
{
@@ -37,8 +37,9 @@ use Espo\{
class Followed implements PrimaryFilter
{
protected $entityType;
protected $user;
private $entityType;
private $user;
public function __construct(string $entityType, User $user)
{
@@ -36,7 +36,7 @@ use InvalidArgumentException;
*/
class SearchParams
{
protected $rawParams;
private $rawParams;
const ORDER_ASC = 'ASC';
const ORDER_DESC = 'DESC';
@@ -268,7 +268,7 @@ class SearchParams
/**
* For compatibility with the legacy definition.
*/
protected function adjustParams(array &$params) : void
private function adjustParams(array &$params) : void
{
if (!$params['where']) {
return;
@@ -39,8 +39,9 @@ use Espo\{
class MetadataProvider
{
protected $metadata;
protected $entityManager;
private $metadata;
private $entityManager;
public function __construct(Metadata $metadata, EntityManager $entityManager)
{
+32 -32
View File
@@ -60,33 +60,33 @@ use LogicException;
*/
class SelectBuilder
{
protected $entityType = null;
private $entityType = null;
protected $queryBuilder;
private $queryBuilder;
protected $user = null;
private $user = null;
protected $sourceQuery = null;
private $sourceQuery = null;
protected $searchParams = null;
private $searchParams = null;
protected $applyAccessControlFilter = false;
private $applyAccessControlFilter = false;
protected $applyDefaultOrder = false;
private $applyDefaultOrder = false;
protected $textFilter = null;
private $textFilter = null;
protected $primaryFilter = null;
private $primaryFilter = null;
protected $boolFilterList = [];
private $boolFilterList = [];
protected $whereItemList = [];
private $whereItemList = [];
protected $applyWherePermissionCheck = false;
private $applyWherePermissionCheck = false;
protected $applyComplexExpressionsForbidden = false;
private $applyComplexExpressionsForbidden = false;
protected $applierFactory;
private $applierFactory;
public function __construct(User $user, ApplierFactory $applierFactory)
{
@@ -322,7 +322,7 @@ class SelectBuilder
return $this;
}
protected function applyPrimaryFilter() : void
private function applyPrimaryFilter() : void
{
$this->createPrimaryFilterApplier()
->apply(
@@ -331,7 +331,7 @@ class SelectBuilder
);
}
protected function applyBoolFilterList() : void
private function applyBoolFilterList() : void
{
$this->createBoolFilterListApplier()
->apply(
@@ -340,7 +340,7 @@ class SelectBuilder
);
}
protected function applyTextFilter() : void
private function applyTextFilter() : void
{
$noFullTextSearch = false;
@@ -358,7 +358,7 @@ class SelectBuilder
);
}
protected function applyAccessControlFilter() : void
private function applyAccessControlFilter() : void
{
$this->createAccessControlFilterApplier()
->apply(
@@ -366,7 +366,7 @@ class SelectBuilder
);
}
protected function applyDefaultOrder() : void
private function applyDefaultOrder() : void
{
$order = null;
@@ -386,14 +386,14 @@ class SelectBuilder
);
}
protected function applyWhereItemList() : void
private function applyWhereItemList() : void
{
foreach ($this->whereItemList as $whereItem) {
$this->applyWhereItem($whereItem);
}
}
protected function applyWhereItem(WhereItem $whereItem) : void
private function applyWhereItem(WhereItem $whereItem) : void
{
$params = WhereParams::fromArray([
'applyPermissionCheck' => $this->applyWherePermissionCheck,
@@ -408,7 +408,7 @@ class SelectBuilder
);
}
protected function applyFromSearchParams() : void
private function applyFromSearchParams() : void
{
if (!$this->searchParams) {
return;
@@ -462,7 +462,7 @@ class SelectBuilder
}
}
protected function applyAdditional() : void
private function applyAdditional() : void
{
$searchParams = SearchParams::fromRaw([
'boolFilterList' => $this->boolFilterList,
@@ -480,47 +480,47 @@ class SelectBuilder
);
}
protected function createWhereApplier() : WhereApplier
private function createWhereApplier() : WhereApplier
{
return $this->applierFactory->create($this->entityType, $this->user, ApplierFactory::WHERE);
}
protected function createSelectApplier() : SelectApplier
private function createSelectApplier() : SelectApplier
{
return $this->applierFactory->create($this->entityType, $this->user, ApplierFactory::SELECT);
}
protected function createOrderApplier() : OrderApplier
private function createOrderApplier() : OrderApplier
{
return $this->applierFactory->create($this->entityType, $this->user, ApplierFactory::ORDER);
}
protected function createLimitApplier() : LimitApplier
private function createLimitApplier() : LimitApplier
{
return $this->applierFactory->create($this->entityType, $this->user, ApplierFactory::LIMIT);
}
protected function createAccessControlFilterApplier() : AccessControlFilterApplier
private function createAccessControlFilterApplier() : AccessControlFilterApplier
{
return $this->applierFactory->create($this->entityType, $this->user, ApplierFactory::ACCESS_CONTROL_FILTER);
}
protected function createTextFilterApplier() : TextFilterApplier
private function createTextFilterApplier() : TextFilterApplier
{
return $this->applierFactory->create($this->entityType, $this->user, ApplierFactory::TEXT_FILTER);
}
protected function createPrimaryFilterApplier() : PrimaryFilterApplier
private function createPrimaryFilterApplier() : PrimaryFilterApplier
{
return $this->applierFactory->create($this->entityType, $this->user, ApplierFactory::PRIMARY_FILTER);
}
protected function createBoolFilterListApplier() : BoolFilterListApplier
private function createBoolFilterListApplier() : BoolFilterListApplier
{
return $this->applierFactory->create($this->entityType, $this->user, ApplierFactory::BOOL_FILTER_LIST);
}
protected function createAdditionalApplier() : AdditionalApplier
private function createAdditionalApplier() : AdditionalApplier
{
return $this->applierFactory->create($this->entityType, $this->user, ApplierFactory::ADDITIONAL);
}
@@ -38,7 +38,7 @@ use Espo\Core\{
*/
class SelectBuilderFactory
{
protected $injectableFactory;
private $injectableFactory;
public function __construct(InjectableFactory $injectableFactory)
{
@@ -40,6 +40,7 @@ class FullTextSearchDataComposer
protected $entityType;
protected $config;
protected $metadataProvider;
public function __construct(
@@ -36,8 +36,9 @@ use Espo\Core\{
class FullTextSearchDataComposerFactory
{
protected $injectableFactory;
protected $metadata;
private $injectableFactory;
private $metadata;
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
{
@@ -54,7 +55,7 @@ class FullTextSearchDataComposerFactory
]);
}
protected function getClassName(string $entityType) : string
private function getClassName(string $entityType) : string
{
return
$this->metadata->get([
@@ -37,8 +37,9 @@ use Espo\ORM\Defs\Defs;
class MetadataProvider
{
protected $metadata;
protected $ormDefs;
private $metadata;
private $ormDefs;
public function __construct(Metadata $metadata, Defs $ormDefs)
{
+11 -10
View File
@@ -45,12 +45,13 @@ class Checker
{
private $seed = null;
protected $entityType;
private $entityType;
protected $entityManager;
protected $acl;
private $entityManager;
protected $nestingTypeList = [
private $acl;
private $nestingTypeList = [
'or',
'and',
'subQueryIn',
@@ -58,13 +59,13 @@ class Checker
'not',
];
protected $subQueryTypeList = [
private $subQueryTypeList = [
'subQueryIn',
'subQueryNotIn',
'not',
];
protected $linkTypeList = [
private $linkTypeList = [
'inCategory',
'isLinked',
'isNotLinked',
@@ -86,7 +87,7 @@ class Checker
$this->checkItem($item, $params);
}
protected function checkItem(Item $item, Params $params) : void
private function checkItem(Item $item, Params $params) : void
{
$type = $item->getType();
$attribute = $item->getAttribute();
@@ -129,7 +130,7 @@ class Checker
}
}
protected function checkAttributeExistence(string $attribute, string $type) : void
private function checkAttributeExistence(string $attribute, string $type) : void
{
if (strpos($attribute, '.') !== false) {
// @todo Check existance of foreign attributes.
@@ -149,7 +150,7 @@ class Checker
}
}
protected function checkAttributePermission(string $attribute, string $type) : void
private function checkAttributePermission(string $attribute, string $type) : void
{
$entityType = $this->entityType;
@@ -210,7 +211,7 @@ class Checker
}
}
protected function getSeed() : Entity
private function getSeed() : Entity
{
return $this->seed ?? $this->entityManager->getEntity($this->entityType);
}
@@ -37,8 +37,9 @@ use Espo\{
class CheckerFactory
{
protected $injectableFactory;
protected $aclManager;
private $injectableFactory;
private $aclManager;
public function __construct(InjectableFactory $injectableFactory, AclManager $aclManager)
{
@@ -45,10 +45,15 @@ use Espo\{
class Converter
{
protected $entityType;
protected $user;
protected $itemConverter;
protected $scanner;
protected $randomStringGenerator;
protected $ormDefs;
public function __construct(
@@ -40,8 +40,9 @@ use Espo\{
class ConverterFactory
{
protected $injectableFactory;
protected $metadata;
private $injectableFactory;
private $metadata;
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
{
@@ -75,7 +76,7 @@ class ConverterFactory
]);
}
protected function getConverterClassName(string $entityType) : string
private function getConverterClassName(string $entityType) : string
{
$className = $this->metadata->get(['selectDefs', $entityType, 'whereConverterClassName']);
@@ -86,7 +87,7 @@ class ConverterFactory
return Converter::class;
}
protected function getItemConverterClassName(string $entityType) : string
private function getItemConverterClassName(string $entityType) : string
{
$className = $this->metadata->get(['selectDefs', $entityType, 'whereItemConverterClassName']);
@@ -97,7 +98,7 @@ class ConverterFactory
return ItemGeneralConverter::class;
}
protected function getDateTimeItemTransformerClassName(string $entityType) : string
private function getDateTimeItemTransformerClassName(string $entityType) : string
{
$className = $this->metadata->get(['selectDefs', $entityType, 'whereDateTimeItemTransformerClassName']);
@@ -44,6 +44,7 @@ use DateInterval;
class DateTimeItemTransformer
{
protected $entityType;
protected $user;
public function __construct(string $entityType, User $user)
@@ -41,8 +41,9 @@ use Espo\{
class ItemConverterFactory
{
protected $injectableFactory;
protected $metadata;
private $injectableFactory;
private $metadata;
public function __construct(InjectableFactory $injectableFactory, Metadata $metadata)
{
@@ -51,13 +51,21 @@ use DateInterval;
class ItemGeneralConverter
{
protected $entityType;
protected $user;
protected $dateTimeItemTransformer;
protected $scanner;
protected $itemConverterFactory;
protected $randomStringGenerator;
protected $entityManager;
protected $ormDefs;
protected $config;
public function __construct(
@@ -39,16 +39,16 @@ use Espo\{
class Scanner
{
protected $entityManager;
private $entityManager;
private $seedHash = [];
protected $nestingTypeList = [
private $nestingTypeList = [
'or',
'and',
];
protected $subQueryTypeList = [
private $subQueryTypeList = [
'subQueryIn',
'subQueryNotIn',
'not',
@@ -70,7 +70,7 @@ class Scanner
$this->applyLeftJoinsFromItem($queryBuilder, $item, $entityType);
}
protected function applyLeftJoinsFromItem(QueryBuilder $queryBuilder, Item $item, string $entityType) : void
private function applyLeftJoinsFromItem(QueryBuilder $queryBuilder, Item $item, string $entityType) : void
{
$type = $item->getType();
$value = $item->getValue();
@@ -99,7 +99,7 @@ class Scanner
$this->applyLeftJoinsFromAttribute($queryBuilder, $attribute, $entityType);
}
protected function applyLeftJoinsFromAttribute(
private function applyLeftJoinsFromAttribute(
QueryBuilder $queryBuilder, string $attribute, string $entityType
) : void {
@@ -142,7 +142,7 @@ class Scanner
}
}
protected function getSeed(string $entityType) : Entity
private function getSeed(string $entityType) : Entity
{
if (!isset($this->seedHash[$entityType])) {
$this->seedHash[$entityType] = $this->entityManager->getEntity($entityType);