Skip to content

Commit 4ba7d87

Browse files
nicolas-grekasfabpot
authored andcommitted
[Clock] A new component to decouple applications from the system clock
1 parent 9996b6f commit 4ba7d87

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use PHPStan\PhpDocParser\Parser\PhpDocParser;
2121
use Psr\Cache\CacheItemPoolInterface;
2222
use Psr\Container\ContainerInterface as PsrContainerInterface;
23-
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
2423
use Psr\Http\Client\ClientInterface;
2524
use Psr\Log\LoggerAwareInterface;
2625
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
@@ -40,6 +39,7 @@
4039
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
4140
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
4241
use Symfony\Component\Cache\ResettableInterface;
42+
use Symfony\Component\Clock\ClockInterface;
4343
use Symfony\Component\Config\Definition\ConfigurationInterface;
4444
use Symfony\Component\Config\FileLocator;
4545
use Symfony\Component\Config\Loader\LoaderInterface;
@@ -273,8 +273,9 @@ public function load(array $configs, ContainerBuilder $container)
273273
$loader->load('fragment_renderer.php');
274274
$loader->load('error_renderer.php');
275275

276-
if (ContainerBuilder::willBeAvailable('psr/event-dispatcher', PsrEventDispatcherInterface::class, ['symfony/framework-bundle'])) {
277-
$container->setAlias(PsrEventDispatcherInterface::class, 'event_dispatcher');
276+
if (!ContainerBuilder::willBeAvailable('symfony/clock', ClockInterface::class, ['symfony/framework-bundle'])) {
277+
$container->removeDefinition('clock');
278+
$container->removeAlias(ClockInterface::class);
278279
}
279280

280281
$container->registerAliasForArgument('parameter_bag', PsrContainerInterface::class);

Resources/config/services.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
1415
use Symfony\Bundle\FrameworkBundle\CacheWarmer\ConfigBuilderCacheWarmer;
1516
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
17+
use Symfony\Component\Clock\ClockInterface;
18+
use Symfony\Component\Clock\NativeClock;
1619
use Symfony\Component\Config\Loader\LoaderInterface;
1720
use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
1821
use Symfony\Component\Config\ResourceCheckerConfigCacheFactory;
@@ -77,6 +80,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
7780
->tag('event_dispatcher.dispatcher', ['name' => 'event_dispatcher'])
7881
->alias(EventDispatcherInterfaceComponentAlias::class, 'event_dispatcher')
7982
->alias(EventDispatcherInterface::class, 'event_dispatcher')
83+
->alias(PsrEventDispatcherInterface::class, 'event_dispatcher')
8084

8185
->set('http_kernel', HttpKernel::class)
8286
->public()
@@ -223,6 +227,9 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
223227
->args([service(KernelInterface::class), service('logger')->nullOnInvalid()])
224228
->tag('kernel.cache_warmer')
225229

230+
->set('clock', NativeClock::class)
231+
->alias(ClockInterface::class, 'clock')
232+
226233
// register as abstract and excluded, aka not-autowirable types
227234
->set(LoaderInterface::class)->abstract()->tag('container.excluded')
228235
->set(Request::class)->abstract()->tag('container.excluded')

0 commit comments

Comments
 (0)