Search by

switon / yaml

switon

Strict Switon YAML subset read/write with placeholder interpolation for Switon Framework

v1.0.2 2026-08-23 01:20 UTC

This package is auto-updated.

Last update: 2026-11-26 15:18:37 UTC


README

YAML CI PHP 8.3+

Switon's strict YAML subset reader/writer and placeholder resolver for predictable config documents.

Highlights

  • Strict YAML subset: only the supported Switon YAML features are parsed and emitted.
  • Single-step read: YAML can be parsed and interpolated at once.
  • Array → YAML dump: emit config-friendly block YAML without going through JSON.
  • Predictable failures: parse errors are reported clearly.
  • Config-friendly arrays: parse results are plain PHP arrays for config loading.

Installation

composer require switon/yaml

Quick Start

use Switon\Core\Attribute\Autowired;
use Switon\Yaml\YamlReaderInterface;
use Switon\Yaml\YamlWriterInterface;

class ConfigService
{
    #[Autowired] protected YamlReaderInterface $yamlReader;
    #[Autowired] protected YamlWriterInterface $yamlWriter;

    public function load(string $yaml): array
    {
        return $this->yamlReader->read($yaml, ['APP_ENV' => 'prod']);
    }

    /** @param array<int|string, mixed> $data */
    public function save(string $file, array $data): void
    {
        $this->yamlWriter->write($file, $data);
    }
}

Docs: https://github.com/switon-php/yaml/blob/main/docs/README.md

License

MIT.