Skip to content

Commit

Permalink
Add missing autowiring of clock (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Kolb <[email protected]>
  • Loading branch information
christian-kolb and Christian Kolb authored May 6, 2024
1 parent de94dc2 commit ce619c7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ The Doctrine types are automatically registered with the bundle with the followi
- `dtp_month`
- `dtp_year`

The package also contains a clock component consisting of the interface `Clock` with the two implementations `SystemClock` (for general use) and `FrozenClock` (for testing). The `SystemClock` will be autowired for the `Clock` and automatically replaced with `FrozenClock` in the test environment.

## Design

### Immutability
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/DateTimePrecisionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');

if ($container->getParameter('kernel.environment') === 'test') {
$loader->load('services_test.yaml');
}
}
}
7 changes: 7 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
services:

# Interface autowiring
DigitalCraftsman\DateTimePrecision\Clock\Clock: '@DigitalCraftsman\DateTimePrecision\Clock\SystemClock'

DigitalCraftsman\DateTimePrecision\Clock\SystemClock:
class: DigitalCraftsman\DateTimePrecision\Clock\SystemClock

# Normalizers
DigitalCraftsman\DateTimePrecision\Serializer\MomentNormalizer:
tags: [ { name: 'serializer.normalizer' } ]

Expand Down
7 changes: 7 additions & 0 deletions src/Resources/config/services_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:

# Interface autowiring
DigitalCraftsman\DateTimePrecision\Clock\Clock: '@DigitalCraftsman\DateTimePrecision\Clock\FrozenClock'

DigitalCraftsman\DateTimePrecision\Clock\FrozenClock:
class: DigitalCraftsman\DateTimePrecision\Clock\FrozenClock

0 comments on commit ce619c7

Please sign in to comment.