(Grav GitSync) Automatic Commit from smokephil
This commit is contained in:
parent
ab8f386766
commit
54730a9480
251 changed files with 5008 additions and 8945 deletions
|
|
@ -42,7 +42,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
|||
private $requestStack;
|
||||
private $currentRequestHash = '';
|
||||
|
||||
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null, RequestStack $requestStack = null)
|
||||
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, ?LoggerInterface $logger = null, ?RequestStack $requestStack = null)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->stopwatch = $stopwatch;
|
||||
|
|
@ -97,7 +97,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListeners(string $eventName = null)
|
||||
public function getListeners(?string $eventName = null)
|
||||
{
|
||||
return $this->dispatcher->getListeners($eventName);
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasListeners(string $eventName = null)
|
||||
public function hasListeners(?string $eventName = null)
|
||||
{
|
||||
return $this->dispatcher->hasListeners($eventName);
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dispatch(object $event, string $eventName = null): object
|
||||
public function dispatch(object $event, ?string $eventName = null): object
|
||||
{
|
||||
$eventName = $eventName ?? \get_class($event);
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
|||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCalledListeners(Request $request = null)
|
||||
public function getCalledListeners(?Request $request = null)
|
||||
{
|
||||
if (null === $this->callStack) {
|
||||
return [];
|
||||
|
|
@ -192,7 +192,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
|||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getNotCalledListeners(Request $request = null)
|
||||
public function getNotCalledListeners(?Request $request = null)
|
||||
{
|
||||
try {
|
||||
$allListeners = $this->getListeners();
|
||||
|
|
@ -235,7 +235,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
|
|||
return $notCalled;
|
||||
}
|
||||
|
||||
public function getOrphanedEvents(Request $request = null): array
|
||||
public function getOrphanedEvents(?Request $request = null): array
|
||||
{
|
||||
if ($request) {
|
||||
return $this->orphanedEvents[spl_object_hash($request)] ?? [];
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ final class WrappedListener
|
|||
private $priority;
|
||||
private static $hasClassStub;
|
||||
|
||||
public function __construct($listener, ?string $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
|
||||
public function __construct($listener, ?string $name, Stopwatch $stopwatch, ?EventDispatcherInterface $dispatcher = null)
|
||||
{
|
||||
$this->listener = $listener;
|
||||
$this->optimizedListener = $listener instanceof \Closure ? $listener : (\is_callable($listener) ? \Closure::fromCallable($listener) : null);
|
||||
|
|
@ -49,7 +49,7 @@ final class WrappedListener
|
|||
$r = new \ReflectionFunction($listener);
|
||||
if (str_contains($r->name, '{closure}')) {
|
||||
$this->pretty = $this->name = 'closure';
|
||||
} elseif ($class = $r->getClosureScopeClass()) {
|
||||
} elseif ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
|
||||
$this->name = $class->name;
|
||||
$this->pretty = $this->name.'::'.$r->name;
|
||||
} else {
|
||||
|
|
@ -114,10 +114,12 @@ final class WrappedListener
|
|||
|
||||
$e = $this->stopwatch->start($this->name, 'event_listener');
|
||||
|
||||
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
|
||||
|
||||
if ($e->isStarted()) {
|
||||
$e->stop();
|
||||
try {
|
||||
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
|
||||
} finally {
|
||||
if ($e->isStarted()) {
|
||||
$e->stop();
|
||||
}
|
||||
}
|
||||
|
||||
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
|
||||
|
|
|
|||
|
|
@ -115,14 +115,18 @@ class RegisterListenersPass implements CompilerPassInterface
|
|||
], function ($matches) { return strtoupper($matches[0]); }, $event['event']);
|
||||
$event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
|
||||
|
||||
if (null !== ($class = $container->getDefinition($id)->getClass()) && ($r = $container->getReflectionClass($class, false)) && !$r->hasMethod($event['method']) && $r->hasMethod('__invoke')) {
|
||||
if (null !== ($class = $container->getDefinition($id)->getClass()) && ($r = $container->getReflectionClass($class, false)) && !$r->hasMethod($event['method'])) {
|
||||
if (!$r->hasMethod('__invoke')) {
|
||||
throw new InvalidArgumentException(sprintf('None of the "%s" or "__invoke" methods exist for the service "%s". Please define the "method" attribute on "%s" tags.', $event['method'], $id, $this->listenerTag));
|
||||
}
|
||||
|
||||
$event['method'] = '__invoke';
|
||||
}
|
||||
}
|
||||
|
||||
$dispatcherDefinition = $globalDispatcherDefinition;
|
||||
if (isset($event['dispatcher'])) {
|
||||
$dispatcherDefinition = $container->getDefinition($event['dispatcher']);
|
||||
$dispatcherDefinition = $container->findDefinition($event['dispatcher']);
|
||||
}
|
||||
|
||||
$dispatcherDefinition->addMethodCall('addListener', [$event['event'], [new ServiceClosureArgument(new Reference($id)), $event['method']], $priority]);
|
||||
|
|
@ -161,7 +165,7 @@ class RegisterListenersPass implements CompilerPassInterface
|
|||
continue;
|
||||
}
|
||||
|
||||
$dispatcherDefinitions[$attributes['dispatcher']] = $container->getDefinition($attributes['dispatcher']);
|
||||
$dispatcherDefinitions[$attributes['dispatcher']] = $container->findDefinition($attributes['dispatcher']);
|
||||
}
|
||||
|
||||
if (!$dispatcherDefinitions) {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class EventDispatcher implements EventDispatcherInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dispatch(object $event, string $eventName = null): object
|
||||
public function dispatch(object $event, ?string $eventName = null): object
|
||||
{
|
||||
$eventName = $eventName ?? \get_class($event);
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ class EventDispatcher implements EventDispatcherInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListeners(string $eventName = null)
|
||||
public function getListeners(?string $eventName = null)
|
||||
{
|
||||
if (null !== $eventName) {
|
||||
if (empty($this->listeners[$eventName])) {
|
||||
|
|
@ -120,7 +120,7 @@ class EventDispatcher implements EventDispatcherInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasListeners(string $eventName = null)
|
||||
public function hasListeners(?string $eventName = null)
|
||||
{
|
||||
if (null !== $eventName) {
|
||||
return !empty($this->listeners[$eventName]);
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ interface EventDispatcherInterface extends ContractsEventDispatcherInterface
|
|||
*
|
||||
* @return array<callable[]|callable>
|
||||
*/
|
||||
public function getListeners(string $eventName = null);
|
||||
public function getListeners(?string $eventName = null);
|
||||
|
||||
/**
|
||||
* Gets the listener priority for a specific event.
|
||||
|
|
@ -66,5 +66,5 @@ interface EventDispatcherInterface extends ContractsEventDispatcherInterface
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasListeners(string $eventName = null);
|
||||
public function hasListeners(?string $eventName = null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
|
|||
protected $arguments;
|
||||
|
||||
/**
|
||||
* Encapsulate an event with $subject and $args.
|
||||
* 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
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class ImmutableEventDispatcher implements EventDispatcherInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dispatch(object $event, string $eventName = null): object
|
||||
public function dispatch(object $event, ?string $eventName = null): object
|
||||
{
|
||||
return $this->dispatcher->dispatch($event, $eventName);
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ class ImmutableEventDispatcher implements EventDispatcherInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListeners(string $eventName = null)
|
||||
public function getListeners(?string $eventName = null)
|
||||
{
|
||||
return $this->dispatcher->getListeners($eventName);
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ class ImmutableEventDispatcher implements EventDispatcherInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasListeners(string $eventName = null)
|
||||
public function hasListeners(?string $eventName = null)
|
||||
{
|
||||
return $this->dispatcher->hasListeners($eventName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2004-2022 Fabien Potencier
|
||||
Copyright (c) 2004-present Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue