Completed
Push — ezp25946-migrate_files_to_othe... ( 56a30c...6cf922 )
by
unknown
24:31
created

RepositoryFactory::buildService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

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