Skip to content

Commit

Permalink
[Dotenv][ErrorHandler][EventDispatcher] Use CPP
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark authored and nicolas-grekas committed Jan 8, 2024
1 parent 5cc5396 commit 9f85f14
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 36 deletions.
17 changes: 6 additions & 11 deletions Debug/TraceableEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,20 @@
*/
class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterface
{
protected ?LoggerInterface $logger;
protected Stopwatch $stopwatch;

/**
* @var \SplObjectStorage<WrappedListener, array{string, string}>|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
Expand Down
15 changes: 7 additions & 8 deletions Debug/WrappedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions DependencyInjection/AddEventAliasesPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions GenericEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [],
) {
}

/**
Expand Down
8 changes: 3 additions & 5 deletions ImmutableEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9f85f14

Please sign in to comment.