rumd3x/php-baseobject
Composer 安装命令:
composer require rumd3x/php-baseobject
包简介
A very helpful class to extend from and use as a base for other classes.
README 文档
README
A very helpful class to extend from and use as a base for other classes.
Installation
To install via composer just run
composer require rumd3x/php-baseobject
Usage
Inheriting stuff
Just make any class extending the BaseObject
use Rumd3x\BaseObject\BaseObject; class MyClass extends BaseObject { // Your class definition private $my_property; }
Automatic getters and setters
To use the automatic getters and setters, make your properties snake case, and your methods camel case.
$obj = new MyClass; $obj->my_property = 'value'; // This will automatically do $obj->setMyProperty('value'); if you have defined this method. $prop_value = $obj->my_property; // This will automatically do $prop_value = $obj->getMyProperty(); if you have defined this method.
Helpers
There are several standard helper method on the base object to help on object manipulation in addidition to the already defined php magic methods.
$obj = new MyClass; // BaseObject::parse($data) Creates a new instance base on the contents of $data. // Data can be either an object of any class, an array, a json string or a XML string. MyClass::parse($data); // Returns instance of MyClass. $obj->parse($data); // Casts $data into the already existing instance. $obj->toArray(); // Converts the object to an array. $obj->toJson(); // Converts the object to a json string representation. $obj->toXml(); // Converts the object to a XML string representation. // You can also safely use the object to along side with strings. echo $obj; $string = "my object value => {$obj}";
统计信息
- 总下载量: 372
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-08-20