From 9f85f14f70beb56bc09d3a87b220886c5ae725f4 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Mon, 8 Jan 2024 08:27:24 +0100 Subject: [PATCH] [Dotenv][ErrorHandler][EventDispatcher] Use CPP --- Debug/TraceableEventDispatcher.php | 17 ++++++----------- Debug/WrappedListener.php | 15 +++++++-------- DependencyInjection/AddEventAliasesPass.php | 8 +++----- GenericEvent.php | 11 ++++------- ImmutableEventDispatcher.php | 8 +++----- 5 files changed, 23 insertions(+), 36 deletions(-) diff --git a/Debug/TraceableEventDispatcher.php b/Debug/TraceableEventDispatcher.php index 1163e07..f6b96bf 100644 --- a/Debug/TraceableEventDispatcher.php +++ b/Debug/TraceableEventDispatcher.php @@ -30,25 +30,20 @@ */ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterface { - protected ?LoggerInterface $logger; - protected Stopwatch $stopwatch; - /** * @var \SplObjectStorage|null */ private ?\SplObjectStorage $callStack = null; - private EventDispatcherInterface $dispatcher; private array $wrappedListeners = []; private array $orphanedEvents = []; - private ?RequestStack $requestStack; private string $currentRequestHash = ''; - public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null, RequestStack $requestStack = null) - { - $this->dispatcher = $dispatcher; - $this->stopwatch = $stopwatch; - $this->logger = $logger; - $this->requestStack = $requestStack; + public function __construct( + private EventDispatcherInterface $dispatcher, + protected Stopwatch $stopwatch, + protected ?LoggerInterface $logger = null, + private ?RequestStack $requestStack = null, + ) { } public function addListener(string $eventName, callable|array $listener, int $priority = 0): void diff --git a/Debug/WrappedListener.php b/Debug/WrappedListener.php index 11462df..b83115b 100644 --- a/Debug/WrappedListener.php +++ b/Debug/WrappedListener.php @@ -26,21 +26,20 @@ final class WrappedListener private string $name; private bool $called = false; private bool $stoppedPropagation = false; - private Stopwatch $stopwatch; - private ?EventDispatcherInterface $dispatcher; private string $pretty; private string $callableRef; private ClassStub|string $stub; - private ?int $priority = null; private static bool $hasClassStub; - public function __construct(callable|array $listener, ?string $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null, int $priority = null) - { + public function __construct( + callable|array $listener, + ?string $name, + private Stopwatch $stopwatch, + private ?EventDispatcherInterface $dispatcher = null, + private ?int $priority = null, + ) { $this->listener = $listener; $this->optimizedListener = $listener instanceof \Closure ? $listener : (\is_callable($listener) ? $listener(...) : null); - $this->stopwatch = $stopwatch; - $this->dispatcher = $dispatcher; - $this->priority = $priority; if (\is_array($listener)) { [$this->name, $this->callableRef] = $this->parseListener($listener); diff --git a/DependencyInjection/AddEventAliasesPass.php b/DependencyInjection/AddEventAliasesPass.php index 13b4336..5308992 100644 --- a/DependencyInjection/AddEventAliasesPass.php +++ b/DependencyInjection/AddEventAliasesPass.php @@ -21,11 +21,9 @@ */ class AddEventAliasesPass implements CompilerPassInterface { - private array $eventAliases; - - public function __construct(array $eventAliases) - { - $this->eventAliases = $eventAliases; + public function __construct( + private array $eventAliases, + ) { } public function process(ContainerBuilder $container): void diff --git a/GenericEvent.php b/GenericEvent.php index cb3edef..2ac654f 100644 --- a/GenericEvent.php +++ b/GenericEvent.php @@ -25,19 +25,16 @@ */ class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate { - protected mixed $subject; - protected array $arguments; - /** * Encapsulate an event with $subject and $arguments. * * @param mixed $subject The subject of the event, usually an object or a callable * @param array $arguments Arguments to store in the event */ - public function __construct(mixed $subject = null, array $arguments = []) - { - $this->subject = $subject; - $this->arguments = $arguments; + public function __construct( + protected mixed $subject = null, + protected array $arguments = [], + ) { } /** diff --git a/ImmutableEventDispatcher.php b/ImmutableEventDispatcher.php index 1e863cc..f715ecb 100644 --- a/ImmutableEventDispatcher.php +++ b/ImmutableEventDispatcher.php @@ -18,11 +18,9 @@ */ class ImmutableEventDispatcher implements EventDispatcherInterface { - private EventDispatcherInterface $dispatcher; - - public function __construct(EventDispatcherInterface $dispatcher) - { - $this->dispatcher = $dispatcher; + public function __construct( + private EventDispatcherInterface $dispatcher, + ) { } public function dispatch(object $event, string $eventName = null): object