maslosoft/addendum
Composer 安装命令:
composer require maslosoft/addendum
包简介
Powerful and easy to use PHP annotations
README 文档
README
Maslosoft Addendum
Powerful and easy to use PHP annotations
Quick Install
composer require maslosoft/addendum
Documentation
Annotations for PHP
This project provides smart annotations support for PHP language with the aim on performance and ease of use.
Annotations are in fact a kind declarative language embedded in PHP code. It does not allow and flow control structures, loops, conditions. It allows us to describe what is required or what we expect from parf of code.
Where to use annotations
While (PHP) programming language itself is very flexible and allows us to describe complex bahaviors, there are some aspects where we want to only describe (or configure) such behaviors. And we want to keep our main code as is, while adding some additional behaviors, which might include:
- Access control
- Way to display data
- Whether to store data
- Where to store data
- Should the data be searchable
And so on, with ever growing list of aspects and behaviors. While this could be made by implementing in our classe more and more interfaces, soon those would end up in hundreds of methods.
Another way could be some kind of extra meta-data configuration, let it be in XML, JSON or YAML files. This requires us to keep those too files in sync and also separates declarations from code. But we might need extra behaviors/aspects for many libraries - resulting in code being split into two or more files.
Embed behavior into code
So the idea is to embed those extra aspects of class into code. With annotations - special comment tags placed just above class/method/property declaration.
These annotations can be interpreted independently by different parts of program. These are extensible, so that adding more annotations does not influence existing code.
Different application parts might interpret just part of annotations while ignoring unknown ones.
In below example one part will react @Label and @Description declarations,
other will perform some extra operations when will encouner @I18N annotation.
Example:
class Page implements AnnotatedInterface { /** * Page URL * @Label('Page URL') * @Description('Relative URL, it should be simple lowercase string with words separated by hyphen') * @SearchBoost(3.5) * @I18N * @SafeValidator * @UrlValidator * @Decorator(Action, 'update') * @see Action * @var string */ public $url = ''; }
All extra metadata is contained just where class property is declared. This is it.
Annotations itself are not evaluated on each request. These are used to generate
metadata, which is later available by using meta containers. Having any object
implementing AnnotatedInterface, metadata can be obtained by passing either
object or class name.
Example of getting meta data:
echo Meta::create(Page::class)->url->label; // Will echo "Page URL"
This metadata is cached, so there is no overhead of parsing annotations.
maslosoft/addendum 适用场景与选型建议
maslosoft/addendum 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.57k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2013 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「annotations」 「php」 「metadata」 「annotation」 「addendum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maslosoft/addendum 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maslosoft/addendum 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maslosoft/addendum 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A collection of helpers for PHPUnit to ease testing Tarantool libraries.
The last validation library you will ever need!
Yii2 Component to manage SEO data and metadata
Extremely simple meta tag generator.
Customizations for routing
This library parses phpdoc annotations and generates md document that can be parsed by slate
统计信息
- 总下载量: 6.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 9
- 依赖项目数: 10
- 推荐数: 1
其他信息
- 授权协议: AGPL-3.0-only
- 更新时间: 2013-12-05