Download the PHP package ysh/webman-annotation without Composer

On this page you can find all versions of the php package ysh/webman-annotation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package webman-annotation

Webman Annotation Plugin

一个功能完整、生产就绪的 Webman 框架注解插件,支持路由、中间件、依赖注入、定时任务、事件监听和自定义注解等功能。

PHP Version Webman

📋 目录

✨ 功能特性

核心功能

高级特性

🚀 安装

使用 Composer 安装

系统要求

可选依赖

🎯 快速开始

1. 安装插件

2. 配置文件

安装后,配置文件会自动复制到 config/plugin/x2nx/webman-annotation/ 目录。

3. 创建第一个注解路由

4. 重启服务

访问 http://localhost:8787/ 即可看到响应。

⚙️ 配置说明

主配置文件 (app.php)

配置文件位置:config/plugin/x2nx/webman-annotation/app.php

进程配置 (process.php)

定时任务监控进程配置(已自动配置,通常无需修改):

中间件配置 (middleware.php)

自定义注解中间件配置(已自动配置):

🛣️ 路由注解

支持的 HTTP 方法注解

本包支持以下 HTTP 方法注解:

基础用法

路由前缀和分组

路由命名

路由参数

🛡️ 中间件注解

类级别中间件

方法级别中间件

多个中间件

💉 依赖注入

[Value] 注解 - 配置值注入

#[Value] 注解用于注入配置值或环境变量。

基础用法

支持的键格式

类型转换

[Inject] 注解 - 服务注入

#[Inject] 注解用于注入服务依赖。

基础用法(类型提示注入)

命名注入

懒加载

注意:懒加载仅适用于属性类型为 object 或 mixed,或者没有类型提示的情况。

循环依赖自动处理

本包自动检测并处理循环依赖,用户无需修改代码:

工作原理:

组合使用

🏭 Bean 管理

使用 #[Bean] 注解将类注册为单例对象到容器中。

基础用法

命名 Bean

Bean 与依赖注入结合

⏰ 定时任务

使用 #[Cron] 注解定义定时任务。

基础用法

Cron 表达式格式

格式:秒 分 时 日 月 周

常用示例:

参数说明

注意:multiProcess 参数已移除,定时任务默认使用分布式锁确保只在一个进程中执行。如果需要多进程执行,请使用动态注册方式。

依赖注入支持

定时任务支持 #[Value] 和 #[Inject] 注解:

动态注册定时任务

除了使用注解,还可以动态注册定时任务:

多进程和分布式锁

定时任务默认使用分布式锁(基于 webman/cache)确保在多进程环境下不会重复执行:

  1. 首先尝试使用 Cache(支持 file、redis 等驱动)
  2. 如果 Cache 不可用,任务将跳过执行

锁的 TTL 为 300 秒(5分钟),确保即使进程异常退出,锁也会自动释放。

📢 事件监听

使用 #[Event] 注解注册事件监听器。

基础用法

触发事件

一个方法监听多个事件

优先级

依赖注入支持

事件监听器支持 #[Value] 和 #[Inject] 注解:

🎨 自定义注解

支持用户自定义注解和处理器。

1. 创建注解类

2. 创建处理器

3. 配置注解映射

在 config/plugin/x2nx/webman-annotation/app.php 中配置:

4. 使用自定义注解

5. 程序内调用自定义注解

使用场景:

⚡ 性能优化

注解白名单/黑名单

本包实现了注解白名单和黑名单机制,只解析已实现和配置中注册的注解,大幅提高扫描性能。

白名单(自动包含)

以下注解会自动包含在白名单中:

黑名单配置

缓存机制

扫描优化

🔧 高级功能

循环依赖自动处理

本包自动检测并处理循环依赖,用户无需修改代码。详见 CIRCULAR_DEPENDENCY.md。

懒加载

使用 #[Inject(lazy: true)] 实现懒加载:

注意:懒加载仅适用于属性类型为 object 或 mixed,或者没有类型提示的情况。

动态任务注册

❓ 常见问题

Q: 路由注解不生效?

A: 检查以下几点:

  1. 确保 auto_register_routes 配置为 true
  2. 确保控制器类在 scan_dirs 配置的目录中
  3. 重启 Webman 服务:php start.php restart
  4. 检查路由文件 config/plugin/x2nx/webman-annotation/route.php 是否存在

Q: 依赖注入失败?

A: 检查以下几点:

  1. 确保 enable_value_injection 配置为 true
  2. 确保属性类型提示正确
  3. 检查容器配置 config/container.php 是否正确
  4. 查看日志文件中的错误信息

Q: 定时任务不执行?

A: 检查以下几点:

  1. 确保 auto_register_crons 配置为 true
  2. 确保 cron_monitor.enable 配置为 true
  3. 检查进程配置 config/plugin/x2nx/webman-annotation/process.php
  4. 查看日志文件中的错误信息
  5. 确保 workerman/crontab 已安装

Q: 事件监听器不执行?

A: 检查以下几点:

  1. 确保 auto_register_events 配置为 true
  2. 确保 webman/event 已安装
  3. 检查事件名称是否正确
  4. 查看日志文件中的错误信息

Q: 循环依赖如何处理?

A: 本包自动检测并处理循环依赖,用户无需修改代码。系统会:

  1. 自动检测循环依赖
  2. 使用正在构建的实例打破循环
  3. 不抛出异常,用户无感
  4. 记录警告日志(用于调试)

Q: 如何提高扫描性能?

A:

  1. 启用缓存:enable_cache => true
  2. 配置黑名单,排除不需要扫描的类
  3. 使用 Redis 作为缓存驱动
  4. 减少扫描目录范围

📚 API 参考

注解类

路由注解

其他注解

工具类

接口

🎯 最佳实践

1. 路由组织

2. 依赖注入

3. 定时任务

4. 事件监听

5. 性能优化

📝 更新日志

详见 CHANGELOG.md(如果存在)

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License

🔗 相关链接


Made with ❤️ for Webman Framework


All versions of webman-annotation with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
workerman/webman-framework Version ^2.0
webman/cache Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ysh/webman-annotation contains the following files

Loading the files please wait ...