Completed
Push — 6.12 ( 945ca3...d0ab56 )
by André
58:04 queued 42:29
created

RepositoryFactory::buildRepository()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 19
nc 1
nop 3
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the RepositoryFactory class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishCoreBundle\ApiLoader;
10
11
use eZ\Publish\Core\MVC\ConfigResolverInterface;
12
use eZ\Publish\Core\Repository\Values\User\UserReference;
13
use eZ\Publish\Core\Search\Common\BackgroundIndexer;
14
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler;
15
use eZ\Publish\SPI\Search\Handler as SearchHandler;
16
use eZ\Publish\SPI\Limitation\Type as SPILimitationType;
17
use eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeCollectionFactory;
18
use eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeNameableCollectionFactory;
19
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
20
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
21
22
class RepositoryFactory implements ContainerAwareInterface
23
{
24
    use ContainerAwareTrait;
25
26
    /**
27
     * @var \eZ\Publish\Core\MVC\ConfigResolverInterface
28
     */
29
    private $configResolver;
30
31
    /**
32
     * Collection of fieldTypes, lazy loaded via a closure.
33
     *
34
     * @var \eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeCollectionFactory
35
     */
36
    protected $fieldTypeCollectionFactory;
37
38
    /**
39
     * Collection of fieldTypes, lazy loaded via a closure.
40
     *
41
     * @var \eZ\Publish\Core\Base\Container\ApiLoader\FieldTypeNameableCollectionFactory
42
     */
43
    protected $fieldTypeNameableCollectionFactory;
44
45
    /**
46
     * @var string
47
     */
48
    private $repositoryClass;
49
50
    /**
51
     * Collection of limitation types for the RoleService.
52
     *
53
     * @var \eZ\Publish\SPI\Limitation\Type[]
54
     */
55
    protected $roleLimitations = array();
56
57
    /**
58
     * @var array
59
     */
60
    private $policyMap;
61
62
    public function __construct(
63
        ConfigResolverInterface $configResolver,
64
        FieldTypeCollectionFactory $fieldTypeCollectionFactory,
65
        FieldTypeNameableCollectionFactory $fieldTypeNameableCollectionFactory,
66
        $repositoryClass,
67
        array $policyMap
68
    ) {
69
        $this->configResolver = $configResolver;
70
        $this->fieldTypeCollectionFactory = $fieldTypeCollectionFactory;
71
        $this->fieldTypeNameableCollectionFactory = $fieldTypeNameableCollectionFactory;
72
        $this->repositoryClass = $repositoryClass;
73
        $this->policyMap = $policyMap;
74
    }
75
76
    /**
77
     * Builds the main repository, heart of eZ Publish API.
78
     *
79
     * This always returns the true inner Repository, please depend on ezpublish.api.repository and not this method
80
     * directly to make sure you get an instance wrapped inside Signal / Cache / * functionality.
81
     *
82
     * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler
83
     * @param \eZ\Publish\SPI\Search\Handler $searchHandler
84
     * @param \eZ\Publish\Core\Search\Common\BackgroundIndexer $backgroundIndexer
85
     *
86
     * @return \eZ\Publish\API\Repository\Repository
87
     */
88
    public function buildRepository(
89
        PersistenceHandler $persistenceHandler,
90
        SearchHandler $searchHandler,
91
        BackgroundIndexer $backgroundIndexer
92
    ) {
93
        $config = $this->container->get('ezpublish.api.repository_configuration_provider')->getRepositoryConfig();
94
95
        $repository = new $this->repositoryClass(
96
            $persistenceHandler,
97
            $searchHandler,
98
            $backgroundIndexer,
99
            array(
100
                'fieldType' => $this->fieldTypeCollectionFactory->getFieldTypes(),
101
                'nameableFieldTypes' => $this->fieldTypeNameableCollectionFactory->getNameableFieldTypes(),
102
                'role' => array(
103
                    'limitationTypes' => $this->roleLimitations,
104
                    'policyMap' => $this->policyMap,
105
                ),
106
                'languages' => $this->configResolver->getParameter('languages'),
107
                'content' => ['default_version_archive_limit' => $config['options']['default_version_archive_limit']],
108
            ),
109
            new UserReference($this->configResolver->getParameter('anonymous_user_id'))
110
        );
111
112
        return $repository;
113
    }
114
115
    /**
116
     * Registers a limitation type for the RoleService.
117
     *
118
     * @param string $limitationName
119
     * @param \eZ\Publish\SPI\Limitation\Type $limitationType
120
     */
121
    public function registerLimitationType($limitationName, SPILimitationType $limitationType)
122
    {
123
        $this->roleLimitations[$limitationName] = $limitationType;
124
    }
125
}
126