Completed
Push — master ( 3eb757...3bc7c8 )
by Oleg
03:46
created

ConfigProvider::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 5
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Domain;
5
6
use Psr\Log\LoggerInterface;
7
use SlayerBirden\DataFlowServer\Doctrine\Persistence\EntityManagerRegistry;
8
use SlayerBirden\DataFlowServer\Domain\Controller\AddUserAction;
9
use SlayerBirden\DataFlowServer\Domain\Controller\DeleteUserAction;
10
use SlayerBirden\DataFlowServer\Domain\Controller\GetUserAction;
11
use SlayerBirden\DataFlowServer\Domain\Controller\GetUsersAction;
12
use SlayerBirden\DataFlowServer\Domain\Controller\UpdateUserAction;
13
use SlayerBirden\DataFlowServer\Domain\Factory\UserResourceMiddlewareFactory;
14
use SlayerBirden\DataFlowServer\Domain\Repository\UserRepository;
15
use SlayerBirden\DataFlowServer\Zend\InputFilter\ProxyFilterManagerFactory;
16
use Zend\Expressive\Application;
17
use Zend\Hydrator\ClassMethods;
18
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
19
20
class ConfigProvider
21
{
22
    public function __invoke(): array
23
    {
24
        return [
25
            ConfigAbstractFactory::class => $this->getAbstractFactoryConfig(),
26
            'doctrine' => $this->getDoctrineConfig(),
27
            'dependencies' => $this->getDependenciesConfig(),
28
            'input_filter_specs' => [
29
                'UserInputFilter' => $this->getUserInputFilterSpec(),
30
            ],
31
        ];
32
    }
33
34
    private function getUserInputFilterSpec(): array
35
    {
36
        return [
37
            'first' => [
38
                'required' => true,
39
                'filters' => [
40
                    [
41
                        'name' => 'stringtrim',
42
                    ]
43
                ],
44
                'validators' => [
45
                    [
46
                        'name' => 'notempty',
47
                    ],
48
                    [
49
                        'name' => 'alpha',
50
                    ],
51
                ]
52
            ],
53
            'last' => [
54
                'required' => true,
55
                'filters' => [
56
                    [
57
                        'name' => 'stringtrim',
58
                    ]
59
                ],
60
                'validators' => [
61
                    [
62
                        'name' => 'notempty',
63
                    ],
64
                    [
65
                        'name' => 'alpha',
66
                    ],
67
                ]
68
            ],
69
            'email' => [
70
                'required' => true,
71
                'filters' => [
72
                    [
73
                        'name' => 'stringtrim',
74
                    ]
75
                ],
76
                'validators' => [
77
                    [
78
                        'name' => 'notempty',
79
                    ],
80
                    [
81
                        'name' => 'emailAddress',
82
                    ],
83
                ],
84
            ],
85
        ];
86
    }
87
88
    private function getAbstractFactoryConfig(): array
89
    {
90
        return [
91
            UserRepository::class => [
92
                EntityManagerRegistry::class,
93
            ],
94
            AddUserAction::class => [
95
                EntityManagerRegistry::class,
96
                ClassMethods::class,
97
                'UserInputFilter',
98
                LoggerInterface::class,
99
            ],
100
            UpdateUserAction::class => [
101
                EntityManagerRegistry::class,
102
                ClassMethods::class,
103
                'UserInputFilter',
104
                LoggerInterface::class,
105
            ],
106
            GetUserAction::class => [
107
                ClassMethods::class,
108
            ],
109
            GetUsersAction::class => [
110
                UserRepository::class,
111
                LoggerInterface::class,
112
                ClassMethods::class,
113
            ],
114
            DeleteUserAction::class => [
115
                EntityManagerRegistry::class,
116
                LoggerInterface::class,
117
                ClassMethods::class,
118
            ],
119
        ];
120
    }
121
122
    private function getDoctrineConfig(): array
123
    {
124
        return [
125
            'entity_managers' => [
126
                'default' => [
127
                    'paths' => [
128
                        'src/Domain/Entities',
129
                    ],
130
                ],
131
            ],
132
        ];
133
    }
134
135
    private function getDependenciesConfig(): array
136
    {
137
        return [
138
            'delegators' => [
139
                Application::class => [
140
                    Factory\RoutesDelegator::class,
141
                ]
142
            ],
143
            'factories' => [
144
                'UserInputFilter' => ProxyFilterManagerFactory::class,
145
                'UserResourceMiddleware' => UserResourceMiddlewareFactory::class,
146
            ],
147
        ];
148
    }
149
}
150