定制 entire-studio/dynamic-accessors 二次开发

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

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

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

Packagist Version (including pre-releases) GitHub release (latest SemVer including pre-releases) CI codecov

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-26