masnathan/object
最新稳定版本:v1.1.0
Composer 安装命令:
composer require masnathan/object
包简介
Super Object that can handle everything you throw at him... or almost everything.
README 文档
README
Super Object that can handle everything you throw at him...
Install
Via Composer
$ composer require masnathan/object
Usage
use MASNathan\SuperObject; $object = new SuperObject(); $object->setMode('live'); $object->set('mode', 'live'); $object->mode = 'live'; $object['mode'] = 'live'; echo $object->getAppMode() // 'live' echo $object->get('app_mode') // 'live' echo $object->app_mode // 'live' echo $object['mode'] // 'live'
So... let's suppose you have an array like this:
$myBigDataArray = array( 'details' => array( 'first_name' => 'André', 'last_name' => 'Filipe', 'email' => 'andre.r.flip@gmail.com', 'social' => array( 'github' => 'https://github.com/MASNathan', 'twitter' => 'https://twitter.com/masnathan' ) ), 'account_info' => array( 'admin' => true, 'last_login' => 2015-06-13 13:37:00 ) 'cart_items' => array( array('id' => 1337), // (...) ) );
Using the SuperObject class you can access it's information like this:
$object = new SuperObject($myBigDataArray); echo $object->getDetails()->getFirstName(); // 'André' $object->getDetails()->isLastName('Roque'); // false echo $object->getDetails()->getSocial()->getGithub(); // 'https://github.com/MASNathan' echo $object->getDetails()->getSocial()->getFacebook(); // '' $object->getAccountInfo()->isAdmin(); // true $object->getAccountInfo()->unsetLastLogin(); // unsets $myBigDataArray['account_info']['last_login'] foreach ($object->getCartItems() as $item) { echo $item->getId(); // 1337 }
You can also retrive the contents of the SuperObject as an array or a StdClass:
$object->toArray(); // array( ... ) $object->toObject(); // StdClass( ... )
And even serialize/ deserialize the object
unserialize(serialize($object)); // or as json json_decode(json_encode($object));
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email andre.r.flip@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 93
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-17