publicstaticfunctioninit(){$loader=requiredirname(__DIR__)."/vendor/autoload.php";
AnnotationRegistry::registerLoader([$loader,'loadClass']);
self::loadAnnotationRoute();//收集路由注解
self::loadAnnotationBean();//收集容器注解}//Registers an autoloading callable for annotations, much like spl_autoload_register()publicstaticfunctionregisterLoader(callable $callable): void
{// Reset our static cache now that we have a new loader to work with
self::$failedToAutoload=[];
self::$loaders[]=$callable;}publicstaticfunctionloadAnnotationRoute(){//自动加载注解类(规则)到组件当中$reader=newAnnotations\AnnotationReader();//手动实例化类 glob() 遍历文件$obj=new\App\Http\Controller\HomeController();$re=new\ReflectionClass($obj);//类注解$class_annos=$reader->getClassAnnotations($re);foreach($class_annosas$class_anno){$routePrefix=$class_anno->getPrefix();//通过反射得到所有的方法$refMethods=$re->getMethods();foreach($refMethodsas$method){// var_dump($method->name);$methodAnnos=$reader->getMethodAnnotations($method);foreach($methodAnnosas$methodAnno){$routePath=$methodAnno->getRoute();//在某个解析类当中处理逻辑(newRequestMappingParser())->parse($routePrefix,$routePath,$re->newInstance(),$method->name);}}}publicstaticfunctionloadAnnotationBean(){//自动加载注解类(规则)到组件当中$reader=newAnnotations\AnnotationReader();//手动实例化类 glob() 遍历文件$obj=newRoute();$re=new\ReflectionClass($obj);// var_dump($re);//类注解$class_annos=$reader->getClassAnnotations($re);foreach($class_annosas$class_anno){$beanName=$class_anno->getName();//parse方法作为作业
self::$beans[$beanName]=$re->newInstance();}}