gong023 / ayaml
utility to convert yaml to array
Installs: 108 992
Dependents: 0
Suggesters: 0
Security: 0
Stars: 13
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: >=5.5
- gong023/retry: ^0.2.1
- nesbot/carbon: ^2.57
- symfony/yaml: ^5.3.6
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.*
- mockery/mockery: 0.9.*
- php-coveralls/php-coveralls: ^2.4.3
README
Utility for making Array from Yaml.
Setup
Install Ayaml
composer require --dev gong023/ayaml:0.2.*
Register yaml dir in testing bootstrap.php
\Ayaml\Ayaml::registerBasePath('/Dir/YamlFile/Exists');
Usage
Basic
Example yaml file is below.
# /Dir/YamlFile/Exists/User.yaml valid_user: id: 1 name: Taro created: 2014-01 valid_user_collection: user1: id: 1 name: Taro created: 2014-01 user2: id: 2 name: Jiro created: 2014-01
You can create array from above yaml file.
// plain pattern Ayaml::file('user')->schema('valid_user')->dump(); => ['id' => 1, 'name' => 'Taro', 'created' => '2014-01']; // with overwriting Ayaml::file('user')->schema('valid_user')->with(['id' => 2, 'name' => 'John'])->dump(); => ['id' => 2, 'name' => 'John', 'created' => '2014-01']; // you can get data from nested yaml Ayaml::file('user')->schema('valid_user_collection.user2')->dump(); => ['id' => 2, 'name' => 'Jiro', 'created' => '2014-01'];
Create Sequential Data
You can create sequential data from yaml data type.
$validUser = Ayaml::file('user')->schema('valid_user'); // make incremental id sequence. Ayaml::seq($validUser)->range('id', 10, 12)->byOne()->dump(); => [ ['id' => 10, 'name' => 'Taro', 'created' => '2014-01'], ['id' => 11, 'name' => 'Taro', 'created' => '2014-01'], ['id' => 12, 'name' => 'Taro', 'created' => '2014-01'], ]; // make decremental id sequence. Ayaml::seq($validUser)->range('id', 10, 8)->byOne()->dump(); => [ ['id' => 10, 'name' => 'Taro', 'created' => '2014-01'], ['id' => 9, 'name' => 'Taro', 'created' => '2014-01'], ['id' => 8, 'name' => 'Taro', 'created' => '2014-01'], ] // you can specify logic. Ayaml::seq($validUser)->range('id', 10, 12)->by(function($id) { return $id + 2; })->dump(); => [ ['id' => 10, 'name' => 'Taro', 'created' => '2014-01'], ['id' => 12, 'name' => 'Taro', 'created' => '2014-01'], ]; // make incremental date sequence. // you can specify duration 'byDay','byWeek','byMonth','byYear' Ayaml::seq($validUser)->between('created', '2014-01', '2014-03')->byMonth()->dump(); => [ ['id' => 1, 'name' => 'Taro', 'created' => '2014-01'], ['id' => 1, 'name' => 'Taro', 'created' => '2014-02'], ['id' => 1, 'name' => 'Taro', 'created' => '2014-03'], ]; // make decremental date sequence. Ayaml::seq($validUser)->between('created', '2014-03', '2014-01')->byMonth()->dump(); => [ ['id' => 1, 'name' => 'Taro', 'created' => '2014-03'], ['id' => 1, 'name' => 'Taro', 'created' => '2014-02'], ['id' => 1, 'name' => 'Taro', 'created' => '2014-01'], ]; // make numeric and date column sequential. Ayaml::seq($validUser) ->range('id', 10, 12)->byOne() ->between('created', '2014-01', '2014-03')->byMonth() ->dump(); => [ ['id' => 10, 'name' => 'Taro', 'created' => '2014-01'], ['id' => 11, 'name' => 'Taro', 'created' => '2014-02'], ['id' => 12, 'name' => 'Taro', 'created' => '2014-03'], ];