swoole-framwork/core/annotationhandlers/AnnotationHandler.php
2024-05-21 14:33:56 +08:00

24 lines
780 B
PHP

<?php
namespace Core\annotationhandlers;
use Core\annotations\Bean;
use Core\annotations\Value;
return [
Bean::class => function ($instance, $container, $self) {
$vars = get_object_vars($self);
if (isset($vars['name']) && !empty($vars['name'])){
$beanName = $vars['name'];
}else{
$arrs = explode('\\',get_class($instance));
$beanName = end($arrs);
}
$container->set($beanName,$instance);
},
Value::class => function (\ReflectionProperty $property, $instance, $self) {
$env = parse_ini_file(ROOT_PATH.'/.env');
if (!isset($env[$self->name]) || empty($self->name)) return $instance;
$property->setValue($instance,$env[$self->name]);
return $instance;
}
];