entire-studio/dynamic-accessors
最新稳定版本:v1.9.1
Composer 安装命令:
composer require entire-studio/dynamic-accessors
包简介
Dynamic setters and getters. While it can be done, it doesn't mean you should do it.
README 文档
README
Dynamic setters and getters. While it can be done, it doesn't mean you should do it.
Installation
Install the latest version with
$ composer require entire-studio/dynamic-accessors
Examples
Basic - accessors on class properties
<?php declare(strict_types=1); use EntireStudio\DynamicAccessors\{ DynamicAccessors, Get, Set }; /** * You can annotate your class for IDE completion * * @method string|void firstName(?string $argument = '') * @method void setLastName(string $name) * @method string getLastName() */ class Basic { use DynamicAccessors; #[Set, Get] private string $firstName; #[Set('setLastName'), Get('getLastName')] private string $lastName; } $basic = new Basic(); $basic->firstName('Clark'); $basic->setLastName('Kent'); printf( 'My name is %s %s.' . PHP_EOL, $basic->firstName(), $basic->getLastName(), );
$ php example/Basic.php
Constructor - accessors on constructor parameters
<?php declare(strict_types=1); use EntireStudio\DynamicAccessors\{ DynamicAccessors, Get, Set }; /** * You can annotate your class for IDE completion * * @method string|void firstName(?string $argument = '') * @method void setLastName(string $name) * @method string getLastName() */ class ConstructorPropertyPromotion { use DynamicAccessors; public function __construct( #[Set, Get] private string $firstName, #[Set('setLastName'), Get('getLastName')] private string $lastName, ) { } } $cpp = new ConstructorPropertyPromotion( 'Lois', 'Lane' ); printf( 'My name is %s %s.' . PHP_EOL, $cpp->firstName(), $cpp->getLastName(), );
$ php example/ConstructorPropertyPromotion.php
Commands
Development
composer test- runs test suite.composer sat- runs static analysis.composer style- checks codebase against PSR-12 coding style.composer style:fix- fixes basic coding style issues.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-26