2024-05-20 11:51:07 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Core\annotationhandlers;
|
|
|
|
|
|
|
|
use Core\annotations\RequestMapping;
|
|
|
|
use Core\BeanFactory;
|
2024-05-21 14:33:56 +08:00
|
|
|
use Core\init\DecoratorCollector;
|
2024-05-20 11:51:07 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
//$methodAnnoSelf 注解本身
|
2024-05-21 14:33:56 +08:00
|
|
|
RequestMapping::class => function (\ReflectionMethod $method, $instance, $self) {
|
|
|
|
$path = $self->value;//uri;
|
|
|
|
$requestMethod = $self->method ?: ['GET'];
|
2024-05-20 11:51:07 +08:00
|
|
|
$RouterCollector = BeanFactory::getBean("RouterCollector");
|
|
|
|
//var_dump($RouterCollector);
|
|
|
|
$RouterCollector->addRouter($requestMethod, $path, function ($params,$extParams) use ($method, $instance) {
|
|
|
|
$inputParams=[];
|
|
|
|
$refParams=$method->getParameters();
|
|
|
|
foreach ($refParams as $refParam){
|
|
|
|
if(isset($params[$refParam->getName()])){
|
|
|
|
$inputParams[] = $params[$refParam->getName()];
|
|
|
|
}else{
|
|
|
|
foreach($extParams as $extParam){
|
2024-05-21 14:33:56 +08:00
|
|
|
$type = $refParam->getType();
|
|
|
|
if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) {
|
|
|
|
$className = $type->getName();
|
|
|
|
if(class_exists($className)){
|
|
|
|
$reflectionClass = new \ReflectionClass($className);
|
|
|
|
if($reflectionClass->isInstance($extParam)){
|
|
|
|
$inputParams[] = $extParam;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
2024-05-20 11:51:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$inputParams[] = false;
|
|
|
|
}
|
2024-05-21 14:33:56 +08:00
|
|
|
end:
|
2024-05-20 11:51:07 +08:00
|
|
|
}
|
2024-05-21 14:33:56 +08:00
|
|
|
return BeanFactory::getBean(DecoratorCollector::class)->exec($method,$instance,$inputParams);
|
|
|
|
//return $method->invokeArgs($instance,$inputParams);
|
2024-05-20 11:51:07 +08:00
|
|
|
//return $method->invoke($instance);//执行反射方法
|
|
|
|
|
|
|
|
});
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
];
|