Completed
Pull Request — master (#564)
by Michał
07:58
created

ConfigProvider::getDependencyConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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 DoctrineModule;
21
22
use Doctrine\Common\Cache;
23
use Zend\Authentication\Storage\Session;
24
use Zend\ServiceManager\Factory\InvokableFactory;
25
26
class ConfigProvider
27
{
28
    /**
29
     * Return general-purpose zend-i18n configuration.
30
     *
31
     * @return array
32
     */
33
    public function __invoke()
34
    {
35
        return [
36
            'console'            => $this->getConsoleConfig(),
37
            'controllers'        => $this->getControllerConfig(),
38
            'dependencies'       => $this->getDependencyConfig(),
39
            'doctrine'           => $this->getDoctrineConfig(),
40
            'doctrine_factories' => $this->getDoctrineFactoryConfig(),
41
            'route_manager'      => $this->getRouteManagerConfig(),
42
        ];
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getConsoleConfig()
49
    {
50
        return [
51
            'router' => [
52
                'routes' => [
53
                    'doctrine_cli' => [
54
                        'type' => 'symfony_cli',
55
                    ],
56
                ],
57
            ],
58
        ];
59
    }
60
61
    /**
62
     * @return array
63
     */
64
    public function getControllerConfig()
65
    {
66
        return [
67
            'factories' => [
68
                Controller\CliController::class => Service\CliControllerFactory::class,
69
            ],
70
        ];
71
    }
72
73
    /**
74
     * Return application-level dependency configuration.
75
     *
76
     * @return array
77
     */
78
    public function getDependencyConfig()
79
    {
80
        return [
81
            'aliases' => [
82
                'DoctrineModule\Authentication\Storage\Session' => Session::class,
83
            ],
84
            'factories' => [
85
                'doctrine.cli' => Service\CliFactory::class,
86
                Session::class => InvokableFactory::class,
87
            ],
88
            'abstract_factories' => [
89
                'DoctrineModule' => ServiceFactory\AbstractDoctrineServiceFactory::class,
90
            ],
91
        ];
92
    }
93
94
    /**
95
     * @return array
96
     */
97
    public function getDoctrineConfig()
98
    {
99
        return [
100
            'cache' => [
101
                'apcu' => [
102
                    'class'     => Cache\ApcuCache::class,
103
                    'namespace' => __NAMESPACE__,
104
                ],
105
                'array' => [
106
                    'class'     => Cache\ArrayCache::class,
107
                    'namespace' => __NAMESPACE__,
108
                ],
109
                'filesystem' => [
110
                    'class'     => Cache\FilesystemCache::class,
111
                    'directory' => 'data/DoctrineModule/cache',
112
                    'namespace' => __NAMESPACE__,
113
                ],
114
                'memcache' => [
115
                    'class'     => Cache\MemcacheCache::class,
116
                    'instance'  => 'my_memcache_alias',
117
                    'namespace' => __NAMESPACE__,
118
                ],
119
                'memcached' => [
120
                    'class'     => Cache\MemcachedCache::class,
121
                    'instance'  => 'my_memcached_alias',
122
                    'namespace' => __NAMESPACE__,
123
                ],
124
                'predis' => [
125
                    'class'     => Cache\PredisCache::class,
126
                    'instance'  => 'my_predis_alias',
127
                    'namespace' => __NAMESPACE__,
128
                ],
129
                'redis' => [
130
                    'class'     => Cache\RedisCache::class,
131
                    'instance'  => 'my_redis_alias',
132
                    'namespace' => __NAMESPACE__,
133
                ],
134
                'wincache' => [
135
                    'class'     => Cache\WinCacheCache::class,
136
                    'namespace' => __NAMESPACE__,
137
                ],
138
                'xcache' => [
139
                    'class'     => Cache\XcacheCache::class,
140
                    'namespace' => __NAMESPACE__,
141
                ],
142
                'zenddata' => [
143
                    'class'     => Cache\ZendDataCache::class,
144
                    'namespace' => __NAMESPACE__,
145
                ],
146
            ],
147
148
            // These authentication settings are a hack to tide things over until version 1.0
149
            // Normal doctrineModule should have no mention of odm or orm
150
            'authentication' => [
151
                // default authentication options should be set in either the odm or orm modules
152
                'odm_default' => [],
153
                'orm_default' => [],
154
            ],
155
            'authenticationadapter' => [
156
                'odm_default' => true,
157
                'orm_default' => true,
158
            ],
159
            'authenticationstorage' => [
160
                'odm_default' => true,
161
                'orm_default' => true,
162
            ],
163
            'authenticationservice' => [
164
                'odm_default' => true,
165
                'orm_default' => true,
166
            ],
167
        ];
168
    }
169
170
    /**
171
     * @return array
172
     */
173
    public function getDoctrineFactoryConfig()
174
    {
175
        return [
176
            'cache'                 => Service\CacheFactory::class,
177
            'eventmanager'          => Service\EventManagerFactory::class,
178
            'driver'                => Service\DriverFactory::class,
179
            'authenticationadapter' => Service\Authentication\AdapterFactory::class,
180
            'authenticationstorage' => Service\Authentication\StorageFactory::class,
181
            'authenticationservice' => Service\Authentication\AuthenticationServiceFactory::class,
182
        ];
183
    }
184
185
    /**
186
     * @return array
187
     */
188
    public function getRouteManagerConfig()
189
    {
190
        return [
191
            'factories' => [
192
                'symfony_cli' => Service\SymfonyCliRouteFactory::class,
193
            ],
194
        ];
195
    }
196
}
197