diff --git a/composer.json b/composer.json index 4f6012f0e..10e321021 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": "^8.0", "ext-openssl": "*", - "league/event": "^2.2", + "league/event": "^3.0", "league/uri": "^6.7 || ^7.0", "lcobucci/jwt": "^4.3 || ^5.0", "psr/http-message": "^1.0.1 || ^2.0", diff --git a/src/AuthorizationServer.php b/src/AuthorizationServer.php index fbdf99228..9b6629478 100644 --- a/src/AuthorizationServer.php +++ b/src/AuthorizationServer.php @@ -14,8 +14,8 @@ use DateInterval; use Defuse\Crypto\Key; -use League\Event\EmitterAwareInterface; -use League\Event\EmitterAwareTrait; +use League\OAuth2\Server\EventEmitting\EmitterAwareInterface; +use League\OAuth2\Server\EventEmitting\EmitterAwarePolyfill; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Grant\GrantTypeInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; @@ -30,7 +30,7 @@ class AuthorizationServer implements EmitterAwareInterface { - use EmitterAwareTrait; + use EmitterAwarePolyfill; /** * @var GrantTypeInterface[] diff --git a/src/EventEmitting/AbstractEvent.php b/src/EventEmitting/AbstractEvent.php new file mode 100644 index 000000000..80c229aaa --- /dev/null +++ b/src/EventEmitting/AbstractEvent.php @@ -0,0 +1,44 @@ +name; + } + + /** + * Backwards compatibility method + * + * @deprecated use eventName instead + */ + public function getName(): string + { + return $this->name; + } + + public function isPropagationStopped(): bool + { + return $this->propagationStopped; + } + + public function stopPropagation(): self + { + $this->propagationStopped = true; + + return $this; + } +} diff --git a/src/EventEmitting/EmitterAwareInterface.php b/src/EventEmitting/EmitterAwareInterface.php new file mode 100644 index 000000000..206428a1e --- /dev/null +++ b/src/EventEmitting/EmitterAwareInterface.php @@ -0,0 +1,12 @@ +emitter ?? new EventEmitter(); + } + + public function setEmitter(EventEmitter $emitter): self + { + $this->emitter = $emitter; + + return $this; + } + + public function getEventDispatcher(): EventDispatcherInterface + { + return $this->getEmitter(); + } + + public function getListenerRegistry(): ListenerRegistry + { + return $this->getEmitter(); + } +} diff --git a/src/EventEmitting/EventEmitter.php b/src/EventEmitting/EventEmitter.php new file mode 100644 index 000000000..25c15c5ba --- /dev/null +++ b/src/EventEmitting/EventEmitter.php @@ -0,0 +1,23 @@ +subscribeTo($event, $listener, $priority); + + return $this; + } + + public function emit(object $event): object + { + return $this->dispatch($event); + } +} diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index 060bbbcea..340586f44 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -19,7 +19,6 @@ use DomainException; use Error; use Exception; -use League\Event\EmitterAwareTrait; use League\OAuth2\Server\CryptKeyInterface; use League\OAuth2\Server\CryptTrait; use League\OAuth2\Server\Entities\AccessTokenEntityInterface; @@ -27,6 +26,7 @@ use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; +use League\OAuth2\Server\EventEmitting\EmitterAwarePolyfill; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException; use League\OAuth2\Server\RedirectUriValidators\RedirectUriValidator; @@ -60,7 +60,7 @@ */ abstract class AbstractGrant implements GrantTypeInterface { - use EmitterAwareTrait; + use EmitterAwarePolyfill; use CryptTrait; protected const SCOPE_DELIMITER_STRING = ' '; diff --git a/src/Grant/GrantTypeInterface.php b/src/Grant/GrantTypeInterface.php index a2fda3734..3f08565a6 100644 --- a/src/Grant/GrantTypeInterface.php +++ b/src/Grant/GrantTypeInterface.php @@ -16,8 +16,8 @@ use DateInterval; use Defuse\Crypto\Key; -use League\Event\EmitterAwareInterface; use League\OAuth2\Server\CryptKeyInterface; +use League\OAuth2\Server\EventEmitting\EmitterAwareInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; diff --git a/src/RequestEvent.php b/src/RequestEvent.php index b0ae00767..2a1fb0915 100644 --- a/src/RequestEvent.php +++ b/src/RequestEvent.php @@ -12,10 +12,10 @@ namespace League\OAuth2\Server; -use League\Event\Event; +use League\OAuth2\Server\EventEmitting\AbstractEvent; use Psr\Http\Message\ServerRequestInterface; -class RequestEvent extends Event +class RequestEvent extends AbstractEvent { public const CLIENT_AUTHENTICATION_FAILED = 'client.authentication.failed'; public const USER_AUTHENTICATION_FAILED = 'user.authentication.failed'; diff --git a/tests/Stubs/GrantType.php b/tests/Stubs/GrantType.php index bd2f95f77..d81c0c271 100644 --- a/tests/Stubs/GrantType.php +++ b/tests/Stubs/GrantType.php @@ -6,8 +6,8 @@ use DateInterval; use Defuse\Crypto\Key; -use League\Event\EmitterInterface; use League\OAuth2\Server\CryptKeyInterface; +use League\OAuth2\Server\EventEmitting\EventEmitter; use League\OAuth2\Server\Grant\GrantTypeInterface; use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; @@ -20,16 +20,16 @@ final class GrantType implements GrantTypeInterface { - private ?EmitterInterface $emitter; + private EventEmitter $emitter; - public function setEmitter(EmitterInterface $emitter = null): self + public function setEmitter(EventEmitter $emitter = null): self { $this->emitter = $emitter; return $this; } - public function getEmitter(): ?EmitterInterface + public function getEmitter(): EventEmitter { return $this->emitter; }