2017 © Pedro Peláez
 

library yaml-services

Callable Symfony YAML wrapper, with Pimple Service provider and PSR-3 Logger support

image

germania-kg/yaml-services

Callable Symfony YAML wrapper, with Pimple Service provider and PSR-3 Logger support

  • Wednesday, September 6, 2017
  • by germania-kg
  • Repository
  • 2 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Germania KG · YAML Services

Callable wrappers around Symfony's YAML component, with Pimple 3 Service provider and optional PSR3 Logger support., (*1)

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status, (*2)

Installation with Composer

$ composer require germania-kg/yaml-services

Parse YAML string

<?php
use Germania\YamlServices\YamlParserCallable;

// Instantiate
$parser = new YamlParserCallable;

// Do business, assuming YAML content string
$result = $parser( $yaml_content );

// Evaluate, usually Array [...]
print_r( $result );

Parse YAML file

<?php
use Germania\YamlServices\YamlFileParserCallable;
use Symfony\Component\Finder\Finder;

// Instantiate, passing a Symfony Finder
$finder = new Finder;
$finder = $finder->depth( 0 )->in( [ 'contents', 'includes'] );

// Setup parser
$parser = new YamlFileParserCallable( $finder );

// Do business, just passing your YAML file:
$result = $parser( "config.yaml" );

// Evaluate, usually Array [...]
print_r( $result );

Configuration

Both YamlParserCallable and YamlFileParserCallable accept the usual YAML Parser options, as described here: Symfony YAML Component or on GitHub. — Additionally, the constructor accepts any PSR 3 Logger., (*3)

Example 1: YamlParserCallable, (*4)

<?php
use Germania\YamlServices\YamlParserCallable;
use Symfony\Component\Yaml;

$parser = new YamlParserCallable( Yaml::PARSE_OBJECT );
$parser = new YamlParserCallable( Yaml::PARSE_OBJECT, $psr3_logger );

// Or, use per-case parsing options:
$custom_flags = Yaml::PARSE_OBJECT | YAML::PARSE_OBJECT_FOR_MAP;
$result = $parser($yaml_content, $custom_flags);
print_r( $result );

Example 2: YamlFileParserCallable, (*5)

<?php
use Germania\YamlServices\ YamlFileParserCallable;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml;

// Configure your Finder 
$finder = new Finder;
$finder = $finder->depth( 0 )->in( [ 'contents', 'includes'] );

// Setup parser
$parser = new YamlParserCallable( $finder, Yaml::PARSE_OBJECT );
$parser = new YamlParserCallable( $finder, Yaml::PARSE_OBJECT, $psr3_logger );

// Or, use per-case parsing options:
$custom_flags = Yaml::PARSE_OBJECT | YAML::PARSE_OBJECT_FOR_MAP;
$result = $parser( "config.yaml", $custom_flags);
print_r( $result );

Pimple Service Provider

Registering the Service Provider

<?php
use Germania\YamlServices\PimpleServiceProvider;

// Have your Pimple Container ready...
$dic = new Pimple\Container;

// Instantiate and register
$yaml_services = new PimpleServiceProvider;
$dic->register( $yaml_services );

Use YAML services

<?php
// To parse a string
$parser = $dic['Yaml.Parser'];
$result = $parser( "My YAML string" );

// To parse a file
$parser = $dic['Yaml.FileParser'];
$result = $parser( "config.yaml" );

Configuring the Service Provider

The PimpleServiceProvider constructor allows you to optionally pass these dependencies:, (*6)

  • YAML Parser options, service name: Yaml.Flags
  • The Symfony Finder instance, service name: Yaml.Finder
  • The PSR 3 Logger instance, service name: Yaml.Logger
$yaml_services = new PimpleServiceProvider( yaml_options, $finder, $psr3_logger) ;
$dic->register( $yaml_services );

As all dependencies are Pimple services as well, you alternatively may override each service like this:, (*7)

$dic->register( new PimpleServiceProvider );

$dic->extend('Yaml.Flags', function( $flags, $dic) {
    return $flags | YAML::PARSE_OBJECT_FOR_MAP;
});

$dic->extend('Yaml.Finder', function( $finder, $dic) {
    return $dic['MyCustomFinder'];
});

$dic->extend('Yaml.Logger', function( $logger, $dic) {
    return $dic['Logger']->withName('YAML');
});

Development

$ git clone https://github.com/GermaniaKG/YAML-Services.git
$ cd YAML-Services
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:, (*8)

$ composer test
# or
$ vendor/bin/phpunit

The Versions

06/09 2017

dev-master

9999999-dev

Callable Symfony YAML wrapper, with Pimple Service provider and PSR-3 Logger support

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

yaml callable service provider pimple symfony yaml symfony finder

06/09 2017

dev-develop

dev-develop

Callable Symfony YAML wrapper, with Pimple Service provider and PSR-3 Logger support

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

yaml callable service provider pimple symfony yaml symfony finder

30/08 2017

1.0.6

1.0.6.0

Callable Symfony YAML wrapper, with Pimple Service provider and PSR-3 Logger support

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

yaml callable service provider pimple symfony yaml symfony finder

29/08 2017

1.0.5

1.0.5.0

Callable Symfony YAML wrapper, with Pimple Service provider and PSR-3 Logger support

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

yaml callable service provider pimple symfony yaml symfony finder

29/08 2017

1.0.4

1.0.4.0

Callable Symfony YAML wrapper, with Pimple Service provider and PSR-3 Logger support

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

yaml callable service provider pimple symfony yaml symfony finder

29/08 2017

1.0.3

1.0.3.0

Symfony YAML Callables with Pimple ServiceProvider

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

yaml callable service provider pimple symfony finder

28/08 2017

1.0.2

1.0.2.0

Symfony YAML Callables with Pimple ServiceProvider

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

yaml callable service provider pimple symfony finder

22/08 2017

1.0.1

1.0.1.0

Symfony YAML Callables with Pimple ServiceProvider

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

yaml callable service provider pimple symfony finder

22/08 2017

1.0.0

1.0.0.0

Symfony YAML Callables with Pimple ServiceProvider

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

yaml callable service provider pimple symfony finder