-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathAdminSearcher.php
45 lines (36 loc) · 1.28 KB
/
AdminSearcher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php declare(strict_types=1);
namespace Shopware\Administration\Service;
use Shopware\Administration\Framework\Search\CriteriaCollection;
use Shopware\Core\Framework\Api\Acl\Role\AclRoleDefinition;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry;
use Shopware\Core\Framework\Log\Package;
#[Package('administration')]
class AdminSearcher
{
/**
* @internal
*/
public function __construct(private readonly DefinitionInstanceRegistry $definitionRegistry)
{
}
public function search(CriteriaCollection $entities, Context $context): array
{
$result = [];
foreach ($entities as $entityName => $criteria) {
if (!$this->definitionRegistry->has($entityName)) {
continue;
}
if (!$context->isAllowed($entityName . ':' . AclRoleDefinition::PRIVILEGE_READ)) {
continue;
}
$repository = $this->definitionRegistry->getRepository($entityName);
$collection = $repository->search($criteria, $context);
$result[$entityName] = [
'data' => $collection->getEntities(),
'total' => $collection->getTotal(),
];
}
return $result;
}
}