定制 himanshu-m/accessors 二次开发

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

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

himanshu-m/accessors

最新稳定版本:0.0.2

Composer 安装命令:

composer require himanshu-m/accessors

包简介

Define getter and setter for inaccessible members of a PHP class

README 文档

README

Define getter and setter for inaccessible members of a PHP class

Installation

composer require himanshu-m/accessors

Usage

Use the trait in any class to build getter and/or setters for the private and protected properties of the classes. It can also allow instance method which do not accept any arguments to invoked just like using a property of the object.

use Accessors;

class AccessorsTest
{
    use Accessors;

    private string $prop1;
    private string $prop2;

    function __construct(string $p1, string $p2)
    {
	$this->prop1 = $p1;
	$this->prop2 = $p2;

	$this->acccessible("prop1");
	// prop2 can also be renamed as readonlyProp for access from outside.
	$this->readonly("readonlyProp", "prop2");
    }
}

$obj = new AccessorsTest("property1", "property2");

echo $obj->prop1;
// property1
$obj->prop1 = "changed prop1";
echo $obj->readonlyProp;
// property2
$obj->readonlyProp = "cannot change prop2...";
// Exception: Property 'readonlyProp' of class AccessorsTest is not accessible

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-15