Created
August 11, 2023 11:11
-
-
Save dg/26baf3ce8f29d0f751e9dddfaa06504f to your computer and use it in GitHub Desktop.
Why NEON is better than YAML for dependency injection configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) | |
{ | |
/// | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see Service Definitions in Nette