|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace eZ\Publish\Core\Base\Container\ApiLoader; |
|
8
|
|
|
|
|
9
|
|
|
use eZ\Publish\Core\FieldType\FieldTypeRegistry; |
|
10
|
|
|
use eZ\Publish\Core\Repository\Permission\LimitationService; |
|
11
|
|
|
use eZ\Publish\Core\Repository\ProxyFactory\ProxyDomainMapperFactoryInterface; |
|
12
|
|
|
use eZ\Publish\Core\Repository\User\PasswordHashServiceInterface; |
|
13
|
|
|
use eZ\Publish\Core\Repository\Helper\RelationProcessor; |
|
14
|
|
|
use eZ\Publish\Core\Repository\Mapper; |
|
15
|
|
|
use eZ\Publish\Core\Search\Common\BackgroundIndexer; |
|
16
|
|
|
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler; |
|
17
|
|
|
use eZ\Publish\SPI\Repository\Strategy\ContentThumbnail\ThumbnailStrategy; |
|
18
|
|
|
use eZ\Publish\SPI\Search\Handler as SearchHandler; |
|
19
|
|
|
use eZ\Publish\API\Repository\Repository; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
22
|
|
|
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException; |
|
23
|
|
|
|
|
24
|
|
|
class RepositoryFactory implements ContainerAwareInterface |
|
25
|
|
|
{ |
|
26
|
|
|
use ContainerAwareTrait; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
private $repositoryClass; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Policies map. |
|
33
|
|
|
* |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $policyMap = []; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct( |
|
39
|
|
|
$repositoryClass, |
|
40
|
|
|
array $policyMap |
|
41
|
|
|
) { |
|
42
|
|
|
$this->repositoryClass = $repositoryClass; |
|
43
|
|
|
$this->policyMap = $policyMap; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Builds the main repository, heart of eZ Publish API. |
|
48
|
|
|
* |
|
49
|
|
|
* This always returns the true inner Repository, please depend on ezpublish.api.repository and not this method |
|
50
|
|
|
* directly to make sure you get an instance wrapped inside Event / Cache / * functionality. |
|
51
|
|
|
*/ |
|
52
|
|
|
public function buildRepository( |
|
53
|
|
|
PersistenceHandler $persistenceHandler, |
|
54
|
|
|
SearchHandler $searchHandler, |
|
55
|
|
|
BackgroundIndexer $backgroundIndexer, |
|
56
|
|
|
RelationProcessor $relationProcessor, |
|
57
|
|
|
FieldTypeRegistry $fieldTypeRegistry, |
|
58
|
|
|
PasswordHashServiceInterface $passwordHashService, |
|
59
|
|
|
ThumbnailStrategy $thumbnailStrategy, |
|
60
|
|
|
ProxyDomainMapperFactoryInterface $proxyDomainMapperFactory, |
|
61
|
|
|
Mapper\ContentDomainMapper $contentDomainMapper, |
|
62
|
|
|
Mapper\ContentTypeDomainMapper $contentTypeDomainMapper, |
|
63
|
|
|
LimitationService $limitationService |
|
64
|
|
|
): Repository { |
|
65
|
|
|
return new $this->repositoryClass( |
|
66
|
|
|
$persistenceHandler, |
|
67
|
|
|
$searchHandler, |
|
68
|
|
|
$backgroundIndexer, |
|
69
|
|
|
$relationProcessor, |
|
70
|
|
|
$fieldTypeRegistry, |
|
71
|
|
|
$passwordHashService, |
|
72
|
|
|
$thumbnailStrategy, |
|
73
|
|
|
$proxyDomainMapperFactory, |
|
74
|
|
|
$contentDomainMapper, |
|
75
|
|
|
$contentTypeDomainMapper, |
|
76
|
|
|
$limitationService, |
|
77
|
|
|
[ |
|
78
|
|
|
'role' => [ |
|
79
|
|
|
'policyMap' => $this->policyMap, |
|
80
|
|
|
], |
|
81
|
|
|
'languages' => $this->container->getParameter('languages'), |
|
82
|
|
|
], |
|
83
|
|
|
); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Returns a service based on a name string (content => contentService, etc). |
|
88
|
|
|
* |
|
89
|
|
|
* @param \eZ\Publish\API\Repository\Repository $repository |
|
90
|
|
|
* @param string $serviceName |
|
91
|
|
|
* |
|
92
|
|
|
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException |
|
93
|
|
|
* |
|
94
|
|
|
* @return mixed |
|
95
|
|
|
*/ |
|
96
|
|
|
public function buildService(Repository $repository, $serviceName) |
|
97
|
|
|
{ |
|
98
|
|
|
$methodName = 'get' . $serviceName . 'Service'; |
|
99
|
|
|
if (!method_exists($repository, $methodName)) { |
|
100
|
|
|
throw new InvalidArgumentException($serviceName, 'No such service'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $repository->$methodName(); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|