1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ODM\MongoDB\PersistentCollection; |
21
|
|
|
|
22
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
23
|
|
|
use Doctrine\Common\Collections\Collection as BaseCollection; |
24
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
25
|
|
|
use Doctrine\ODM\MongoDB\PersistentCollection; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Abstract factory for creating persistent collection classes. |
29
|
|
|
* |
30
|
|
|
* @since 1.1 |
31
|
|
|
*/ |
32
|
|
|
abstract class AbstractPersistentCollectionFactory implements PersistentCollectionFactory |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function create(DocumentManager $dm, array $mapping, BaseCollection $coll = null) |
38
|
|
|
{ |
39
|
|
|
if ($coll === null) { |
40
|
|
|
$coll = ! empty($mapping['collectionClass']) |
41
|
|
|
? $this->createCollectionClass($mapping['collectionClass']) |
42
|
|
|
: new ArrayCollection(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (empty($mapping['collectionClass'])) { |
46
|
|
|
return new PersistentCollection($coll, $dm, $dm->getUnitOfWork()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$className = $dm->getConfiguration()->getPersistentCollectionGenerator() |
50
|
|
|
->loadClass($mapping['collectionClass'], $dm->getConfiguration()->getAutoGeneratePersistentCollectionClasses()); |
51
|
|
|
|
52
|
|
|
return new $className($coll, $dm, $dm->getUnitOfWork()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Creates instance of collection class to be wrapped by PersistentCollection. |
57
|
|
|
* |
58
|
|
|
* @param string $collectionClass FQCN of class to instantiate |
59
|
|
|
* @return BaseCollection |
60
|
|
|
*/ |
61
|
|
|
abstract protected function createCollectionClass($collectionClass); |
62
|
|
|
} |
63
|
|
|
|