Merge pull request #23491 from nextcloud/backport/23481/stable20

[stable20] Add psalm types for the event dispatcher
This commit is contained in:
Morris Jobke 2020-10-16 09:32:47 +02:00 committed by GitHub
commit dd7c6d1947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 37 additions and 2 deletions

View File

@ -35,6 +35,9 @@ use OCP\EventDispatcher\IEventListener;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Util; use OCP\Util;
/**
* @template-implements IEventListener<\OC\Authentication\Events\LoginFailed>
*/
class LoginFailedListener implements IEventListener { class LoginFailedListener implements IEventListener {
/** @var IEventDispatcher */ /** @var IEventDispatcher */

View File

@ -35,6 +35,9 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener; use OCP\EventDispatcher\IEventListener;
use OCP\ILogger; use OCP\ILogger;
/**
* @template-implements IEventListener<\OC\Authentication\Events\ARemoteWipeEvent>
*/
class RemoteWipeActivityListener implements IEventListener { class RemoteWipeActivityListener implements IEventListener {
/** @var IActvityManager */ /** @var IActvityManager */

View File

@ -40,6 +40,9 @@ use OCP\Mail\IMailer;
use OCP\Mail\IMessage; use OCP\Mail\IMessage;
use function substr; use function substr;
/**
* @template-implements IEventListener<\OC\Authentication\Events\ARemoteWipeEvent>
*/
class RemoteWipeEmailListener implements IEventListener { class RemoteWipeEmailListener implements IEventListener {
/** @var IMailer */ /** @var IMailer */

View File

@ -35,6 +35,9 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener; use OCP\EventDispatcher\IEventListener;
use OCP\Notification\IManager as INotificationManager; use OCP\Notification\IManager as INotificationManager;
/**
* @template-implements IEventListener<\OC\Authentication\Events\ARemoteWipeEvent>
*/
class RemoteWipeNotificationsListener implements IEventListener { class RemoteWipeNotificationsListener implements IEventListener {
/** @var INotificationManager */ /** @var INotificationManager */

View File

@ -31,6 +31,9 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener; use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\UserDeletedEvent; use OCP\User\Events\UserDeletedEvent;
/**
* @template-implements IEventListener<\OCP\User\Events\UserDeletedEvent>
*/
class UserDeletedStoreCleanupListener implements IEventListener { class UserDeletedStoreCleanupListener implements IEventListener {
/** @var Registry */ /** @var Registry */

View File

@ -33,6 +33,9 @@ use OCP\ILogger;
use OCP\User\Events\UserDeletedEvent; use OCP\User\Events\UserDeletedEvent;
use Throwable; use Throwable;
/**
* @template-implements IEventListener<\OCP\User\Events\UserDeletedEvent>
*/
class UserDeletedTokenCleanupListener implements IEventListener { class UserDeletedTokenCleanupListener implements IEventListener {
/** @var Manager */ /** @var Manager */

View File

@ -31,6 +31,9 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener; use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\PostLoginEvent; use OCP\User\Events\PostLoginEvent;
/**
* @template-implements IEventListener<\OCP\User\Events\PostLoginEvent>
*/
class UserLoggedInListener implements IEventListener { class UserLoggedInListener implements IEventListener {
/** @var Manager */ /** @var Manager */

View File

@ -113,10 +113,11 @@ interface IRegistrationContext {
* *
* This is equivalent to calling IEventDispatcher::addServiceListener * This is equivalent to calling IEventDispatcher::addServiceListener
* *
* @template T of \OCP\EventDispatcher\Event
* @param string $event preferably the fully-qualified class name of the Event sub class to listen for * @param string $event preferably the fully-qualified class name of the Event sub class to listen for
* @psalm-param string|class-string<\OCP\EventDispatcher\Event> $event preferably the fully-qualified class name of the Event sub class to listen for * @psalm-param string|class-string<T> $event preferably the fully-qualified class name of the Event sub class to listen for
* @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container * @param string $listener fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
* @psalm-param class-string<\OCP\EventDispatcher\IEventListener> $listener fully qualified class name that can be built by the DI container * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $listener fully qualified class name that can be built by the DI container
* @param int $priority * @param int $priority
* *
* @see IEventDispatcher::addServiceListener() * @see IEventDispatcher::addServiceListener()

View File

@ -35,7 +35,9 @@ namespace OCP\EventDispatcher;
interface IEventDispatcher { interface IEventDispatcher {
/** /**
* @template T of \OCP\EventDispatcher\Event
* @param string $eventName preferably the fully-qualified class name of the Event sub class * @param string $eventName preferably the fully-qualified class name of the Event sub class
* @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class
* @param callable $listener the object that is invoked when a matching event is dispatched * @param callable $listener the object that is invoked when a matching event is dispatched
* @param int $priority * @param int $priority
* *
@ -44,7 +46,9 @@ interface IEventDispatcher {
public function addListener(string $eventName, callable $listener, int $priority = 0): void; public function addListener(string $eventName, callable $listener, int $priority = 0): void;
/** /**
* @template T of \OCP\EventDispatcher\Event
* @param string $eventName preferably the fully-qualified class name of the Event sub class * @param string $eventName preferably the fully-qualified class name of the Event sub class
* @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class
* @param callable $listener the object that is invoked when a matching event is dispatched * @param callable $listener the object that is invoked when a matching event is dispatched
* *
* @since 19.0.0 * @since 19.0.0
@ -52,8 +56,11 @@ interface IEventDispatcher {
public function removeListener(string $eventName, callable $listener): void; public function removeListener(string $eventName, callable $listener): void;
/** /**
* @template T of \OCP\EventDispatcher\Event
* @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for * @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for
* @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class to listen for
* @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container * @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
* @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $className fully qualified class name that can be built by the DI container
* @param int $priority * @param int $priority
* *
* @since 17.0.0 * @since 17.0.0
@ -61,8 +68,11 @@ interface IEventDispatcher {
public function addServiceListener(string $eventName, string $className, int $priority = 0): void; public function addServiceListener(string $eventName, string $className, int $priority = 0): void;
/** /**
* @template T of \OCP\EventDispatcher\Event
* @param string $eventName * @param string $eventName
* @psalm-param string|class-string<T> $eventName
* @param Event $event * @param Event $event
* @psalm-param T $event
* *
* @since 17.0.0 * @since 17.0.0
*/ */

View File

@ -28,11 +28,14 @@ namespace OCP\EventDispatcher;
/** /**
* @since 17.0.0 * @since 17.0.0
*
* @template T of Event
*/ */
interface IEventListener { interface IEventListener {
/** /**
* @param Event $event * @param Event $event
* @psalm-param T $event
* *
* @since 17.0.0 * @since 17.0.0
*/ */