Skip to content

Commit

Permalink
bug #48347 [Clock] Autowire PSR interface (wouterj)
Browse files Browse the repository at this point in the history
This PR was merged into the 6.2 branch.

Discussion
----------

[Clock] Autowire PSR interface

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Sorry for doing two things in a single PR, but it felt too small to split.

* The first commit I'm sure about: autowire PSR's `ClockInterface`, just like we do for e.g. the `EventDispatcherInterface`
* ~The second commit is something I want to propose after trying to write some docs on using Clock as a framework user: It isn't trivial to change the class of a definition from an application... and using a fixed moment in time while testing is *the* advantage of a clock component. So what about automatically switching to it when test mode is enabled?~ `@nicolas`-grekas

Commits
-------

648ed20 Autowire the PSR ClockInterface
  • Loading branch information
nicolas-grekas committed Nov 28, 2022
2 parents a97d79a + 648ed20 commit 3bc06b3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Expand Up @@ -20,6 +20,7 @@
use PhpParser\Parser;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Clock\ClockInterface as PsrClockInterface;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerAwareInterface;
Expand Down Expand Up @@ -277,6 +278,7 @@ public function load(array $configs, ContainerBuilder $container)
if (!ContainerBuilder::willBeAvailable('symfony/clock', ClockInterface::class, ['symfony/framework-bundle'])) {
$container->removeDefinition('clock');
$container->removeAlias(ClockInterface::class);
$container->removeAlias(PsrClockInterface::class);
}

$container->registerAliasForArgument('parameter_bag', PsrContainerInterface::class);
Expand Down
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Psr\Clock\ClockInterface as PsrClockInterface;
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\ConfigBuilderCacheWarmer;
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
Expand Down Expand Up @@ -230,6 +231,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []

->set('clock', NativeClock::class)
->alias(ClockInterface::class, 'clock')
->alias(PsrClockInterface::class, 'clock')

// register as abstract and excluded, aka not-autowirable types
->set(LoaderInterface::class)->abstract()->tag('container.excluded')
Expand Down

0 comments on commit 3bc06b3

Please sign in to comment.