selfiens/property-alias
最新稳定版本:1.0
Composer 安装命令:
composer require selfiens/property-alias
包简介
Enables property alias via ClassDoc
README 文档
README
This package enables you to create aliases for existing class properties with a simple ClassDoc setup.
Below is an example of creating an alias to $this->foo.
/** * @property $my_alias = foo * ^ * | * This is how you define an alias to "$foo". * Valid PHP identifiers will work, including UTF-8 $한글. */ class MyClass { use \Selfiens\PropertyAliasTrait; public string $foo = 'foo'; }
Then you can read/write properties via alias.
$my = new MyClass(); // read echo $my->my_alias; // 'foo' // write $my->my_alias = 'bar'; echo $my->foo; // 'bar';
Install
composer require selfiens/property-alias:^1.0
Setup
This package's \Selfiens\PropertyAliasTrait uses ClassDoc as the source of alias definitions.
You can create aliases using the @property syntax, as shown in the following example:
/** * @property $alias_name = target_property */
You can define as many aliases as you desire. Aliases can point to the other aliases.
Background
Aliases on existing properties
This package aims to assist in accessing poorly named properties by better names. It is designed to help in situations where you are unable to rename a property due to reasons such as its origin from an external API, a poorly named database field, or the high risk associated with refactoring the name.
Defining aliases in ClassDoc with @property
The @property definitions in ClassDoc are understood by many IDEs,
and these IDEs will provide auto-completions and refactorings as if the aliases were real properties.
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-27