Download the PHP package ryunosuke/utility-attribute without Composer
On this page you can find all versions of the php package ryunosuke/utility-attribute. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package utility-attribute
PHP Utility Attribute
Description
This package provides generic/useful attribute.
Install
Usage
see below.
member | native | utility |
---|---|---|
const by class-string | (new ReflectionClassConstant(ClassName::class, 'CONST_NAME'))->getAttributes(AttributeClass::class)[0] ?? null | AttributeClass::of(ClassName::class . '::CONST_NAME') |
property by class-string | (new ReflectionProperty(ClassName::class, 'field_name'))->getAttributes(AttributeClass::class)[0] ?? null | AttributeClass::of(ClassName::class . '::$field_name') |
method by class-string | (new ReflectionMethod(ClassName::class, 'method_name'))->getAttributes(AttributeClass::class)[0] ?? null | AttributeClass::of(ClassName::class . '::method_name') |
const by $object | (new ReflectionClassConstant($object, 'CONST_NAME'))->getAttributes(AttributeClass::class)[0] ?? null | AttributeClass::of([$object, 'CONST_NAME']) |
property by $object | (new ReflectionProperty($object, 'field_name'))->getAttributes(AttributeClass::class)[0] ?? null | AttributeClass::of([$object, '$field_name']) |
method by $object | (new ReflectionMethod($object, 'method_name'))->getAttributes(AttributeClass::class)[0] ?? null | AttributeClass::of($object->method(...)) |
Note
個人的に php 標準の属性取得は下記の点で使いにくいです。
- わざわざリフレクションを経由したくない
- 手元にある class-string やインスタンスでダイレクトに取得したい
- name 未指定で取得することはまずない
- それなら Attribute クラスを主体にして取れた方が便利
- repeat な属性より single な属性の方が用途が多い
- それなら配列で返さず、?Attribute で返ってくる方が使いやすい
- getArguments が本当に arguments を返すので使いづらい
- 上記のように妙な分岐を入れざるを得ないので名前付き引数で統一して取得したい
- クラスの属性をメンバーの属性のデフォルトとして使いたい
- 例えば PHPUnit の
@group
とかそういうやつ。シチュエーションは結構多い
- 例えば PHPUnit の
- メソッドを委譲するだけで属性が消えてしまう
- 完全上書きなら元のメソッドの属性が欲しいことが多い
Release
Versioning is romantic versioning(no semantic versioning).
- major: large BC break. e.g. change architecture, package, class etc
- minor: small BC break. e.g. change arguments, return type etc
- patch: no BC break. e.g. fix bug, add optional arguments, code format etc
1.1.3
- [feature] DebugInfo の object/array の変換機能
1.1.2
- [fixbug] 可変長引数の場合に値が取れない不具合
1.1.1
- [feature] php8.2 のエラーを修正
1.1.0
- [change] php>=8.0
1.0.2
- [feature] MERGE_REPEATABLE を追加
1.0.1
- fix demo
1.0.0
- publish
License
MIT
All versions of utility-attribute with dependencies
PHP Build Version
Package Version
Requires
php Version
>=8.0
The package ryunosuke/utility-attribute contains the following files
Loading the files please wait ....