Skip to content

Commit ccd5c3e

Browse files
committedMar 7, 2023
Fix container dependancy resolution for optional params
1 parent ea62842 commit ccd5c3e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/*/config.php
2-
.idea
2+
.idea
3+
/vendor/

‎Framework/classes/Mvc/Application.php

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ public function runWeb($request = null, bool $returnResponse = false, bool $thro
152152

153153
$response = $this->container->get('web_handler')->process($request);
154154
} catch (ResponseException $e) {
155-
if ($throwExceptions) throw $e;
156155
$response = $e->getResponse();
157156
} catch (PageNotFound $e) {
158157
if ($throwExceptions) throw $e;

‎Framework/classes/Mvc/Container.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@ public function resolve(string $name)
126126

127127
$dependencies = [];
128128
foreach ($parameters as $parameter) {
129-
$dependencies[] = $this->get((string)$parameter->getType());
129+
$type = (string)$parameter->getType();
130+
131+
try {
132+
$dependencies[] = $this->get($type);
133+
} catch (ClassNotFound $e) {
134+
if (!$parameter->isOptional()) {
135+
throw $e;
136+
}
137+
}
130138
}
131139

132140
return new $name(...$dependencies);

0 commit comments

Comments
 (0)
Please sign in to comment.