2017 © Pedro Peláez
 

library ayaml

utility to convert yaml to array

image

gong023/ayaml

utility to convert yaml to array

  • Wednesday, July 27, 2016
  • by gong023
  • Repository
  • 2 Watchers
  • 11 Stars
  • 29,158 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

Ayaml

Build Status Coverage Status Scrutinizer Code Quality, (*1)

Utility for making Array from Yaml., (*2)

Setup

Install Ayaml, (*3)

composer require --dev gong023/ayaml:0.2.*

Register yaml dir in testing bootstrap.php, (*4)

\Ayaml\Ayaml::registerBasePath('/Dir/YamlFile/Exists');

Usage

Basic

Example yaml file is below., (*5)

# /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., (*6)

// 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., (*7)

$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'],
];

The Versions

29/12 2014
24/12 2014

0.1.0

0.1.0.0

utility to convert yaml to array

  Sources   Download

MIT

The Requires

 

The Development Requires

by sho ogihara

24/12 2014

0.0.1

0.0.1.0

utility to convert yaml to array

  Sources   Download

MIT

The Requires

 

The Development Requires

by sho ogihara