From 58f2497c943617f6da634c9718e9685a02ec6447 Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Mon, 20 May 2024 00:48:06 -0300 Subject: [PATCH] Added config DI argument type --- system/config/autoload.php | 4 ++-- system/engine/registry.php | 35 ++++++++++------------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/system/config/autoload.php b/system/config/autoload.php index 735a053..2b2f4cf 100644 --- a/system/config/autoload.php +++ b/system/config/autoload.php @@ -9,7 +9,7 @@ namespace Phacil\Framework; /** @package Phacil\Framework */ -final class Config { +class Config { /** * @var array @@ -21,7 +21,7 @@ final class Config { * @return null|array|string */ public function get($key) { - return (isset($this->data[$key]) ? $this->data[$key] : null); + return ($this->has($key) ? $this->data[$key] : null); } /** diff --git a/system/engine/registry.php b/system/engine/registry.php index 504c0af..204b4f0 100644 --- a/system/engine/registry.php +++ b/system/engine/registry.php @@ -63,13 +63,6 @@ final class Registry { */ static private $preferences = []; - /** - * DI Preference class - * - * @var array - */ - static private $diOptions = []; - static private $diCheckedRoutes = []; /** @@ -413,32 +406,17 @@ final class Registry { $type = key(self::$preferences[$class]['arguments'][$argument]); // Verifica se $type é um tipo válido - $validTypes = ['string', 'int', 'integer', 'bool', 'boolean', 'float', 'double', 'array', 'object', 'objects', 'object[]', 'resource']; - + $validTypes = ['string', 'int', 'integer', 'bool', 'boolean', 'float', 'double', 'array', 'object', 'objects', 'object[]', 'config']; + if (in_array($type, $validTypes, true)) { return self::returnArgumentType($type, reset(self::$preferences[$class]['arguments'][$argument])); } - - /* foreach(self::$preferences[$class]['arguments'][$argument] as $type => $value) { - return self::returnArgumentType($type, $value); - } */ } return self::$preferences[$class]['arguments'][$argument]; } } - /* if(isset(self::$diOptions['type'])){ - if(isset(self::$diOptions['type'][$class])){ - if(isset(self::$diOptions['type'][$class][$argument])){ - if(!is_array(self::$diOptions['type'][$class][$argument])) - return self::$diOptions['type'][$class][$argument]; - - if(isset(self::$diOptions['type'][$class][$argument]['type'])){ - return self::returnArgumentType(self::$diOptions['type'][$class][$argument]['type'], self::$diOptions['type'][$class][$argument]['value']); - } - } - } - } */ + return null; } @@ -470,9 +448,16 @@ final class Registry { return boolval($argumentValue); break; + case 'integer': case 'int': return intval($argumentValue); break; + + case 'config': + /** @var \Phacil\Framework\Config */ + $config = self::getInstance(\Phacil\Framework\Config::class); + return $config->get($argumentValue); + break; default: return $argumentValue;