framework

framework

Go! AOP框架为PHP提供面向切面编程能力

Go! AOP是一个PHP面向切面编程框架,通过高效的钩子系统在现有PHP代码中实现横切关注点。支持方法拦截、属性访问拦截等功能,无需修改源代码。针对生产环境优化,可集成到现有PHP项目中。该框架为开发者提供了实现AOP的灵活方案。

Go! AOP面向切面编程PHP框架横切关注点钩子系统Github开源项目

Go! Aspect-Oriented Framework for PHP

Go! 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.

GitHub Workflow Status GitHub release Total Downloads Daily Downloads SensioLabs Insight Minimum PHP Version License

Features

  • Provides dynamic hook system for PHP without changes in the original source code.
  • Doesn't require any PECL-extentions (php-aop, runkit, uopz) and DI-containers to work.
  • Object-oriented design of aspects, joinpoints and pointcuts.
  • Intercepting an execution of any public or protected method in a classes.
  • Intercepting an execution of static methods and methods in final classes.
  • Intercepting an execution of methods in the traits.
  • Intercepting an access to the public/protected properties for objects.
  • Hooks for static class initialization (after class is loaded into PHP memory).
  • Hooks for object initialization (intercepting new keywords).
  • Intercepting an invocation of system PHP functions.
  • Ability to change the return value of any methods/functions via Around type of advice.
  • Rich pointcut grammar syntax for defining pointcuts in the source code.
  • 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)!
  • Can be integrated with any existing PHP frameworks and libraries (with or without additional configuration).
  • 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.

What is AOP?

AOP (Aspect-Oriented Programming) is an approach to cross-cutting concerns, where these concerns are designed and implemented in a "modular" way (that is, with appropriate encapsulation, lack of duplication, etc.), then integrated into all the relevant execution points in a succinct and robust way, e.g. through declarative or programmatic means.

In AOP terms, the execution points are called join points. A set of those points is called a pointcut and the new behavior that is executed before, after, or "around" a join point is called advice. You can read more about AOP in Introduction section.

Installation

Go! AOP framework can be installed with composer. Installation is quite easy:

  1. Download the framework using composer
  2. Create an application aspect kernel
  3. Configure the aspect kernel in the front controller
  4. Create an aspect
  5. Register the aspect in the aspect kernel

Step 0 (optional): Try demo examples in the framework

Ask composer to create new project in empty directory:

composer create-project goaop/framework

After 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.

Step 1: Download the library using composer

Ask composer to download the latest version of Go! AOP framework with its dependencies by running the command:

composer require goaop/framework

Composer will install the framework to your project's vendor/goaop/framework directory.

Step 2: Create an application aspect kernel

The aim of this framework is to provide easy AOP integration for your application. You have to first create the AspectKernel class for your application. This class will manage all aspects of your application in one place.

The framework provides base class to make it easier to create your own kernel. To create your application kernel, extend the abstract class Go\Core\AspectKernel

<?php // app/ApplicationAspectKernel.php use Go\Core\AspectKernel; use Go\Core\AspectContainer; /** * Application Aspect Kernel */ class ApplicationAspectKernel extends AspectKernel { /** * Configure an AspectContainer with advisors, aspects and pointcuts * * @param AspectContainer $container * * @return void */ protected function configureAop(AspectContainer $container) { } }

3. Configure the aspect kernel in the front controller

To configure the aspect kernel, call init() method of kernel instance.

// front-controller, for Symfony2 application it's web/app_dev.php include __DIR__ . '/vendor/autoload.php'; // use composer // Initialize an application aspect container $applicationAspectKernel = ApplicationAspectKernel::getInstance(); $applicationAspectKernel->init([ 'debug' => true, // use 'false' for production mode 'appDir' => __DIR__ . '/..', // Application root directory 'cacheDir' => __DIR__ . '/path/to/cache/for/aop', // Cache directory // Include paths restricts the directories where aspects should be applied, or empty for all source files 'includePaths' => [ __DIR__ . '/../src/' ] ]);

4. Create an aspect

Aspect 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. As an example let's intercept all the methods and display their names:

// Aspect/MonitorAspect.php namespace Aspect; use Go\Aop\Aspect; use Go\Aop\Intercept\FieldAccess; use Go\Aop\Intercept\MethodInvocation; use Go\Lang\Annotation\After; use Go\Lang\Annotation\Before; use Go\Lang\Annotation\Around; use Go\Lang\Annotation\Pointcut; /** * Monitor aspect */ class MonitorAspect implements Aspect { /** * Method that will be called before real method * * @param MethodInvocation $invocation Invocation * @Before("execution(public Example->*(*))") */ public function beforeMethodExecution(MethodInvocation $invocation) { echo 'Calling Before Interceptor for: ', $invocation, ' with arguments: ', json_encode($invocation->getArguments()), "<br>\n"; } }

Easy, isn't it? We declared here that we want to install a hook before the execution of all dynamic public methods in the class Example. This is done with the help of annotation @Before("execution(public Example->*(*))") Hooks can be of any types, you will see them later. But we don't change any code in the class Example! I can feel your astonishment now.

5. Register the aspect in the aspect kernel

To register the aspect just add an instance of it in the configureAop() method of the kernel:

// app/ApplicationAspectKernel.php use Aspect\MonitorAspect; //... protected function configureAop(AspectContainer $container) { $container->registerAspect(new MonitorAspect()); } //...

6. Optional configurations

6.1 Custom annotation cache

By default, Go! AOP uses Doctrine\Common\Cache\FilesystemCache for caching annotations. However, if you need to use any other caching engine for annotation, you may configure cache driver via annotationCache configuration option of your application aspect kernel. Only requirement is that cache driver implements Doctrine\Common\Cache\Cache interface.

This can be very useful when deploying to read-only filesystems. In that case, you may use, per example, Doctrine\Common\Cache\ArrayCache or some memory-based cache driver.

6.2 Support for weaving Doctrine entities (experimental, alpha)

Weaving Doctrine entities can not be supported out of the box due to the fact that Go! AOP generates two sets of classes for each weaved entity, a concrete class and proxy with pointcuts. Doctrine will interpret both of those classes as concrete entities and assign for both of them same metadata, which would mess up the database and relations (see https://github.com/goaop/framework/issues/327).

Therefore, a workaround is provided with this library which will sort out mapping issue in Doctrine. Workaround is in form of event subscriber, Go\Bridge\Doctrine\MetadataLoadInterceptor which has to be registered when Doctrine is bootstraped in your project. For details how to do that, see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html.

Event subscriber will modify metadata entity definition for generated Go! Aop proxies as mapped superclass. That would sort out issues on which you may stumble upon when weaving Doctrine entities.

7. Contribution

To contribute changes see the Contribute Readme

Documentation

Documentation about Go! library can be found at official site. If you like this project, you could support it via <a href="https://flattr.com/submit/auto?fid=83r77w&url=https%3A%2F%2Fgithub.com%2Fgoaop%2Fframework" target="_blank"><img src="https://button.flattr.com/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0"></a>

编辑推荐精选

Qwen2.5-VL

Qwen2.5-VL

一款强大的视觉语言模型,支持图像和视频输入

Qwen2.5-VL 是一款强大的视觉语言模型,支持图像和视频输入,可用于多种场景,如商品特点总结、图像文字识别等。项目提供了 OpenAI API 服务、Web UI 示例等部署方式,还包含了视觉处理工具,有助于开发者快速集成和使用,提升工作效率。

HunyuanVideo

HunyuanVideo

HunyuanVideo 是一个可基于文本生成高质量图像和视频的项目。

HunyuanVideo 是一个专注于文本到图像及视频生成的项目。它具备强大的视频生成能力,支持多种分辨率和视频长度选择,能根据用户输入的文本生成逼真的图像和视频。使用先进的技术架构和算法,可灵活调整生成参数,满足不同场景的需求,是文本生成图像视频领域的优质工具。

WebUI for Browser Use

WebUI for Browser Use

一个基于 Gradio 构建的 WebUI,支持与浏览器智能体进行便捷交互。

WebUI for Browser Use 是一个强大的项目,它集成了多种大型语言模型,支持自定义浏览器使用,具备持久化浏览器会话等功能。用户可以通过简洁友好的界面轻松控制浏览器智能体完成各类任务,无论是数据提取、网页导航还是表单填写等操作都能高效实现,有利于提高工作效率和获取信息的便捷性。该项目适合开发者、研究人员以及需要自动化浏览器操作的人群使用,在 SEO 优化方面,其关键词涵盖浏览器使用、WebUI、大型语言模型集成等,有助于提高网页在搜索引擎中的曝光度。

xiaozhi-esp32

xiaozhi-esp32

基于 ESP32 的小智 AI 开发项目,支持多种网络连接与协议,实现语音交互等功能。

xiaozhi-esp32 是一个极具创新性的基于 ESP32 的开发项目,专注于人工智能语音交互领域。项目涵盖了丰富的功能,如网络连接、OTA 升级、设备激活等,同时支持多种语言。无论是开发爱好者还是专业开发者,都能借助该项目快速搭建起高效的 AI 语音交互系统,为智能设备开发提供强大助力。

olmocr

olmocr

一个用于 OCR 的项目,支持多种模型和服务器进行 PDF 到 Markdown 的转换,并提供测试和报告功能。

olmocr 是一个专注于光学字符识别(OCR)的 Python 项目,由 Allen Institute for Artificial Intelligence 开发。它支持多种模型和服务器,如 vllm、sglang、OpenAI 等,可将 PDF 文件的页面转换为 Markdown 格式。项目还提供了测试框架和 HTML 报告生成功能,方便用户对 OCR 结果进行评估和分析。适用于科研、文档处理等领域,有助于提高工作效率和准确性。

飞书多维表格

飞书多维表格

飞书多维表格 ×DeepSeek R1 满血版

飞书多维表格联合 DeepSeek R1 模型,提供 AI 自动化解决方案,支持批量写作、数据分析、跨模态处理等功能,适用于电商、短视频、影视创作等场景,提升企业生产力与创作效率。关键词:飞书多维表格、DeepSeek R1、AI 自动化、批量处理、企业协同工具。

CSM

CSM

高质量语音生成模型

CSM 是一个开源的语音生成项目,它提供了一个基于 Llama-3.2-1B 和 CSM-1B 的语音生成模型。该项目支持多语言,可生成多种声音,适用于研究和教育场景。通过使用 CSM,用户可以方便地进行语音合成,同时项目还提供了水印功能,确保生成音频的可追溯性和透明度。

agents-course

agents-course

Hugging Face 的 AI 智能体课程,涵盖多种智能体框架及相关知识

本项目是 Hugging Face 推出的 AI 智能体课程,深入介绍了 AI 智能体的相关概念,如大语言模型、工具使用等。课程包含多个单元,详细讲解了不同的智能体框架,如 smolagents 和 LlamaIndex,提供了丰富的学习资源和实践案例。适合对 AI 智能体感兴趣的开发者和学习者,有助于提升他们在该领域的知识和技能。

RagaAI-Catalyst

RagaAI-Catalyst

用于 AI 项目管理和 API 交互的工具集,助力 AI 项目高效开发与管理。

RagaAI-Catalyst 是一款专注于 AI 领域的强大工具集,为开发者提供了便捷的项目管理、API 交互、令牌管理等功能。支持多 API 密钥上传,能快速创建、列出和管理 AI 项目,还可获取项目用例和指标信息。适用于各类 AI 开发场景,提升开发效率,推动 AI 项目顺利开展。

smolagents

smolagents

一个包含多种工具和文档处理功能,适用于 LLM 使用的项目。

smolagents 是一个功能丰富的项目,提供了如文件格式转换、网页内容读取、语义搜索等多种工具,支持将常见文件类型或网页转换为 Markdown,方便进行文档处理和信息提取,能满足不同场景下的需求,提升工作效率和数据处理能力。

下拉加载更多