switon / yaml
Strict Switon YAML subset read/write with placeholder interpolation for Switon Framework
v1.0.2
2026-08-23 01:20 UTC
Requires
- php: >=8.3
- ext-json: *
- switon/core: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^12.0
- switon/testing: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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.