{"id":13475743,"url":"https://github.com/goaop/framework","last_synced_at":"2025-05-14T01:03:38.395Z","repository":{"id":1398689,"uuid":"1416156","full_name":"goaop/framework","owner":"goaop","description":":gem: Go! AOP PHP - modern aspect-oriented framework for the new level of software development","archived":false,"fork":false,"pushed_at":"2024-05-19T14:59:31.000Z","size":2596,"stargazers_count":1658,"open_issues_count":11,"forks_count":163,"subscribers_count":86,"default_branch":"master","last_synced_at":"2024-10-29T11:17:40.049Z","etag":null,"topics":["aop","aspect-oriented-framework","framework","interceptor","php"],"latest_commit_sha":null,"homepage":"go.aopphp.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"vespolina/vespolina-sandbox","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goaop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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},"funding":{"github":["lisachenko"]}},"created_at":"2011-02-26T22:15:12.000Z","updated_at":"2024-10-27T02:26:53.000Z","dependencies_parsed_at":"2024-02-07T10:24:05.531Z","dependency_job_id":"664a843f-b400-4fd9-acdb-9ef057dda986","html_url":"https://github.com/goaop/framework","commit_stats":{"total_commits":1011,"total_committers":42,"mean_commits":"24.071428571428573","dds":"0.10781404549950546","last_synced_commit":"501d013c78e92057601c17ca0df1a59ab984f210"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goaop%2Fframework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goaop%2Fframework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goaop%2Fframework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goaop%2Fframework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goaop","download_url":"https://codeload.github.com/goaop/framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247962460,"owners_count":21024862,"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","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","aspect-oriented-framework","framework","interceptor","php"],"created_at":"2024-07-31T16:01:23.147Z","updated_at":"2025-04-09T02:11:05.871Z","avatar_url":"https://github.com/goaop.png","language":"PHP","readme":"Go! Aspect-Oriented Framework for PHP\n-----------------\n\nGo! AOP is a modern aspect-oriented framework in plain PHP with rich features for the new level of software development. The framework allows cross-cutting issues to be solved in the traditional object-oriented PHP code by providing a highly efficient and transparent hook system for your exisiting code.\n\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/goaop/framework/phpunit.yml?branch=master)\n[![GitHub release](https://img.shields.io/github/release/goaop/framework.svg)](https://github.com/goaop/framework/releases/latest)\n[![Total Downloads](https://img.shields.io/packagist/dt/goaop/framework.svg)](https://packagist.org/packages/goaop/framework)\n[![Daily Downloads](https://img.shields.io/packagist/dd/goaop/framework.svg)](https://packagist.org/packages/goaop/framework)\n[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/34549463-37d3-4368-94f5-812880d3ce4c.svg)](https://insight.sensiolabs.com/projects/34549463-37d3-4368-94f5-812880d3ce4c)\n[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%208.2-8892BF.svg)](https://php.net/)\n[![License](https://img.shields.io/packagist/l/goaop/framework.svg)](https://packagist.org/packages/goaop/framework)\n\nFeatures\n------------\n* Provides dynamic hook system for PHP without changes in the original source code.\n* Doesn't require any PECL-extentions (php-aop, runkit, uopz) and DI-containers to work.\n* Object-oriented design of aspects, joinpoints and pointcuts.\n* Intercepting an execution of any public or protected method in a classes.\n* Intercepting an execution of static methods and methods in final classes.\n* Intercepting an execution of methods in the traits.\n* Intercepting an access to the public/protected properties for objects.\n* Hooks for static class initialization (after class is loaded into PHP memory).\n* Hooks for object initialization (intercepting `new` keywords).\n* Intercepting an invocation of system PHP functions.\n* Ability to change the return value of any methods/functions via `Around` type of advice.\n* Rich pointcut grammar syntax for defining pointcuts in the source code.\n* Native debugging for AOP with XDebug. The code with weaved aspects is fully readable and native. You can put a breakpoint in the original class or in the aspect and it will work (for debug mode)!\n* Can be integrated with any existing PHP frameworks and libraries (with or without additional configuration).\n* Highly optimized for production use: support of opcode cachers, lazy loading of advices and aspects, joinpoints caching, no runtime checks of pointcuts, no runtime annotations parsing, no evals and `__call` methods, no slow proxies and `call_user_func_array()`. Fast bootstraping process (2-20ms) and advice invocation.\n\n\nWhat is AOP?\n------------\n\n[AOP (Aspect-Oriented Programming)](http://en.wikipedia.org/wiki/Aspect-oriented_programming) is an approach to cross-cutting concerns, where these concerns are designed and implemented \nin a \"modular\" way (that is, with appropriate encapsulation, lack of duplication, etc.), then integrated into all the relevant\nexecution points in a succinct and robust way, e.g. through declarative or programmatic means.\n\nIn AOP terms, the execution points are called join points. A set of those points is called a pointcut and the new\nbehavior that is executed before, after, or \"around\" a join point is called advice. You can read more about AOP in\n[Introduction](http://go.aopphp.com/docs/introduction/) section.\n\n\nInstallation\n------------\n\nGo! AOP framework can be installed with composer. Installation is quite easy:\n\n1. Download the framework using composer\n2. Create an application aspect kernel\n3. Configure the aspect kernel in the front controller\n4. Create an aspect\n5. Register the aspect in the aspect kernel\n\n### Step 0 (optional): Try demo examples in the framework\n\nAsk composer to create new project in empty directory:\n\n```bash\ncomposer create-project goaop/framework\n```\nAfter that just configure your web server to `demos/` folder and open it in your browser. Then you can look at some demo examples before going deeper into installing it in your project.\n\n### Step 1: Download the library using composer\n\nAsk composer to download the latest version of Go! AOP framework with its dependencies by running the command:\n\n``` bash\ncomposer require goaop/framework\n```\n\nComposer will install the framework to your project's `vendor/goaop/framework` directory.\n\n\n### Step 2: Create an application aspect kernel\n\nThe aim of this framework is to provide easy AOP integration for your application.\nYou have to first create the `AspectKernel` class\nfor your application. This class will manage all aspects of your\napplication in one place.\n\nThe framework provides base class to make it easier to create your own kernel.\nTo create your application kernel, extend the abstract class `Go\\Core\\AspectKernel`\n\n``` php\n\u003c?php\n// app/ApplicationAspectKernel.php\n\nuse Go\\Core\\AspectKernel;\nuse Go\\Core\\AspectContainer;\n\n/**\n * Application Aspect Kernel\n */\nclass ApplicationAspectKernel extends AspectKernel\n{\n\n    /**\n     * Configure an AspectContainer with advisors, aspects and pointcuts\n     *\n     * @param AspectContainer $container\n     *\n     * @return void\n     */\n    protected function configureAop(AspectContainer $container)\n    {\n    }\n}\n```\n\n### 3. Configure the aspect kernel in the front controller\n\nTo configure the aspect kernel, call `init()` method of kernel instance.\n\n``` php\n// front-controller, for Symfony2 application it's web/app_dev.php\n\ninclude __DIR__ . '/vendor/autoload.php'; // use composer\n\n// Initialize an application aspect container\n$applicationAspectKernel = ApplicationAspectKernel::getInstance();\n$applicationAspectKernel-\u003einit([\n        'debug'        =\u003e true, // use 'false' for production mode\n        'appDir'       =\u003e __DIR__ . '/..', // Application root directory\n        'cacheDir'     =\u003e __DIR__ . '/path/to/cache/for/aop', // Cache directory\n        // Include paths restricts the directories where aspects should be applied, or empty for all source files\n        'includePaths' =\u003e [\n            __DIR__ . '/../src/'\n        ]\n]);\n```\n\n### 4. Create an aspect\n\nAspect is the key element of AOP philosophy. Go! AOP framework just uses simple PHP classes for declaring aspects, which makes it possible to use all features of OOP for aspect classes.\nAs an example let's intercept all the methods and display their names:\n\n``` php\n// Aspect/MonitorAspect.php\n\nnamespace Aspect;\n\nuse Go\\Aop\\Aspect;\nuse Go\\Aop\\Intercept\\FieldAccess;\nuse Go\\Aop\\Intercept\\MethodInvocation;\nuse Go\\Lang\\Annotation\\After;\nuse Go\\Lang\\Annotation\\Before;\nuse Go\\Lang\\Annotation\\Around;\nuse Go\\Lang\\Annotation\\Pointcut;\n\n/**\n * Monitor aspect\n */\nclass MonitorAspect implements Aspect\n{\n\n    /**\n     * Method that will be called before real method\n     *\n     * @param MethodInvocation $invocation Invocation\n     * @Before(\"execution(public Example-\u003e*(*))\")\n     */\n    public function beforeMethodExecution(MethodInvocation $invocation)\n    {\n        echo 'Calling Before Interceptor for: ',\n            $invocation,\n            ' with arguments: ',\n            json_encode($invocation-\u003egetArguments()),\n            \"\u003cbr\u003e\\n\";\n    }\n}\n```\n\nEasy, isn't it? We declared here that we want to install a hook before the execution of\nall dynamic public methods in the class Example. This is done with the help of annotation\n`@Before(\"execution(public Example-\u003e*(*))\")`\nHooks can be of any types, you will see them later.\nBut we don't change any code in the class Example! I can feel your astonishment now.\n\n### 5. Register the aspect in the aspect kernel\n\nTo register the aspect just add an instance of it in the `configureAop()` method of the kernel:\n\n``` php\n// app/ApplicationAspectKernel.php\n\nuse Aspect\\MonitorAspect;\n\n//...\n\n    protected function configureAop(AspectContainer $container)\n    {\n        $container-\u003eregisterAspect(new MonitorAspect());\n    }\n\n//...\n```\n\n### 6. Optional configurations\n\n#### 6.1 Custom annotation cache\n\nBy default, Go! AOP uses `Doctrine\\Common\\Cache\\FilesystemCache` for caching\nannotations. However, if you need to use any other caching engine\nfor annotation, you may configure cache driver via `annotationCache` configuration\noption of your application aspect kernel. Only requirement is\nthat cache driver implements `Doctrine\\Common\\Cache\\Cache` interface.\n\nThis can be very useful when deploying to read-only filesystems. In that\ncase, you may use, per example, `Doctrine\\Common\\Cache\\ArrayCache` or some\nmemory-based cache driver.\n\n#### 6.2 Support for weaving Doctrine entities (experimental, alpha)\n\nWeaving Doctrine entities can not be supported out of the box due to the fact\nthat Go! AOP generates two sets of classes for each weaved entity, a concrete class and\nproxy with pointcuts. Doctrine will interpret both of those classes as concrete entities\nand assign for both of them same metadata, which would mess up the database and relations\n(see [https://github.com/goaop/framework/issues/327](https://github.com/goaop/framework/issues/327)).\n\nTherefore, a workaround is provided with this library which will sort out\nmapping issue in Doctrine. Workaround is in form of event subscriber,\n`Go\\Bridge\\Doctrine\\MetadataLoadInterceptor` which has to be registered\nwhen Doctrine is bootstraped in your project. For details how to do that,\nsee [http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html).\n\nEvent subscriber will modify metadata entity definition for generated Go! Aop proxies\nas mapped superclass. That would sort out issues on which you may stumble upon when\nweaving Doctrine entities.\n\n### 7. Contribution\n\nTo contribute changes see the [Contribute Readme](CONTRIBUTE.md)\n\nDocumentation\n-------------\n\nDocumentation about Go! library can be found at [official site][1].\nIf you like this project, you could support it via \u003ca href=\"https://flattr.com/submit/auto?fid=83r77w\u0026url=https%3A%2F%2Fgithub.com%2Fgoaop%2Fframework\" target=\"_blank\"\u003e\u003cimg src=\"https://button.flattr.com/flattr-badge-large.png\" alt=\"Flattr this\" title=\"Flattr this\" border=\"0\"\u003e\u003c/a\u003e\n\n[1]: http://go.aopphp.com\n","funding_links":["https://github.com/sponsors/lisachenko"],"categories":["PHP","基础框架"],"sub_categories":["构建/部署","Uncommon PHP Frameworks"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoaop%2Fframework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoaop%2Fframework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoaop%2Fframework/lists"}