Skip to content
Snippets Groups Projects

Enable autowiring and use service closure

Open Michael Strelan requested to merge issue/project_browser-3450499:3450499-autowire into 1.0.x
2 unresolved threads
Files
2
@@ -3,7 +3,7 @@
namespace Drupal\project_browser_test\Datetime;
use Drupal\Component\Datetime\Time;
use Drupal\Core\State\StateInterface;
use Symfony\Component\DependencyInjection\Attribute\AutowireServiceClosure;
use Symfony\Component\HttpFoundation\RequestStack;
/**
@@ -25,13 +25,14 @@ class TestTime extends Time {
* The time service.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The RequestStack object.
* @param \Drupal\Core\State\StateInterface $state
* @param \Closure $state
* The state storage service.
*/
public function __construct(
Time $time,
RequestStack $request_stack,
protected readonly StateInterface $state,
#[AutowireServiceClosure('state')]
protected readonly \Closure $state,
) {
$this->decoratorTime = $time;
parent::__construct($request_stack);
@@ -41,7 +42,7 @@ class TestTime extends Time {
* {@inheritdoc}
*/
public function getRequestTime(): int {
if ($faked_date = $this->state->get('project_browser_test.fake_date_time')) {
if ($faked_date = ($this->state)()->get('project_browser_test.fake_date_time')) {
return \DateTime::createFromFormat('U', $faked_date)->getTimestamp();
}
return $this->decoratorTime->getRequestTime();
Loading