Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[EventDispatcher] Add types to private properties #41924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
protected $logger;
protected $stopwatch;

private $callStack;
private $dispatcher;
private $wrappedListeners;
private $orphanedEvents;
private $requestStack;
private $currentRequestHash = '';
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->wrappedListeners = [];
$this->orphanedEvents = [];
$this->requestStack = $requestStack;
}

Expand Down
34 changes: 14 additions & 20 deletions src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,24 @@
*/
final class WrappedListener
{
private $listener;
private $optimizedListener;
private $name;
private $called;
private $stoppedPropagation;
private $stopwatch;
private $dispatcher;
private $pretty;
private $stub;
private $priority;
private static $hasClassStub;
private string|array|object $listener;
private ?\Closure $optimizedListener;
private string $name;
private bool $called = false;
private bool $stoppedPropagation = false;
private Stopwatch $stopwatch;
private ?EventDispatcherInterface $dispatcher;
private string $pretty;
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)
{
$this->listener = $listener;
$this->optimizedListener = $listener instanceof \Closure ? $listener : (\is_callable($listener) ? \Closure::fromCallable($listener) : null);
$this->stopwatch = $stopwatch;
$this->dispatcher = $dispatcher;
$this->called = false;
$this->stoppedPropagation = false;

if (\is_array($listener)) {
$this->name = \is_object($listener[0]) ? get_debug_type($listener[0]) : $listener[0];
Expand All @@ -66,12 +64,10 @@ public function __construct(callable|array $listener, ?string $name, Stopwatch $
$this->name = $name;
}

if (null === self::$hasClassStub) {
self::$hasClassStub = class_exists(ClassStub::class);
}
self::$hasClassStub ??= class_exists(ClassStub::class);
}

public function getWrappedListener()
public function getWrappedListener(): callable|array
{
return $this->listener;
}
Expand All @@ -93,9 +89,7 @@ public function getPretty(): string

public function getInfo(string $eventName): array
{
if (null === $this->stub) {
$this->stub = self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()';
}
$this->stub ??= self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()';

return [
'event' => $eventName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class AddEventAliasesPass implements CompilerPassInterface
{
private $eventAliases;
private array $eventAliases;

public function __construct(array $eventAliases)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
*/
class RegisterListenersPass implements CompilerPassInterface
{
private $hotPathEvents = [];
private $hotPathTagName = 'container.hot_path';
private $noPreloadEvents = [];
private $noPreloadTagName = 'container.no_preload';
private array $hotPathEvents = [];
private string $hotPathTagName = 'container.hot_path';
private array $noPreloadEvents = [];
private string $noPreloadTagName = 'container.no_preload';

/**
* @return $this
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/EventDispatcher/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
*/
class EventDispatcher implements EventDispatcherInterface
{
private $listeners = [];
private $sorted = [];
private $optimized;
private array $listeners = [];
private array $sorted = [];
private array $optimized;

public function __construct()
{
Expand All @@ -49,7 +49,7 @@ public function dispatch(object $event, string $eventName = null): object
{
$eventName = $eventName ?? \get_class($event);

if (null !== $this->optimized) {
if (isset($this->optimized)) {
$listeners = $this->optimized[$eventName] ?? (empty($this->listeners[$eventName]) ? [] : $this->optimizeListeners($eventName));
} else {
$listeners = $this->getListeners($eventName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class ImmutableEventDispatcher implements EventDispatcherInterface
{
private $dispatcher;
private EventDispatcherInterface $dispatcher;

public function __construct(EventDispatcherInterface $dispatcher)
{
Expand Down