PHP code example of germania-kg / yaml-services

1. Go to this page and download the library: Download germania-kg/yaml-services library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

germania-kg / yaml-services example snippets



use Germania\YamlServices\YamlParserCallable;

// Instantiate
$parser = new YamlParserCallable;

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

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


use Germania\YamlServices\YamlFileParserCallable;
use Symfony\Component\Finder\Finder;

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


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 );



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', ':PARSE_OBJECT | YAML::PARSE_OBJECT_FOR_MAP;
$result = $parser( "config.yaml", $custom_flags);
print_r( $result );



use Germania\YamlServices\PimpleServiceProvider;

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

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


// 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" );

$yaml_services = new PimpleServiceProvider( yaml_options, $finder, $psr3_logger) ;
$dic->register( $yaml_services );

$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');
});