|
31 | 31 | use PhpSchool\PhpWorkshop\Output\StdOutput; |
32 | 32 | use PhpSchool\PhpWorkshop\Patch; |
33 | 33 | use PhpSchool\PhpWorkshop\ResultAggregator; |
| 34 | +use PhpSchool\PSX\Factory as PsxFactory; |
34 | 35 | use PhpSchool\PSX\SyntaxHighlighter; |
35 | 36 | use PhpSchool\PhpWorkshop\Check\FileExistsCheck; |
36 | 37 | use PhpSchool\PhpWorkshop\Check\FunctionRequirementsCheck; |
|
57 | 58 |
|
58 | 59 | return [ |
59 | 60 | 'appName' => basename($_SERVER['argv'][0]), |
60 | | - ExerciseDispatcher::class => factory(function (ContainerInterface $c) { |
| 61 | + ExerciseDispatcher::class => function (ContainerInterface $c) { |
61 | 62 | $dispatcher = new ExerciseDispatcher( |
62 | 63 | $c->get(RunnerFactory::class), |
63 | 64 | $c->get(ResultAggregator::class), |
|
70 | 71 | $dispatcher->requireCheck(PhpLintCheck::class); |
71 | 72 | $dispatcher->requireCheck(CodeParseCheck::class); |
72 | 73 | return $dispatcher; |
73 | | - }), |
| 74 | + }, |
74 | 75 | ResultAggregator::class => object(ResultAggregator::class), |
75 | | - CheckRepository::class => factory(function (ContainerInterface $c) { |
| 76 | + CheckRepository::class => function (ContainerInterface $c) { |
76 | 77 | return new CheckRepository([ |
77 | 78 | $c->get(FileExistsCheck::class), |
78 | 79 | $c->get(PhpLintCheck::class), |
|
81 | 82 | $c->get(FunctionRequirementsCheck::class), |
82 | 83 | $c->get(DatabaseCheck::class), |
83 | 84 | ]); |
84 | | - }), |
85 | | - CommandRouter::class => factory(function (ContainerInterface $c) { |
| 85 | + }, |
| 86 | + CommandRouter::class => function (ContainerInterface $c) { |
86 | 87 | return new CommandRouter( |
87 | 88 | [ |
88 | 89 | new CommandDefinition('menu', [], MenuCommand::class), |
|
95 | 96 | 'menu', |
96 | 97 | $c |
97 | 98 | ); |
98 | | - }), |
| 99 | + }, |
99 | 100 |
|
100 | | - Color::class => factory(function (ContainerInterface $c) { |
| 101 | + Color::class => function () { |
101 | 102 | $colors = new Color; |
102 | 103 | $colors->setForceStyle(true); |
103 | 104 | return $colors; |
104 | | - }), |
105 | | - OutputInterface::class => factory(function (ContainerInterface $c) { |
| 105 | + }, |
| 106 | + OutputInterface::class => function (ContainerInterface $c) { |
106 | 107 | return new StdOutput($c->get(Color::class), $c->get(TerminalInterface::class)); |
107 | | - }), |
| 108 | + }, |
108 | 109 |
|
109 | | - ExerciseRepository::class => factory(function (ContainerInterface $c) { |
| 110 | + ExerciseRepository::class => function (ContainerInterface $c) { |
110 | 111 | return new ExerciseRepository( |
111 | 112 | array_map(function ($exerciseClass) use ($c) { |
112 | 113 | return $c->get($exerciseClass); |
113 | 114 | }, $c->get('exercises')) |
114 | 115 | ); |
115 | | - }), |
| 116 | + }, |
116 | 117 |
|
117 | | - EventDispatcher::class => factory([new EventDispatcherFactory, '__invoke']), |
| 118 | + EventDispatcher::class => factory(EventDispatcherFactory::class), |
| 119 | + EventDispatcherFactory::class => object(), |
118 | 120 |
|
119 | 121 | //Exercise Runners |
120 | | - RunnerFactory::class => factory(function (ContainerInterface $c) { |
121 | | - return new RunnerFactory; |
122 | | - }), |
| 122 | + RunnerFactory::class => object(), |
123 | 123 |
|
124 | 124 | //commands |
125 | | - MenuCommand::class => factory(function (ContainerInterface $c) { |
| 125 | + MenuCommand::class => function (ContainerInterface $c) { |
126 | 126 | return new MenuCommand($c->get('menu')); |
127 | | - }), |
| 127 | + }, |
128 | 128 |
|
129 | | - PrintCommand::class => factory(function (ContainerInterface $c) { |
| 129 | + PrintCommand::class => function (ContainerInterface $c) { |
130 | 130 | return new PrintCommand( |
131 | 131 | $c->get('appName'), |
132 | 132 | $c->get(ExerciseRepository::class), |
133 | 133 | $c->get(UserState::class), |
134 | 134 | $c->get(MarkdownRenderer::class), |
135 | 135 | $c->get(OutputInterface::class) |
136 | 136 | ); |
137 | | - }), |
| 137 | + }, |
138 | 138 |
|
139 | | - VerifyCommand::class => factory(function (ContainerInterface $c) { |
| 139 | + VerifyCommand::class => function (ContainerInterface $c) { |
140 | 140 | return new VerifyCommand( |
141 | 141 | $c->get(ExerciseRepository::class), |
142 | 142 | $c->get(ExerciseDispatcher::class), |
|
145 | 145 | $c->get(OutputInterface::class), |
146 | 146 | $c->get(ResultsRenderer::class) |
147 | 147 | ); |
148 | | - }), |
| 148 | + }, |
149 | 149 |
|
150 | | - RunCommand::class => factory(function (ContainerInterface $c) { |
| 150 | + RunCommand::class => function (ContainerInterface $c) { |
151 | 151 | return new RunCommand( |
152 | 152 | $c->get(ExerciseRepository::class), |
153 | 153 | $c->get(ExerciseDispatcher::class), |
154 | 154 | $c->get(UserState::class), |
155 | 155 | $c->get(UserStateSerializer::class), |
156 | 156 | $c->get(OutputInterface::class) |
157 | 157 | ); |
158 | | - }), |
| 158 | + }, |
159 | 159 |
|
160 | | - CreditsCommand::class => factory(function (ContainerInterface $c) { |
| 160 | + CreditsCommand::class => function (ContainerInterface $c) { |
161 | 161 | return new CreditsCommand( |
162 | 162 | $c->get('coreContributors'), |
163 | 163 | $c->get('appContributors'), |
164 | 164 | $c->get(OutputInterface::class), |
165 | 165 | $c->get(Color::class) |
166 | 166 | ); |
167 | | - }), |
| 167 | + }, |
168 | 168 |
|
169 | | - HelpCommand::class => factory(function (ContainerInterface $c) { |
| 169 | + HelpCommand::class => function (ContainerInterface $c) { |
170 | 170 | return new HelpCommand( |
171 | 171 | $c->get('appName'), |
172 | 172 | $c->get(OutputInterface::class), |
173 | 173 | $c->get(Color::class) |
174 | 174 | ); |
175 | | - }), |
| 175 | + }, |
176 | 176 |
|
177 | 177 | //Listeners |
178 | 178 | PrepareSolutionListener::class => object(), |
179 | | - CodePatchListener::class => factory(function (ContainerInterface $c) { |
| 179 | + CodePatchListener::class => function (ContainerInterface $c) { |
180 | 180 | return new CodePatchListener($c->get(CodePatcher::class)); |
181 | | - }), |
182 | | - SelfCheckListener::class => factory(function (ContainerInterface $c) { |
| 181 | + }, |
| 182 | + SelfCheckListener::class => function (ContainerInterface $c) { |
183 | 183 | return new SelfCheckListener($c->get(ResultAggregator::class)); |
184 | | - }), |
| 184 | + }, |
185 | 185 |
|
186 | 186 | //checks |
187 | | - FileExistsCheck::class => object(FileExistsCheck::class), |
188 | | - PhpLintCheck::class => object(PhpLintCheck::class), |
189 | | - CodeParseCheck::class => factory(function (ContainerInterface $c) { |
| 187 | + FileExistsCheck::class => object(), |
| 188 | + PhpLintCheck::class => object(), |
| 189 | + CodeParseCheck::class => function (ContainerInterface $c) { |
190 | 190 | return new CodeParseCheck($c->get(Parser::class)); |
191 | | - }), |
192 | | - FunctionRequirementsCheck::class => factory(function (ContainerInterface $c) { |
| 191 | + }, |
| 192 | + FunctionRequirementsCheck::class => function (ContainerInterface $c) { |
193 | 193 | return new FunctionRequirementsCheck($c->get(Parser::class)); |
194 | | - }), |
195 | | - DatabaseCheck::class => object(DatabaseCheck::class), |
196 | | - ComposerCheck::class => object(ComposerCheck::class), |
| 194 | + }, |
| 195 | + DatabaseCheck::class => object(), |
| 196 | + ComposerCheck::class => object(), |
197 | 197 |
|
198 | 198 | //Utils |
199 | | - Filesystem::class => object(Filesystem::class), |
200 | | - Parser::class => factory(function (ContainerInterface $c) { |
| 199 | + Filesystem::class => object(), |
| 200 | + Parser::class => function () { |
201 | 201 | $parserFactory = new ParserFactory; |
202 | 202 | return $parserFactory->create(ParserFactory::PREFER_PHP7); |
203 | | - }), |
204 | | - CodePatcher::class => factory(function (ContainerInterface $c) { |
| 203 | + }, |
| 204 | + CodePatcher::class => function (ContainerInterface $c) { |
205 | 205 | $patch = (new Patch) |
206 | 206 | ->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'ini_set("display_errors", 1);')) |
207 | 207 | ->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'error_reporting(E_ALL);')) |
208 | 208 | ->withInsertion(new Insertion(Insertion ::TYPE_BEFORE, 'date_default_timezone_set("Europe/London");')); |
209 | 209 |
|
210 | 210 | return new CodePatcher($c->get(Parser::class), new Standard, $patch); |
211 | | - }), |
212 | | - FakerGenerator::class => factory(function (ContainerInterface $c) { |
| 211 | + }, |
| 212 | + FakerGenerator::class => function () { |
213 | 213 | return FakerFactory::create(); |
214 | | - }), |
| 214 | + }, |
215 | 215 |
|
216 | 216 | TerminalInterface::class => factory([TerminalFactory::class, 'fromSystem']), |
217 | | - 'menu' => factory([new MenuFactory, '__invoke']), |
218 | | - ExerciseRenderer::class => factory(function (ContainerInterface $c) { |
| 217 | + 'menu' => factory(MenuFactory::class), |
| 218 | + MenuFactory::class => object(), |
| 219 | + ExerciseRenderer::class => function (ContainerInterface $c) { |
219 | 220 | return new ExerciseRenderer( |
220 | 221 | $c->get('appName'), |
221 | 222 | $c->get(ExerciseRepository::class), |
|
225 | 226 | $c->get(Color::class), |
226 | 227 | $c->get(OutputInterface::class) |
227 | 228 | ); |
228 | | - }), |
229 | | - MarkdownRenderer::class => factory(function (ContainerInterface $c) { |
| 229 | + }, |
| 230 | + MarkdownRenderer::class => function (ContainerInterface $c) { |
230 | 231 | $docParser = new DocParser(Environment::createCommonMarkEnvironment()); |
231 | 232 | $cliRenderer = (new MarkdownCliRendererFactory)->__invoke($c); |
232 | 233 | return new MarkdownRenderer($docParser, $cliRenderer); |
233 | | - }), |
234 | | - UserStateSerializer::class => factory(function (ContainerInterface $c) { |
| 234 | + }, |
| 235 | + UserStateSerializer::class => function (ContainerInterface $c) { |
235 | 236 | return new UserStateSerializer( |
236 | 237 | getenv('HOME'), |
237 | 238 | $c->get('workshopTitle'), |
238 | 239 | $c->get(ExerciseRepository::class) |
239 | 240 | ); |
240 | | - }), |
241 | | - UserState::class => factory(function (ContainerInterface $c) { |
| 241 | + }, |
| 242 | + UserState::class => function (ContainerInterface $c) { |
242 | 243 | return $c->get(UserStateSerializer::class)->deSerialize(); |
243 | | - }), |
244 | | - SyntaxHighlighter::class => factory(function (ContainerInterface $c) { |
245 | | - return (new \PhpSchool\PSX\Factory)->__invoke(); |
246 | | - }), |
247 | | - ResetProgress::class => factory(function (ContainerInterface $c) { |
| 244 | + }, |
| 245 | + SyntaxHighlighter::class => factory(PsxFactory::class), |
| 246 | + PsxFactory::class => object(), |
| 247 | + ResetProgress::class => function (ContainerInterface $c) { |
248 | 248 | return new ResetProgress( |
249 | 249 | $c->get(UserStateSerializer::class), |
250 | 250 | $c->get(OutputInterface::class) |
251 | 251 | ); |
252 | | - }), |
| 252 | + }, |
253 | 253 | ResultRendererFactory::class => object(), |
254 | | - ResultsRenderer::class => factory(function (ContainerInterface $c) { |
| 254 | + ResultsRenderer::class => function (ContainerInterface $c) { |
255 | 255 | return new ResultsRenderer( |
256 | 256 | $c->get('appName'), |
257 | 257 | $c->get(Color::class), |
|
260 | 260 | $c->get(SyntaxHighlighter::class), |
261 | 261 | $c->get(ResultRendererFactory::class) |
262 | 262 | ); |
263 | | - }), |
| 263 | + }, |
264 | 264 | 'coreContributors' => [ |
265 | 265 | '@AydinHassan' => 'Aydin Hassan', |
266 | 266 | '@mikeymike' => 'Michael Woodward', |
|
0 commit comments