mustangostang/spyc
Spyc is a pure-PHP YAML 1.0 loader/dumper. Parse YAML documents into PHP arrays, or serialize arrays back to YAML for config files, logs, and data exchange. Simple class-based or functional API for loading files and strings.
composer require mustangostang/spycSpyc::YAMLLoad() or Spyc::YAMLLoadFile()Spyc::YAMLDump()First use case: Load a simple config.yaml into your app:
$config = Spyc::YAMLLoadFile('config.yaml');
echo $config['app']['name'];
config.local.yaml)—especially useful in CLI tools or microservices.YAMLDump().YAMLLoad() to read multiple YAML versions (2.0-style keys, basic inline comments, simple anchors) without needing symfony/yaml.New in v0.6.3: Control how empty hashes ({}) are parsed:
$config = Spyc::YAMLLoadFile('config.yaml', [
'setting_empty_hash_as_object' => true,
]);
// Now {} loads as stdClass instead of [] (empty array)
Integration Tip: Wrap Spyc in a ConfigLoader class for centralized parsing and fallback handling (e.g., try config.yaml, then config.yml, then defaults).
--- + ...), inline anchors/aliases, or numeric keys with trailing spaces—they may misparse."123", '0') parse as strings, but unquoted 123 becomes integer. Beware of 007 → integer 7.symfony/yaml unless dependency size is critical. For legacy, Spyc is stable for basic configs.null, ~, NULL, false, FALSE are supported—but Off/On are not boolean aliases (unlike some YAML parsers).{} loads as an empty array ([]). Set 'setting_empty_hash_as_object' => true in options to get new \stdClass() instead—useful for objects expecting JSON compatibility (e.g., APIs returning YAML from JavaScript sources).&anchor or *ref unless you’re certain of compatibility—Spike fails silently with non-matching anchors.How can I help you explore Laravel packages today?