peridot-php/object-path
最新稳定版本:1.0.0
Composer 安装命令:
composer require peridot-php/object-path
包简介
A string syntax to fetch values from array and object hierarchies
关键字:
README 文档
README
Allows traversal of objects and arrays with a simple string syntax. Extracted from Peridot's matcher library: Leo.
Usage
$data = [ 'name' => 'Brian', 'hobbies' => [ 'reading', 'programming', 'lion taming' ], 'address' => [ 'street' => '1234 Lane', 'zip' => '12345' ] ]; use Peridot\ObjectPath\ObjectPath; $path = new ObjectPath($data); $reading = $path->get('hobbies[0]'); $zip = $path->get('address[zip]'); // the result of get() is an ObjectPathValue instance $value = $reading->getPropertyValue(); // The syntax also works for objects and nested structures $data = new stdClass(); $data->name = 'Brian'; $data->address = new stdClass(); $data->address->zip = '12345'; $hobby = new stdClass(); $hobby->name = 'reading'; $hobby->style = 'relaxing'; $data->hobbies = [$hobby]; $path = new ObjectPath($data); $name = $path->get('name'); $zip = $path->get('address->zip'); $reading = $path->get('hobbies[0]->name');
Tests
$ composer install
$ vendor/bin/peridot specs/
统计信息
- 总下载量: 51.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-24