Completed
Pull Request — master (#479)
by Michał
08:23
created

ConfigProvider::getFormElementConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

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 10
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 DoctrineORMModule;
21
22
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
23
use Doctrine\DBAL\Tools\Console\Command as DBALCommand;
24
use Doctrine\ORM\Tools\Console\Command as ORMCommand;
25
use DoctrineModule\Form\Element;
26
use DoctrineModule\Stdlib\Hydrator\DoctrineObject;
27
use DoctrineORMModule\Yuml\YumlController;
28
use DoctrineORMModule\Yuml\YumlControllerFactory;
29
use Zend\Router\Http\Literal;
30
use Zend\ServiceManager\Factory\InvokableFactory;
31
32
class ConfigProvider
33
{
34
    /**
35
     * Return general-purpose zend-i18n configuration.
36
     *
37
     * @return array
38
     */
39
    public function __invoke()
40
    {
41
        return [
42
            'controllers'        => $this->getControllerConfig(),
43
            'dependencies'       => $this->getDependencyConfig(),
44
            'doctrine'           => $this->getDoctrineConfig(),
45
            'doctrine_factories' => $this->getDoctrineFactoryConfig(),
46
            'form_elements'      => $this->getFormElementConfig(),
47
            'hydrators'          => $this->getHydratorConfig(),
48
            'router'             => $this->getRouterConfig(),
49
            'view_manager'       => $this->getViewManagerConfig(),
50
            'zenddevelopertools' => $this->getZendDeveloperToolConfig(),
51
        ];
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function getControllerConfig()
58
    {
59
        return [
60
            'factories' => [
61
                YumlController::class => YumlControllerFactory::class,
62
            ],
63
        ];
64
    }
65
66
    /**
67
     * Return application-level dependency configuration.
68
     *
69
     * @return array
70
     */
71
    public function getDependencyConfig()
72
    {
73
        return [
74
            'aliases' => [
75
                // DBAL commands
76
                'doctrine.dbal_cmd.runsql' => DBALCommand\RunSqlCommand::class,
77
                'doctrine.dbal_cmd.import' => DBALCommand\ImportCommand::class,
78
                // ORM Commands
79
                'doctrine.orm_cmd.clear_cache_metadata'       => ORMCommand\ClearCache\MetadataCommand::class,
80
                'doctrine.orm_cmd.clear_cache_result'         => ORMCommand\ClearCache\ResultCommand::class,
81
                'doctrine.orm_cmd.clear_cache_query'          => ORMCommand\ClearCache\QueryCommand::class,
82
                'doctrine.orm_cmd.schema_tool_create'         => ORMCommand\SchemaTool\CreateCommand::class,
83
                'doctrine.orm_cmd.schema_tool_update'         => ORMCommand\SchemaTool\UpdateCommand::class,
84
                'doctrine.orm_cmd.schema_tool_drop'           => ORMCommand\SchemaTool\DropCommand::class,
85
                'doctrine.orm_cmd.convert_d1_schema'          => ORMCommand\ConvertDoctrine1SchemaCommand::class,
86
                'doctrine.orm_cmd.generate_entities'          => ORMCommand\GenerateEntitiesCommand::class,
87
                'doctrine.orm_cmd.generate_proxies'           => ORMCommand\GenerateProxiesCommand::class,
88
                'doctrine.orm_cmd.convert_mapping'            => ORMCommand\ConvertMappingCommand::class,
89
                'doctrine.orm_cmd.run_dql'                    => ORMCommand\RunDqlCommand::class,
90
                'doctrine.orm_cmd.validate_schema'            => ORMCommand\ValidateSchemaCommand::class,
91
                'doctrine.orm_cmd.info'                       => ORMCommand\InfoCommand::class,
92
                'doctrine.orm_cmd.ensure_production_settings' => ORMCommand\EnsureProductionSettingsCommand::class,
93
                'doctrine.orm_cmd.generate_repositories'      => ORMCommand\GenerateRepositoriesCommand::class,
94
            ],
95
            'factories' => [
96
                'Doctrine\ORM\EntityManager' => Service\EntityManagerAliasCompatFactory::class,
97
                DBALCommand\RunSqlCommand::class                  => InvokableFactory::class,
98
                DBALCommand\ImportCommand::class                  => InvokableFactory::class,
99
                ORMCommand\ClearCache\MetadataCommand::class      => InvokableFactory::class,
100
                ORMCommand\ClearCache\ResultCommand::class        => InvokableFactory::class,
101
                ORMCommand\ClearCache\QueryCommand::class         => InvokableFactory::class,
102
                ORMCommand\SchemaTool\CreateCommand::class        => InvokableFactory::class,
103
                ORMCommand\SchemaTool\UpdateCommand::class        => InvokableFactory::class,
104
                ORMCommand\SchemaTool\DropCommand::class          => InvokableFactory::class,
105
                ORMCommand\ConvertDoctrine1SchemaCommand::class   => InvokableFactory::class,
106
                ORMCommand\GenerateEntitiesCommand::class         => InvokableFactory::class,
107
                ORMCommand\GenerateProxiesCommand::class          => InvokableFactory::class,
108
                ORMCommand\ConvertMappingCommand::class           => InvokableFactory::class,
109
                ORMCommand\RunDqlCommand::class                   => InvokableFactory::class,
110
                ORMCommand\ValidateSchemaCommand::class           => InvokableFactory::class,
111
                ORMCommand\InfoCommand::class                     => InvokableFactory::class,
112
                ORMCommand\EnsureProductionSettingsCommand::class => InvokableFactory::class,
113
                ORMCommand\GenerateRepositoriesCommand::class     => InvokableFactory::class,
114
            ],
115
        ];
116
    }
117
118
    /**
119
     * @return array
120
     */
121
    public function getDoctrineConfig()
122
    {
123
        return [
124
            'connection' => [
125
                // Configuration for service `doctrine.connection.orm_default` service
126
                'orm_default' => [
127
                    // configuration instance to use. The retrieved service name will
128
                    // be `doctrine.configuration.$thisSetting`
129
                    'configuration' => 'orm_default',
130
131
                    // event manager instance to use. The retrieved service name will
132
                    // be `doctrine.eventmanager.$thisSetting`
133
                    'eventmanager'  => 'orm_default',
134
135
                    // connection parameters, see
136
                    // http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html
137
                    'params' => [
138
                        'host'     => 'localhost',
139
                        'port'     => '3306',
140
                        'user'     => 'username',
141
                        'password' => 'password',
142
                        'dbname'   => 'database',
143
                    ],
144
                ],
145
            ],
146
147
            // Configuration details for the ORM.
148
            // See http://docs.doctrine-project.org/en/latest/reference/configuration.html
149
            'configuration' => [
150
                // Configuration for service `doctrine.configuration.orm_default` service
151
                'orm_default' => [
152
                    // metadata cache instance to use. The retrieved service name will
153
                    // be `doctrine.cache.$thisSetting`
154
                    'metadata_cache'    => 'array',
155
156
                    // DQL queries parsing cache instance to use. The retrieved service
157
                    // name will be `doctrine.cache.$thisSetting`
158
                    'query_cache'       => 'array',
159
160
                    // ResultSet cache to use.  The retrieved service name will be
161
                    // `doctrine.cache.$thisSetting`
162
                    'result_cache'      => 'array',
163
164
                    // Hydration cache to use.  The retrieved service name will be
165
                    // `doctrine.cache.$thisSetting`
166
                    'hydration_cache'   => 'array',
167
168
                    // Mapping driver instance to use. Change this only if you don't want
169
                    // to use the default chained driver. The retrieved service name will
170
                    // be `doctrine.driver.$thisSetting`
171
                    'driver'            => 'orm_default',
172
173
                    // Generate proxies automatically (turn off for production)
174
                    'generate_proxies'  => true,
175
176
                    // directory where proxies will be stored. By default, this is in
177
                    // the `data` directory of your application
178
                    'proxy_dir'         => 'data/DoctrineORMModule/Proxy',
179
180
                    // namespace for generated proxy classes
181
                    'proxy_namespace'   => 'DoctrineORMModule\Proxy',
182
183
                    // SQL filters. See http://docs.doctrine-project.org/en/latest/reference/filters.html
184
                    'filters'           => [],
185
186
                    // Custom DQL functions.
187
                    // You can grab common MySQL ones at https://github.com/beberlei/DoctrineExtensions
188
                    // Further docs at
189
                    // http://docs.doctrine-project.org/en/latest/cookbook/dql-user-defined-functions.html
190
                    'datetime_functions' => [],
191
                    'string_functions'   => [],
192
                    'numeric_functions'  => [],
193
194
                    // Second level cache configuration (see doc to learn about configuration)
195
                    'second_level_cache' => [],
196
                ],
197
            ],
198
199
            // Metadata Mapping driver configuration
200
            'driver' => [
201
                // Configuration for service `doctrine.driver.orm_default` service
202
                'orm_default' => [
203
                    // By default, the ORM module uses a driver chain. This allows multiple
204
                    // modules to define their own entities
205
                    'class'   => MappingDriverChain::class,
206
207
                    // Map of driver names to be used within this driver chain, indexed by
208
                    // entity namespace
209
                    'drivers' => [],
210
                ],
211
            ],
212
213
            // Entity Manager instantiation settings
214
            'entitymanager' => [
215
                // configuration for the `doctrine.entitymanager.orm_default` service
216
                'orm_default' => [
217
                    // connection instance to use. The retrieved service name will
218
                    // be `doctrine.connection.$thisSetting`
219
                    'connection'    => 'orm_default',
220
221
                    // configuration instance to use. The retrieved service name will
222
                    // be `doctrine.configuration.$thisSetting`
223
                    'configuration' => 'orm_default',
224
                ],
225
            ],
226
227
            'eventmanager' => [
228
                // configuration for the `doctrine.eventmanager.orm_default` service
229
                'orm_default' => [],
230
            ],
231
232
            // SQL logger collector, used when ZendDeveloperTools and its toolbar are active
233
            'sql_logger_collector' => [
234
                // configuration for the `doctrine.sql_logger_collector.orm_default` service
235
                'orm_default' => [],
236
            ],
237
238
            // mappings collector, used when ZendDeveloperTools and its toolbar are active
239
            'mapping_collector' => [
240
                // configuration for the `doctrine.sql_logger_collector.orm_default` service
241
                'orm_default' => [],
242
            ],
243
244
            // form annotation builder configuration
245
            'formannotationbuilder' => [
246
                // Configuration for service `doctrine.formannotationbuilder.orm_default` service
247
                'orm_default' => [],
248
            ],
249
250
            // entity resolver configuration, allows mapping associations to interfaces
251
            'entity_resolver' => [
252
                // configuration for the `doctrine.entity_resolver.orm_default` service
253
                'orm_default' => [],
254
            ],
255
256
            // authentication service configuration
257
            'authentication' => [
258
                // configuration for the `doctrine.authentication.orm_default` authentication service
259
                'orm_default' => [
260
                    // name of the object manager to use. By default, the EntityManager is used
261
                    'objectManager' => 'doctrine.entitymanager.orm_default',
262
                    //'identityClass' => 'Application\Model\User',
263
                    //'identityProperty' => 'username',
264
                    //'credentialProperty' => 'password',
265
                ],
266
            ],
267
268
            // migrations configuration
269
            'migrations_configuration' => [
270
                'orm_default' => [
271
                    'directory' => 'data/DoctrineORMModule/Migrations',
272
                    'name'      => 'Doctrine Database Migrations',
273
                    'namespace' => 'DoctrineORMModule\Migrations',
274
                    'table'     => 'migrations',
275
                    'column'    => 'version',
276
                ],
277
            ],
278
279
            // migrations commands base config
280
            'migrations_cmd' => [
281
                'generate' => [],
282
                'execute'  => [],
283
                'migrate'  => [],
284
                'status'   => [],
285
                'version'  => [],
286
                'diff'     => [],
287
                'latest'   => [],
288
            ],
289
        ];
290
    }
291
292
    /**
293
     * @return array
294
     */
295
    public function getDoctrineFactoryConfig()
296
    {
297
        return [
298
            'connection'               => Service\DBALConnectionFactory::class,
299
            'configuration'            => Service\ConfigurationFactory::class,
300
            'entitymanager'            => Service\EntityManagerFactory::class,
301
            'entity_resolver'          => Service\EntityResolverFactory::class,
302
            'sql_logger_collector'     => Service\SQLLoggerCollectorFactory::class,
303
            'mapping_collector'        => Service\MappingCollectorFactory::class,
304
            'formannotationbuilder'    => Service\FormAnnotationBuilderFactory::class,
305
            'migrations_configuration' => Service\MigrationsConfigurationFactory::class,
306
            'migrations_cmd'           => Service\MigrationsCommandFactory::class,
307
        ];
308
    }
309
310
    public function getFormElementConfig()
311
    {
312
        return [
313
            'aliases' => [
314
                'objectselect'        => Element\ObjectSelect::class,
315
                'objectradio'         => Element\ObjectRadio::class,
316
                'objectmulticheckbox' => Element\ObjectMultiCheckbox::class,
317
            ],
318
            'factories' => [
319
                Element\ObjectSelect::class        => Service\ObjectSelectFactory::class,
320
                Element\ObjectRadio::class         => Service\ObjectRadioFactory::class,
321
                Element\ObjectMultiCheckbox::class => Service\ObjectMultiCheckboxFactory::class,
322
            ],
323
        ];
324
    }
325
326
    /**
327
     * @return array
328
     */
329
    public function getHydratorConfig()
330
    {
331
        return [
332
            'factories' => [
333
                DoctrineObject::class => Service\DoctrineObjectHydratorFactory::class,
334
            ],
335
        ];
336
    }
337
338
    /**
339
     * @return array
340
     */
341
    public function getRouterConfig()
342
    {
343
        return [
344
            'routes' => [
345
                'doctrine_orm_module_yuml' => [
346
                    'type' => Literal::class,
347
                    'options' => [
348
                        'route' => '/ocra_service_manager_yuml',
349
                        'defaults' => [
350
                            'controller' => Yuml\YumlController::class,
351
                            'action'     => 'index',
352
                        ],
353
                    ],
354
                ],
355
            ],
356
        ];
357
    }
358
359
    /**
360
     * @return array
361
     */
362
    public function getViewManagerConfig()
363
    {
364
        return [
365
            'template_map' => [
366
                'zend-developer-tools/toolbar/doctrine-orm-queries'
367
                    => __DIR__ . '/../view/zend-developer-tools/toolbar/doctrine-orm-queries.phtml',
368
                'zend-developer-tools/toolbar/doctrine-orm-mappings'
369
                    => __DIR__ . '/../view/zend-developer-tools/toolbar/doctrine-orm-mappings.phtml',
370
            ],
371
        ];
372
    }
373
374
    /**
375
     * @return array
376
     */
377
    public function getZendDeveloperToolConfig()
378
    {
379
        return [
380
            'profiler' => [
381
                'collectors' => [
382
                    'doctrine.sql_logger_collector.orm_default' => 'doctrine.sql_logger_collector.orm_default',
383
                    'doctrine.mapping_collector.orm_default'    => 'doctrine.mapping_collector.orm_default',
384
                ],
385
            ],
386
            'toolbar' => [
387
                'entries' => [
388
                    'doctrine.sql_logger_collector.orm_default' => 'zend-developer-tools/toolbar/doctrine-orm-queries',
389
                    'doctrine.mapping_collector.orm_default'    => 'zend-developer-tools/toolbar/doctrine-orm-mappings',
390
                ],
391
            ],
392
        ];
393
    }
394
}
395