PHP code example of wexample / php-yaml

1. Go to this page and download the library: Download wexample/php-yaml 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/ */

    

wexample / php-yaml example snippets


use Wexample\PhpYaml\YamlIncludeResolver;

// Create a resolver instance
$resolver = new YamlIncludeResolver();

// Register individual YAML files with domain names
$resolver->registerFile('@domain.one', '/path/to/one.yml');
$resolver->registerFile('@domain.two', '/path/to/two.yml');

// Get values using domain and key references
$value = $resolver->getValueResolved('@domain.one::some_key');
$value = $resolver->getValue('some_key', 'domain.one');

// Get nested values using dot notation
$nestedValue = $resolver->getValueResolved('@domain.one::group.subgroup.key');

// Process multiple values at once, resolving all references
$translations = [
    'key1' => 'Simple value',
    'key2' => '@domain.one::some_key',
    'key3' => '@domain.two::other_key',
    'key4' => '%' // Same key wildcard
];

// Resolve all references in the array
$resolved = $resolver->resolveValues($translations);

// With a specific domain for wildcard references
$resolved = $resolver->resolveValues($translations, '@domain.two');

use Wexample\PhpYaml\YamlIncludeResolver;
use Wexample\SymfonyTranslations\Translation\Translator;

// Create a resolver instance
$resolver = new YamlIncludeResolver();

// Create a translator that uses the resolver
$translator = new Translator($resolver);

// The translator will use the resolver to handle references in translation files
bash
composer