定制 bfg/attributes 二次开发

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

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

bfg/attributes

最新稳定版本:1.2.5

Composer 安装命令:

composer require bfg/attributes

包简介

Designed to work with PHP 8 attributes for classes

README 文档

README

Install

composer require bfg/attributes

Description

Designed to work with PHP 8 attributes

About the concept

The concept of this package is to look for attributes in classes and perform them.

Where can I use it?

When we use the PHP attributes as pointers to some actions.

It is important not to run this process in the overall stream of the user process, since the execution of this process can threaten the time.

Calling events on attribute

In order to find attributes, we need to specify which attribute we will search, by default the package searches everywhere except folders public,resources,storage, runtimes,database in the project or you can specify manually in which folder will look for an attribute.

Consider the global attribute search for the method:

use Bfg\Attributes\Items\AttributeClassItem;
use Bfg\Attributes\Items\AttributeConstantItem;
use Bfg\Attributes\Items\AttributeMethodItem;
use Bfg\Attributes\Items\AttributePropertyItem;
use Bfg\Attributes\Attributes;

Attributes::new(MyAttribute::class)
    ->map(function (AttributePropertyItem|AttributeMethodItem|AttributeClassItem|AttributeConstantItem $item) {
        // Process with my attribute
    });

Or the same search but in a specific folder:

use Bfg\Attributes\Items\AttributeClassItem;
use Bfg\Attributes\Attributes;

Attributes::new(MyAttribute::class)
    ->wherePath(app_path())
    ->map(function (AttributePropertyItem|AttributeMethodItem|AttributeClassItem|AttributeConstantItem $item) {
        // Process with my attribute
    });

Or find only class attributes

Attributes::new(MyAttribute::class)
    ->wherePath(app_path())
    ->whereTargetClass()
    ->map(function (AttributeClassItem $item) {
        // Process with my attribute
    });

Or the same search but in a specific class:

use Bfg\Attributes\Items\AttributeMethodItem;
use Bfg\Attributes\Attributes;

Attributes::new(MyAttribute::class)
    ->whereClass(MyAnyClassNamespace::class)
    ->whereTargetMethod()
    ->map(function (AttributeMethodItem $item) {
        // Process with my attribute
    });

Or you can get all found item attributes:

use Bfg\Attributes\Items\AttributePropertyItem;
use Bfg\Attributes\Attributes;

$collectionOfProperties = Attributes::new(MyAttribute::class)
    ->wherePath(app_path())
    ->whereTargetProperty()
    ->all();

$property = Attributes::new(MyAttribute::class)
    ->wherePath(app_path())
    ->whereTargetProperty()
    ->filter(fn (AttributePropertyItem $propertyItem) => $propertyItem)
    ->first();

Or you can get all classes:

use Bfg\Attributes\Attributes;

Attributes::new()
    ->wherePath(app_path())
    ->classes();

// In all directories    
$collectionOfClasses = Attributes::new()->classes();

Supported attributes

The package only supports class attributes, such as: Class,Method,Property,Class constant, or they are all at once

Check constants:

  1. \Attribute::TARGET_CLASS
  2. \Attribute::TARGET_METHOD
  3. \Attribute::TARGET_PROPERTY
  4. \Attribute::TARGET_CLASS_CONSTANT
  5. \Attribute::TARGET_ALL (by Default)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-15