{"id":37003279,"url":"https://github.com/zhanzhaopeng1/yaf-support","last_synced_at":"2026-01-14T00:32:42.795Z","repository":{"id":57052180,"uuid":"256654878","full_name":"zhanzhaopeng1/yaf-support","owner":"zhanzhaopeng1","description":"基于yaf框架和ioc思想实现的二次开发","archived":false,"fork":false,"pushed_at":"2020-05-04T10:00:48.000Z","size":93,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-12T12:32:38.455Z","etag":null,"topics":["laravel","php","yaf","yaf-ioc"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhanzhaopeng1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-18T02:39:26.000Z","updated_at":"2024-09-17T08:47:39.000Z","dependencies_parsed_at":"2022-08-24T03:40:52.452Z","dependency_job_id":null,"html_url":"https://github.com/zhanzhaopeng1/yaf-support","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/zhanzhaopeng1/yaf-support","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanzhaopeng1%2Fyaf-support","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanzhaopeng1%2Fyaf-support/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanzhaopeng1%2Fyaf-support/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanzhaopeng1%2Fyaf-support/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhanzhaopeng1","download_url":"https://codeload.github.com/zhanzhaopeng1/yaf-support/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanzhaopeng1%2Fyaf-support/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","php","yaf","yaf-ioc"],"created_at":"2026-01-14T00:32:41.751Z","updated_at":"2026-01-14T00:32:42.784Z","avatar_url":"https://github.com/zhanzhaopeng1.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yaf-support\n\n基于yaf框架和laravel框架的融合\n-------------\n\n前言\n---\n\nyaf (六脉神剑)\n六脉神剑，并非真剑，乃是以一阳指的指力化作剑气，有质无形，可称无形气剑。\n\nlaravel (降龙十八掌)\n降龙十八掌天下第一，本身掌法套路就刚猛无比，在加上使用者雄浑的内力，更是无可抵挡\n\nyaf 脉络清晰；框架简洁，易上手；可随心扩展自有功能；由于框架使用扩展形式，所以执行效率更高。\n\nlaravel  框架代码优美，整洁，周边丰富，可扩展性强；但框架可读性较差，每次运行加载文件较重，影响执行效率。\n\n故优势互补，以yaf为底，laravel IOC容器思想、中间件、服务注册等贯穿整个yaf生命周期中，使yaf框架\n可以更易扩展，代码也更清晰。\n\n说明\n----\n    本版本为V1.0版，还未经过实际项目校验，如有使用中出现问题，可以发送邮件到zhaopeng156@126.com中\n    共同探讨，如果有更好的想法或者优化也欢迎发送邮件互相切磋讨论，多多益善。\n\n设计思路\n------\n\n* 容器(Container)\n\u003e\u003e\u003e基于pimple/pimple的容器，贯穿于yaf的全生命周期流程中，index.php入口文件会实例化容器并注册到Yaf_Registry实例中,\n以实现全局使用。\n``````PHP\n        $app = new Application([], realpath(dirname(__FILE__)));\n        Yaf_Registry::set('app', $app);\n``````\n* 服务注册(ServiceProvider)\n\u003e\u003e\u003e同样基于pimple/pimple容器，当需要新的中间件，或者新增服务模块时，可以使用服务注册将服务或者中间件注册。\n``````PHP\n        $app = new Application([], realpath(dirname(__FILE__)));\n        Yaf_Registry::set('app', $app);\n\n        app()['request'] = function ($c) {\n            return new Request('test/test', 'base_uri/test/test');\n        };\n\n        app()[Authenticate::class] = function ($c) {\n            return new Authenticate();\n        };\n``````\n\n* 中间件(Middleware)\n\u003e\u003e\u003e在整个请求流程的生命周期中，会有一些鉴权、加解密、路由校验、session等中间件在请求到达核心逻辑之前做一些过滤请求\n的处理，当有新增或者修改、删除一些过滤逻辑的时候可以在相应的配置文件中修改，做到随意扩展。\n``````PHP\n        $app = new Application([], realpath(dirname(__FILE__)));\n        \\Yaf_Registry::set('app', $app);\n        \n         app()['request'] = function ($c) {\n                $request = new Request('test/test', 'base_uri/test/test');\n                $request-\u003esetShouldMethod('any');\n                $request-\u003esetMiddleware(['auth']);\n                $request-\u003esetParam('api_token','12345678');\n        \n                return $request;\n         };\n        \n          app()[Kernel::class] = function ($c) {\n                return new Kernel($c);\n          };\n        \n          arrayConfig()-\u003eset('auth', require __DIR__ . '/../src/Auth/config/auth.php');\n        \n          $res = app(Kernel::class)-\u003ehandle(app('request'));\n          var_dump(Auth()-\u003eid());\n          var_dump(Auth()-\u003euser());\n``````\n\n*核心(Kernel)\n\u003e\u003e\u003e当各个组件、Request、Reponse等注册到服务容器中以后，kernel使用管道顺序调用Middleware 作相应的请求处理。\n``````PHP\n        if ($middlewareList = $request-\u003egetMiddleware()) {\n              collect($middlewareList)-\u003emap(function ($middleware) {\n                   $this-\u003emiddleware[] = $middleware;\n              });\n        }\n        \n        return (new Pipeline($this-\u003eapp))\n               -\u003esend($request)\n               -\u003ethrough($this-\u003emiddleware)\n               -\u003ethen(function ($request) {\n                    return $request;\n        });\n``````\n\n*输入/输出(Request/Response)\n\u003e\u003e\u003erequest和response继承yaf自带的request/response 新增一些必要的数据。一并注册到容器中。\n``````PHP\n         $app = new Application([], realpath(dirname(__FILE__)));\n         Yaf_Registry::set('app', $app);\n        \n         app()['request'] = function ($c) {\n              return new Request('cli', 'cli');\n         };\n``````\n\n*校验器(validation)\n\u003e\u003e\u003e参考laravel的校验器来做参数的校验，但校验类型与laravel相比较少，具体读源码\n``````PHP\n         validator()-\u003evalidate([\n              'age'  =\u003e 'required|int|between:1,100',\n              'name' =\u003e 'required|string'\n         ]);\n         \n         $age  = request()-\u003egetParam('age');\n         $name = request()-\u003egetParam('name', 'test');\n         var_dump($age);\n         var_dump($name);\n``````\n\n*日志(monolog)\n\u003e\u003e\u003e完全复用monolog来做为此版本的日志记录工具，以天为单位，每小时记录所有的请求日志，具体代码需要根据实际\n项目去配置，本处不做过多讲解。\n``````PHP\n         date_default_timezone_set(\"PRC\");\n         \n         $app = new Application([], realpath(dirname(__FILE__)));\n         Yaf_Registry::set('app', $app);\n         \n         app()['request'] = function ($c) {\n               return new Request('cli', 'cli');\n         };\n         \n         (new ServiceProvider())-\u003eboot();\n         \n         Log::debug('debug log');\n         Log::info('info log');\n         Log::notice('notice log');\n         Log::error('error log');\n         Log::warning('warring log');\n``````\n\n未完待续\n----","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanzhaopeng1%2Fyaf-support","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhanzhaopeng1%2Fyaf-support","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanzhaopeng1%2Fyaf-support/lists"}