{"id":33982161,"url":"https://github.com/next-laboratory/aop","last_synced_at":"2025-12-13T03:59:53.808Z","repository":{"id":44422716,"uuid":"486454801","full_name":"next-laboratory/aop","owner":"next-laboratory","description":"一款用于常驻内存型PHP应用的简单的Aop组件。","archived":false,"fork":false,"pushed_at":"2025-11-06T10:30:16.000Z","size":124,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-06T19:24:48.613Z","etag":null,"topics":["aop","di","pcntl","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/next-laboratory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-28T05:13:37.000Z","updated_at":"2025-11-06T10:28:14.000Z","dependencies_parsed_at":"2023-01-22T07:02:10.358Z","dependency_job_id":"90cc79c1-abcf-4f08-b509-099c916460f2","html_url":"https://github.com/next-laboratory/aop","commit_stats":null,"previous_names":["next-laboratory/aop","marxphp/aop"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/next-laboratory/aop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/next-laboratory%2Faop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/next-laboratory%2Faop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/next-laboratory%2Faop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/next-laboratory%2Faop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/next-laboratory","download_url":"https://codeload.github.com/next-laboratory/aop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/next-laboratory%2Faop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27699685,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["aop","di","pcntl","php"],"created_at":"2025-12-13T03:59:52.650Z","updated_at":"2025-12-13T03:59:53.801Z","avatar_url":"https://github.com/next-laboratory.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ！！！ 不能生产使用，仅作为研究用途\n\n一款简单Aop实现。支持常驻内存型PHP应用。可以方便接入nextphp, Swoole，WebMan等框架。\n\n# 环境要求\n\n```\nphp 8.2\n开启passthru函数\n```\n\n# 安装\n\n```shell\ncomposer require next/aop\n```\n\n# 使用，以下以webman为例\n\n## 修改start.php文件\n\n```php\nAop::init(\n    [__DIR__ . '/../app'],\n    [\n        \\Next\\Aop\\Collector\\PropertyAttributeCollector::class,\n        \\Next\\Aop\\Collector\\AspectCollector::class,\n    ],\n    __DIR__ . '/../runtime/aop',\n);\n```\n\n* paths 注解扫描路径\n* collectors 注解收集器\n    - \\Next\\Aop\\Collector\\AspectCollector::class 切面收集器，取消后不能使用切面\n    - \\Next\\Aop\\Collector\\PropertyAttributeCollector::class 属性注解收集器，取消后不支持属性自动注入\n* runtimeDir 运行时，生成的代理类和代理类地图会被缓存到这里\n\n## 编写切面类，实现AspectInterface接口\n\n```php\n\u003c?php\n\nnamespace App\\aspects;\n\nuse Next\\Aop\\ProceedingJoinPoint;\nuse Next\\Aop\\Contract\\AspectInterface;\n\n#[\\Attribute(\\Attribute::TARGET_METHOD)]\nclass Round implements AspectInterface\n{\n    public function process(ProceedingJoinPoint $joinPoint): mixed\n    {\n        echo 'before';\n        $result = $joinPoint-\u003eproceed(); // 直接调用被代理的方法\n//        $result = $joinPoint-\u003eprocess(); // 继续执行其他切面逻辑\n        echo 'after';\n        return $result;\n    }\n}\n```\n\n修改方法添加切面注解\n\n```php\n\u003c?php\n\nnamespace app\\controller;\n\nuse App\\Aop\\Attribute\\Inject;use App\\aspects\\Round;use support\\Request;\n\nclass Index\n{\n    #[Inject]\n    protected Request $request;\n\n    #[Round]\n    public function index()\n    {\n        echo '--controller--';\n        return response('hello webman');\n    }\n}\n```\n\n\u003e\n注意上面添加了两个注解，属性和方法注解的作用分别为注入属性和切入方法，可以直接在控制器中打印属性$request发现已经被注入了，切面注解可以有多个，会按照顺序执行。具体实现可以参考这两个类，注意这里的Inject注解并不是从webman容器中获取实例，所以使用的话需要重新定义Inject以保证单例\n\n你也可以使用`AspectConfig`注解类配置要切入的类，例如上面的切面类\n\n```php\n\u003c?php\n\nnamespace App\\aspects;\n\nuse Next\\Aop\\Attribute\\AspectConfig;\nuse Next\\Aop\\ProceedingJoinPoint;\nuse Next\\Aop\\Contract\\AspectInterface;\n\n#[\\Attribute(\\Attribute::TARGET_METHOD)]\n#[AspectConfig('BaconQrCode\\Writer', 'writeFile')]\nclass Round implements AspectInterface\n{\n    public function process(ProceedingJoinPoint $joinPoint): mixed\n    {\n        echo 'before';\n        $result = $joinPoint-\u003eprocess();\n        echo 'after';\n        return $result;\n    }\n}\n\n```\n\n那么`BaconQrCode\\Writer`类的`writeFile`方法将会被切入，该注解可以传递第三个参数数组，作为该切面构造函数的参数\n\n## 启动\n\n```shell\nphp start.php start\n```\n\n打开浏览器打开~~对应页面~~\n\n## 控制台输出内容为\n\n```\nbefore--controller--after\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnext-laboratory%2Faop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnext-laboratory%2Faop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnext-laboratory%2Faop/lists"}