33
44namespace Plaisio \ExceptionHandler \Helper ;
55
6+ use Plaisio \ExceptionHandler \ExceptionHandler ;
7+ use Plaisio \PlaisioObject ;
68use SetBased \Helper \CodeStore \Importing ;
79use SetBased \Helper \CodeStore \PhpCodeStore ;
810
1214class ExceptionHandlerCodeGenerator
1315{
1416 //--------------------------------------------------------------------------------------------------------------------
15- /**
16- * The parent class of the generated exception handler.
17- *
18- * @var string
19- */
20- private static $ parentClass = '\\Plaisio \\ExceptionHandler \\ExceptionHandler ' ;
21-
2217 /**
2318 * The helper object for importing classes.
2419 *
@@ -58,13 +53,14 @@ public function generateCode(string $fullyQualifiedName, array $allAgents): stri
5853 $ namespace = ltrim (implode ('\\' , $ parts ), '\\' );
5954
6055 $ this ->importing = new Importing ($ namespace );
61- $ this ->importing ->addClass (self ::$ parentClass );
56+ $ this ->importing ->addClass (ExceptionHandler::class);
57+ $ this ->importing ->addClass (PlaisioObject::class);
6258 $ this ->importClasses ($ allAgents );
6359
6460 $ this ->importing ->prepare ();
6561
6662 $ this ->generateHeader ($ namespace );
67- $ this ->generateClass ($ class , $ allAgents );
63+ $ this ->generateClass ($ class , PlaisioObject::class, $ allAgents );
6864 $ this ->generateTrailer ();
6965
7066 return $ this ->store ->getCode ();
@@ -74,15 +70,18 @@ public function generateCode(string $fullyQualifiedName, array $allAgents): stri
7470 /**
7571 * Generates the PHP code of the class definition.
7672 *
77- * @param string $class The class name.
78- * @param array[] $allAgents The metadata of the exception agents.
73+ * @param string $handlerClass The class name of the exception handler.
74+ * @param string $kernelClass The class name of the kernel of PhpPlaisio.
75+ * @param array[] $allAgents The metadata of the exception agents.
7976 */
80- private function generateClass (string $ class , array $ allAgents ): void
77+ private function generateClass (string $ handlerClass , string $ kernelClass , array $ allAgents ): void
8178 {
8279 $ this ->store ->append ('/** ' );
8380 $ this ->store ->append (' * Concrete implementation of the exception handler. ' , false );
8481 $ this ->store ->append (' */ ' , false );
85- $ this ->store ->append (sprintf ('class %s implements ExceptionHandler ' , $ class ));
82+ $ this ->store ->append (sprintf ('class %s extends %s implements ExceptionHandler ' ,
83+ $ handlerClass ,
84+ $ this ->importing ->simplyFullyQualifiedName ($ kernelClass )));
8685 $ this ->store ->append ('{ ' );
8786 foreach ($ allAgents as $ name => $ agents )
8887 {
@@ -137,7 +136,7 @@ private function generateMethod(string $method, array $agents)
137136 $ this ->importing ->simplyFullyQualifiedName ($ agent ['type ' ])));
138137 $ this ->store ->append (sprintf ('/** @var %s $exception */ ' ,
139138 $ this ->importing ->simplyFullyQualifiedName ($ agent ['type ' ])));
140- $ this ->store ->append (sprintf ("\$handler = new %s(); " ,
139+ $ this ->store ->append (sprintf ("\$handler = new %s( \$ this ); " ,
141140 $ this ->importing ->simplyFullyQualifiedName ($ agent ['class ' ])));
142141 $ this ->store ->append (sprintf ('$handler->%s($exception); ' , $ agent ['method ' ]));
143142 $ this ->store ->append ('break; ' );
0 commit comments