|
5 | 5 |
|
6 | 6 | use Plaisio\ExceptionHandler\ExceptionHandler; |
7 | 7 | use Plaisio\PlaisioObject; |
| 8 | +use Plaisio\Response\Response; |
8 | 9 | use SetBased\Helper\CodeStore\Importing; |
9 | 10 | use SetBased\Helper\CodeStore\PhpCodeStore; |
10 | 11 |
|
@@ -55,6 +56,7 @@ public function generateCode(string $fullyQualifiedName, array $allAgents): stri |
55 | 56 | $this->importing = new Importing($namespace); |
56 | 57 | $this->importing->addClass(ExceptionHandler::class); |
57 | 58 | $this->importing->addClass(PlaisioObject::class); |
| 59 | + $this->importing->addClass(Response::class); |
58 | 60 | $this->importClasses($allAgents); |
59 | 61 |
|
60 | 62 | $this->importing->prepare(); |
@@ -121,30 +123,38 @@ private function generateMethod(string $method, array $agents) |
121 | 123 | $this->store->append('/**'); |
122 | 124 | $this->store->append(' * @inheritdoc', false); |
123 | 125 | $this->store->append(' */', false); |
124 | | - $this->store->append(sprintf('public function %s(%s $exception): void', |
| 126 | + $this->store->append(sprintf('public function %s(%s $exception): Response', |
125 | 127 | $method, |
126 | 128 | $this->importing->simplyFullyQualifiedName('\\Throwable'))); |
127 | 129 | $this->store->append('{'); |
128 | | - $this->store->append('switch (true)'); |
129 | | - $this->store->append('{'); |
130 | 130 | $first = true; |
131 | 131 | foreach ($agents as $agent) |
132 | 132 | { |
133 | 133 | if (!$first) $this->store->append(''); |
| 134 | + $isThrowable = ($this->importing->simplyFullyQualifiedName($agent['type'])==='\Throwable'); |
| 135 | + |
| 136 | + if (!$isThrowable) |
| 137 | + { |
| 138 | + $this->store->append(sprintf("if (is_a(\$exception, %s::class))", |
| 139 | + $this->importing->simplyFullyQualifiedName($agent['type']))); |
| 140 | + $this->store->append('{'); |
| 141 | + $this->store->append(sprintf('/** @var %s $exception */', |
| 142 | + $this->importing->simplyFullyQualifiedName($agent['type']))); |
| 143 | + } |
134 | 144 |
|
135 | | - $this->store->append(sprintf("case is_a(\$exception, %s::class):", |
136 | | - $this->importing->simplyFullyQualifiedName($agent['type']))); |
137 | | - $this->store->append(sprintf('/** @var %s $exception */', |
138 | | - $this->importing->simplyFullyQualifiedName($agent['type']))); |
139 | 145 | $this->store->append(sprintf("\$handler = new %s(\$this);", |
140 | 146 | $this->importing->simplyFullyQualifiedName($agent['class']))); |
141 | | - $this->store->append(sprintf('$handler->%s($exception);', $agent['method'])); |
142 | | - $this->store->append('break;'); |
| 147 | + $this->store->append(''); |
| 148 | + $this->store->append(sprintf('return $handler->%s($exception);', $agent['method'])); |
| 149 | + |
| 150 | + if (!$isThrowable) |
| 151 | + { |
| 152 | + $this->store->append('}'); |
| 153 | + } |
143 | 154 |
|
144 | 155 | $first = false; |
145 | 156 | } |
146 | 157 | $this->store->append('}'); |
147 | | - $this->store->append('}'); |
148 | 158 | $this->store->append(''); |
149 | 159 | } |
150 | 160 |
|
|
0 commit comments