{"id":43845501,"url":"https://github.com/xtompie/aop","last_synced_at":"2026-02-06T05:37:05.448Z","repository":{"id":65701988,"uuid":"597562747","full_name":"xtompie/aop","owner":"xtompie","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-05T20:48:36.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-03T09:10:38.967Z","etag":null,"topics":[],"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/xtompie.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":"2023-02-04T23:02:16.000Z","updated_at":"2023-02-05T10:41:58.000Z","dependencies_parsed_at":"2023-02-18T23:01:51.978Z","dependency_job_id":null,"html_url":"https://github.com/xtompie/aop","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/xtompie/aop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Faop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Faop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Faop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Faop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xtompie","download_url":"https://codeload.github.com/xtompie/aop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Faop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29152427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T02:39:25.012Z","status":"ssl_error","status_checked_at":"2026-02-06T02:37:22.784Z","response_time":59,"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":[],"created_at":"2026-02-06T05:37:03.489Z","updated_at":"2026-02-06T05:37:05.436Z","avatar_url":"https://github.com/xtompie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Aop - Aspect-Orientend Programing for PHP\n\nThis library require changes in the original source code.\n\nIn simplified and generalized term AOP is Publish/Subscribe system with Middlewares.\n\n## Requiments\n\nPHP \u003e= 8.0\n\n## Installation\n\nUsing [composer](https://getcomposer.org/)\n\n```\ncomposer require xtompie/aop\n```\n\n## Docs\n\n### 1. Creating Aspect\n\nAspect is a class implementing `Aspect` interface.\n\n```php\n\u003c?php\n\nnamespace Xtompie\\Aop;\n\ninterface Aspect\n{\n    public function order(): float;\n    public function joinpoint(string $joinpoint): bool;\n    public function advice(Invocation $invocation): mixed;\n}\n```\n\nLibrary provides abstract class `GenericAspect`.\n\n```php\n\u003c?php\n\nuse Xtompie\\Aop\\GenericAspect;\n\nclass DebugAspect implements GenericAspect\n{\n    protected function pointcuts(): array\n    {\n        return [\n            'FoobarService::*',\n        ];\n    }\n\n    public function advice(Invocation $invocation): mixed\n    {\n        $result = $invocation();\n        var_dump([\n            'AOP',\n            'joinpoint' =\u003e $invocation-\u003ejoinpoint(),\n            'args' =\u003e $invocation-\u003eargs(),\n            'result' =\u003e $result,\n        ]);\n        return $result;\n    }\n}\n```\n\nPointcut is a pattern that can match Joinpoint.\nPointcut can have a `*` character that describes any character in any number of occurrences.\nIf Pointcut dont have `*` it is equal to Joinpoint.\n\nThere is only one type of Advice - around. Before and after can be achive manualy or using `GenericAspect`.\n\n### 2. Create AOP system\n\n```php\n\u003c?php\n\nuse Xtompie\\Aop\\Aop;\n\n$aop = new Aop([\n    new DebugAspect(),\n]);\n\nfunction aop(string $joinpoint, array $args, callable $main): mixed\n{\n    return $GLOBALS['aop']-\u003e__invoke($joinpoint, $args, $main);\n}\n```\n\n### 3. Create joinpoint in service\n\n```php\n\u003c?php\n\nclass FoobarService\n{\n    public function baz(int $a): int\n    {\n        return aop(__METHOD__, func_get_args(), function(int $a) { // \u003c-- added line\n            return $a + 1;\n        }); // \u003c-- added line\n    }\n}\n```\n\n### 4. Changing invocation arguments\n\n```php\n\u003c?php\n\nuse Xtompie\\Aop\\GenericAspect;\n\nclass AddFiveAspect implements GenericAspect\n{\n    protected function pointcuts(): array\n    {\n        return [\n            'FoobarService::__invoke',\n        ];\n    }\n\n    public function advice(Invocation $invocation): mixed\n    {\n        $invocation = $invocation-\u003ewithArgs([$invocation-\u003eargs()[0] + 5]);\n        return $invocation();\n    }\n}\n```\n\n### 5. Changing aspect orders\n\nThe higher the order, the closer it is to the main invocation.\n\n```php\n\u003c?php\n\nuse Xtompie\\Aop\\GenericAspect;\n\nclass AddFiveAspect implements GenericAspect\n{\n    public function order(): float\n    {\n        return 10;\n    }\n\n    // ...\n}\n```\n\n### 6. Replace orginal invocation\n\nDont call invocation chain `$invocation()`.\n\n```php\n\u003c?php\n\nuse Xtompie\\Aop\\GenericAspect;\n\nclass MinusTeenAspect implements GenericAspect\n{\n    public function order(): float\n    {\n        return 999;\n    }\n\n    protected function pointcuts(): array\n    {\n        return [\n            'FoobarService::__invoke',\n        ];\n    }\n\n    public function advice(Invocation $invocation): mixed\n    {\n        return $invocation-\u003eargs()[0] - 10;\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtompie%2Faop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtompie%2Faop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtompie%2Faop/lists"}