| 1 | <?php |
||
| 15 | abstract class AbstractPersistentCollectionFactory implements PersistentCollectionFactory |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * {@inheritdoc} |
||
| 19 | */ |
||
| 20 | 421 | public function create(DocumentManager $dm, array $mapping, ?BaseCollection $coll = null) : PersistentCollectionInterface |
|
| 21 | { |
||
| 22 | 421 | if ($coll === null) { |
|
| 23 | 247 | $coll = ! empty($mapping['collectionClass']) |
|
| 24 | 6 | ? $this->createCollectionClass($mapping['collectionClass']) |
|
| 25 | 247 | : new ArrayCollection(); |
|
| 26 | } |
||
| 27 | |||
| 28 | 421 | if (empty($mapping['collectionClass'])) { |
|
| 29 | 419 | return new PersistentCollection($coll, $dm, $dm->getUnitOfWork()); |
|
| 30 | } |
||
| 31 | |||
| 32 | 7 | $className = $dm->getConfiguration()->getPersistentCollectionGenerator() |
|
| 33 | 7 | ->loadClass($mapping['collectionClass'], $dm->getConfiguration()->getAutoGeneratePersistentCollectionClasses()); |
|
| 34 | |||
| 35 | 7 | return new $className($coll, $dm, $dm->getUnitOfWork()); |
|
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Creates instance of collection class to be wrapped by PersistentCollection. |
||
| 40 | * |
||
| 41 | * @param string $collectionClass FQCN of class to instantiate |
||
| 42 | * |
||
| 43 | * @return BaseCollection |
||
| 44 | */ |
||
| 45 | abstract protected function createCollectionClass(string $collectionClass) : BaseCollection; |
||
| 46 | } |
||
| 47 |