swoole-framwork/core/annotationhandlers/AnnotationHandler.php

24 lines
780 B
PHP
Raw Normal View History

2024-05-20 11:51:07 +08:00
<?php
namespace Core\annotationhandlers;
use Core\annotations\Bean;
use Core\annotations\Value;
return [
2024-05-21 14:33:56 +08:00
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);
2024-05-20 11:51:07 +08:00
},
2024-05-21 14:33:56 +08:00
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;
2024-05-20 11:51:07 +08:00
}
];