Completed
Pull Request — master (#1219)
by Maciej
13:47
created

createCollectionClass()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
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 387
    public function create(DocumentManager $dm, array $mapping, BaseCollection $coll = null)
38
    {
39 387
        if ($coll === null) {
40 256
            $coll = ! empty($mapping['collectionClass'])
41 256
                ? $this->createCollectionClass($mapping['collectionClass'])
42 256
                : new ArrayCollection();
43 256
        }
44
45 387
        if (empty($mapping['collectionClass'])) {
46 386
            return new PersistentCollection($coll, $dm, $dm->getUnitOfWork());
47
        }
48
49 4
        $className = $dm->getConfiguration()->getPersistentCollectionGenerator()
50 4
            ->loadClass($mapping['collectionClass'], $dm->getConfiguration()->getAutoGeneratePersistentCollectionClasses());
51
52 4
        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