定制 antondperera/php-attributes-reader 二次开发

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

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

antondperera/php-attributes-reader

Composer 安装命令:

composer require antondperera/php-attributes-reader

包简介

Simple PHP Attributes Reader/Parser

README 文档

README

Welcome to PHP Attributes Reader, a lightweight and efficient library designed for effortlessly extracting and working with class, method, and property attributes in PHP 8. With the introduction of attributes in PHP 8, this library simplifies the process of reading and leveraging these attributes in your codebase. Whether you're exploring class, method, or property attributes, PHP Attributes Reader provides a user-friendly interface for seamless attribute retrieval, eliminating the need to deal with PHP's Reflection API directly. Enhance your development experience by easily tapping into the power of PHP 8 attributes with this intuitive and versatile library.

Requirements

PHP 8.1 and later.

Installation

You can install via Composer. Run the following command:

composer require antondperera/php-attributes-reader

Ensure you are using Composer's autoload:

require_once 'vendor/autoload.php';

Getting Started

Sample codes with simplest usages:

PHP Class with Class, Method and Property Attributes

<?php

declare(strict_types=1);

#[TestAttribute1('testValue1')]
class Abc
{
    #[TestAttribute2('testValue2')]
    public ?string $test_property_1 = null;

    public ?string $test_property_2 = null;

    #[TestAttribute3('testValue3')]
    public function testMethod1()
    {
        // rest of the codes
    }

    public function testMethod2()
    {
        // rest of the codes
    }

    // rest of the codes
}

Simplest way on reading those Attributes

<?php

declare(strict_types=1);

$class = Abc::class;

$attributes_reader = new \AntonDPerera\PHPAttributesReader\AttributesReader($class);

// Class attributes
echo $attributes_reader->hasClassAttributes(); // returns true
var_dump($attributes_reader->getClassAttributes()); // returns list of Class attributes


// Method attributes
echo $attributes_reader->hasMethodAttributes(); // returns true
echo $attributes_reader->hasMethodAttributes('testMethod2'); // returns false
echo $attributes_reader->hasMethodAttributes('testMethod1'); // returns true
var_dump($attributes_reader->getMethodAttributes('testMethod1')); // returns list of attributes for the given method. 


// Property attributes
echo $attributes_reader->hasPropertyAttributes(); // returns true
echo $attributes_reader->hasPropertyAttributes('test_property_2'); // returns false
echo $attributes_reader->hasPropertyAttributes('test_property_1'); // returns true
var_dump($attributes_reader->getPropertyAttributes('test_property_1')); // returns list of attributes for the given property.

For further details check the Documentation.

Documentation

Check the PHP Attributes Reader docs for a complete guide with all the methods and examples, and learn how to use them.

Limitations

PHP Attributes have many use cases. With the current version, PHP Attributes Reader covers much simpler usages of them. Check the Limitations section of PHP Attributes Reader docs for a more detailed guide.

Contribute

Please refer to the Contribution Guide for information on how to contribute to PHP Attributes Reader.

antondperera/php-attributes-reader 适用场景与选型建议

antondperera/php-attributes-reader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.79k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「library」 「php-attributes-reader」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 antondperera/php-attributes-reader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 antondperera/php-attributes-reader 我们能提供哪些服务?
定制开发 / 二次开发

基于 antondperera/php-attributes-reader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-09