From 07a43a67231547df0033ea80abd1e98c401ac844 Mon Sep 17 00:00:00 2001
From: filippo.bertilotti <filippobertilotti@gmail.com>
Date: Thu, 16 May 2024 10:14:05 +0200
Subject: [PATCH] implementazione di exception personalizzata per specifica dell'errore (parte 96)

---
 src/Framework/Container.php |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/Framework/Container.php b/src/Framework/Container.php
index 3bef332..cde3165 100644
--- a/src/Framework/Container.php
+++ b/src/Framework/Container.php
@@ -1,9 +1,10 @@
 <?php
-
+declare(strict_types= 1);
 namespace Framework;
 use ReflectionClass;
 use Closure;
 use ReflectionNamedType;
+use InvalidArgumentException;
 
 class Container {
 
@@ -29,18 +30,18 @@
             $type = $param->getType();
             
             if($type === null) {
-                exit("Constructor parameter '{$param->getName()}' in the $class_name class has no type declaration");
+                throw new InvalidArgumentException("Constructor parameter '{$param->getName()}' in the $class_name class has no type declaration");
             }
 
             if( ! ($type instanceof ReflectionNamedType)) {
-                exit("Constructor parameter '{$param->getName()}' in the $class_name class is an invalid type: $type
+                throw new InvalidArgumentException("Constructor parameter '{$param->getName()}' in the $class_name class is an invalid type: $type
                      - only single named type supported");
             }
 
             if($type->isBuiltin()) {
-                exit("Unable to resolve costructor parameter '{$param->getName()}' of type '$type' in the '$class_name' class");
+                throw new InvalidArgumentException("Unable to resolve costructor parameter '{$param->getName()}' of type '$type' in the '$class_name' class");
             }
-            $dependencies[] = $this->get($type);
+            $dependencies[] = $this->get((string) $type);
         }
         
         return new $class_name(...$dependencies);

--
Gitblit v1.8.0