Skip to content

Instantly share code, notes, and snippets.

@dg
Created August 11, 2023 11:11
Show Gist options
  • Save dg/26baf3ce8f29d0f751e9dddfaa06504f to your computer and use it in GitHub Desktop.
Save dg/26baf3ce8f29d0f751e9dddfaa06504f to your computer and use it in GitHub Desktop.
Why NEON is better than YAML for dependency injection configuration
<?php
class FooSettings
{
public function __construct(
public readonly int $id,
public readonly string $name,
) {
}
}
class Foo
{
public function __construct(
public readonly FooSettings $settings,
) {
}
public function setSomething($value)
{
///
}
}
# thanks to the NEON format, the configuration in Nette is very concise and resembles writing in PHP
services:
-
create: Foo( FooSettings(123, 'some value') )
setup:
- setSomething('foo')
# the configuration in Symfony is very verbose also due to the limitations of the YAML format
services:
FooSettings:
arguments:
- 123
- 'some value'
Foo:
arguments:
- '@FooSettings'
calls:
- setSomething: ['foo']
@dg
Copy link
Author

dg commented Aug 11, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment