1 | <?php |
||
16 | class EntityManager |
||
17 | { |
||
18 | /** |
||
19 | * @var \eZ\Publish\API\Repository\Repository $repository |
||
20 | */ |
||
21 | protected $repository; |
||
22 | protected $classMap; |
||
23 | protected $serviceMap; |
||
24 | protected $defaultClass; |
||
25 | protected $contentTypeIdentifierCache = array(); |
||
26 | |||
27 | /** |
||
28 | * @param eZRepository $repository |
||
29 | * @param array $classMap array of classes exposing a RepositoryInterface |
||
30 | * @param RepositoryManagerInterface[] $serviceMap array of services exposing a RepositoryInterface |
||
31 | */ |
||
32 | 10 | public function __construct(eZRepository $repository, array $classMap=array(), array $serviceMap=array()) |
|
42 | |||
43 | /** |
||
44 | * Registers an existing service to be used as repository for a given content type |
||
45 | * @var RepositoryInterface $service |
||
46 | * @var string $contentTypeIdentifier when null, we will ask the Repository to see if it already has its own $contentTypeIdentifier set up |
||
47 | */ |
||
48 | 10 | public function registerService(RepositoryInterface $service, $contentTypeIdentifier) |
|
58 | |||
59 | /** |
||
60 | * Registers a php class to be used as wrapper for a given content type |
||
61 | 2 | * @var string $className |
|
62 | * @var string $contentTypeIdentifier |
||
63 | 2 | * @throws \InvalidArgumentException |
|
64 | * |
||
65 | * @todo improve validation of contentTypeIdentifiers (is '0' a valid content type identifier?...) |
||
66 | 2 | */ |
|
67 | 2 | public function registerClass($className, $contentTypeIdentifier) |
|
77 | |||
78 | /** |
||
79 | 10 | * Registers a php class to be used as default repository |
|
80 | 10 | * @var string $className |
|
81 | * @throws \InvalidArgumentException |
||
82 | */ |
||
83 | public function registerDefaultClass($className) |
||
90 | 3 | ||
91 | 3 | /** |
|
92 | * @param string $contentTypeIdentifier as used in the mapping |
||
93 | * @return \Kaliop\eZObjectWrapperBundle\Core\RepositoryInterface |
||
94 | * @throws \UnexpectedValueException |
||
95 | 10 | */ |
|
96 | 2 | public function getRepository($contentTypeIdentifier) |
|
118 | |||
119 | /** |
||
120 | * @param int $contentTypeId slightly slower than loading by Identifier, but is useful when used eg. by Entities |
||
121 | * @return \Kaliop\eZObjectWrapperBundle\Core\RepositoryInterface |
||
122 | * @throws \UnexpectedValueException |
||
123 | */ |
||
124 | public function getRepositoryByContentTypeId($contentTypeId) |
||
128 | 10 | ||
129 | /** |
||
130 | 10 | * A method added to keep the API friendly to Doctrine users |
|
131 | * @param string $contentTypeIdentifier |
||
132 | * @param mixed $id Content Id |
||
133 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
||
134 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content with the given id does not exist |
||
135 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
||
136 | */ |
||
137 | public function find($contentTypeIdentifier, $id) |
||
141 | |||
142 | 4 | /** |
|
143 | * NB: this is slightly slower in execution than using find(), as it does have to look up the content type identifier. |
||
144 | 4 | * |
|
145 | * @param Location|Content|ContentInfo $content If you have a Content, by all means pass it in, not just its contentInfo |
||
146 | 4 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface |
|
147 | 2 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content with the given id does not exist |
|
148 | 2 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If a content type with the given id and status DEFINED can not be found |
|
149 | 2 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
|
150 | 4 | */ |
|
151 | 4 | public function load($content) |
|
170 | |||
171 | 2 | /** |
|
172 | * @param Content[]|Location[]|Contentinfo[]|SearchResult $contents |
||
173 | 2 | * @return \Kaliop\eZObjectWrapperBundle\Core\EntityInterface[] they keys of the $contents array get preserved |
|
174 | 1 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content with the given id does not exist |
|
175 | 1 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If a content type with the given id and status DEFINED can not be found |
|
176 | 1 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
|
177 | 1 | */ |
|
178 | 1 | public function loadMany($contents) |
|
197 | 7 | ||
198 | 7 | /** |
|
199 | 7 | * @param mixed $id |
|
200 | 7 | * @return string |
|
201 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If a content type with the given id and status DEFINED can not be found |
||
202 | */ |
||
203 | protected function getContentTypeIdentifierFromId($id) |
||
211 | } |
||
212 |