定制 damirco/attr 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

damirco/attr

Composer 安装命令:

composer require damirco/attr

包简介

PHP Attributes Library Package

README 文档

README

PHP library for checking the presence of attributes on classes, properties, methods, parameters, functions, class constants, and enum cases.

Requirements

  • PHP 8.0+

Installation

composer require damirco/attr

Usage

use Damirco\Attr\ClassAttribute;
use Damirco\Attr\PropertyAttribute;
use Damirco\Attr\MethodAttribute;
use Damirco\Attr\ParameterAttribute;
use Damirco\Attr\FunctionAttribute;
use Damirco\Attr\ClassConstantAttribute;
use Damirco\Attr\EnumCaseAttribute;

Check class attributes

$attribute = new ClassAttribute(MyAttribute::class);

$attribute->isPresentOn(MyClass::class);       // by class name
$attribute->isPresentOn(new MyClass());         // by instance

Check property attributes

$attribute = new PropertyAttribute(MyAttribute::class);

$attribute->isPresentOn(MyClass::class, 'propertyName');

Check method attributes

$attribute = new MethodAttribute(MyAttribute::class);

$attribute->isPresentOn(MyClass::class, 'methodName');

Check parameter attributes

$attribute = new ParameterAttribute(MyAttribute::class);

$attribute->isPresentOn(myFunction(...), 'paramName');

Check function attributes

$attribute = new FunctionAttribute(MyAttribute::class);

$attribute->isPresentOn(myFunction(...));

Check class constant attributes

$attribute = new ClassConstantAttribute(MyAttribute::class);

$attribute->isPresentOn(MyClass::class, 'CONSTANT_NAME');

Check enum case attributes

$attribute = new EnumCaseAttribute(MyAttribute::class);

$attribute->isPresentOn(MyEnum::class, 'CASE_NAME');

Available classes

Class Checks
ClassAttribute Class-level attributes
PropertyAttribute Property attributes
MethodAttribute Method attributes
ParameterAttribute Function/method parameter attributes
FunctionAttribute Function attributes
ClassConstantAttribute Class constant attributes
EnumCaseAttribute Enum case attributes

Configuration

All classes extend AbstractAttribute and accept two constructor parameters:

new ClassAttribute(
    attribute_class: MyAttribute::class,  // attribute to check for
    flags: \ReflectionAttribute::IS_INSTANCEOF  // matching mode (default)
);

Flags

  • \ReflectionAttribute::IS_INSTANCEOF (default) — matches if the attribute is an instance of the given class
  • 0 — exact class match only

Fluent setters

$attribute = new ClassAttribute(MyAttribute::class)
    ->setAttributeClass(AnotherAttribute::class)
    ->setFlags(0);

Testing

composer test

License

MIT

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固