1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Core\System\SalesChannel\Entity; |
4
|
|
|
|
5
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry; |
6
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition; |
7
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; |
8
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Exception\DefinitionNotFoundException; |
9
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Exception\EntityRepositoryNotFoundException; |
10
|
|
|
use Shopware\Core\Framework\Log\Package; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @internal |
14
|
|
|
*/ |
15
|
|
|
#[Package('core')] |
16
|
|
|
class DefinitionRegistryChain |
17
|
|
|
{ |
18
|
|
|
public function __construct( |
19
|
|
|
private readonly DefinitionInstanceRegistry $core, |
20
|
|
|
private readonly SalesChannelDefinitionInstanceRegistry $salesChannel |
21
|
|
|
) { |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function get(string $class): EntityDefinition |
25
|
|
|
{ |
26
|
|
|
if ($this->salesChannel->has($class)) { |
27
|
|
|
return $this->salesChannel->get($class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return $this->core->get($class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getRepository(string $entity): EntityRepository |
34
|
|
|
{ |
35
|
|
|
try { |
36
|
|
|
return $this->salesChannel->getRepository($entity); |
37
|
|
|
} catch (EntityRepositoryNotFoundException) { |
38
|
|
|
return $this->core->getRepository($entity); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getByEntityName(string $type): EntityDefinition |
43
|
|
|
{ |
44
|
|
|
try { |
45
|
|
|
return $this->salesChannel->getByEntityName($type); |
46
|
|
|
} catch (DefinitionNotFoundException) { |
47
|
|
|
return $this->core->getByEntityName($type); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function has(string $type): bool |
52
|
|
|
{ |
53
|
|
|
return $this->salesChannel->has($type) || $this->core->has($type); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|