mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Merge pull request #1501 from Reasno/framework
feat: bridge symfony events to hyperf event dispatcher.
This commit is contained in:
commit
b28e5435e3
@ -1,5 +1,9 @@
|
||||
# v1.1.24 - TBD
|
||||
|
||||
## Added
|
||||
|
||||
- [#1501](https://github.com/hyperf/hyperf/pull/1501) Bridged Symfony command events to Hyperf event dispatcher.
|
||||
|
||||
## Fixed
|
||||
|
||||
- [#1494](https://github.com/hyperf/hyperf/pull/1494) Ignore `@mixin` annotation in redis component
|
||||
|
@ -40,6 +40,11 @@ class ApplicationFactory
|
||||
|
||||
$commands = array_unique(array_merge($commands, $annotationCommands));
|
||||
$application = new Application();
|
||||
|
||||
if (isset($eventDispatcher)) {
|
||||
$application->setDispatcher(new SymfonyEventDispatcher($eventDispatcher));
|
||||
}
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$application->add($container->get($command));
|
||||
}
|
||||
|
17
src/framework/src/Exception/NotImplementedException.php
Normal file
17
src/framework/src/Exception/NotImplementedException.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://doc.hyperf.io
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Hyperf\Framework\Exception;
|
||||
|
||||
class NotImplementedException extends \RuntimeException
|
||||
{
|
||||
}
|
75
src/framework/src/SymfonyEventDispatcher.php
Normal file
75
src/framework/src/SymfonyEventDispatcher.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://doc.hyperf.io
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Hyperf\Framework;
|
||||
|
||||
use Hyperf\Framework\Exception\NotImplementedException;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface as PsrDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* Class SymfonyEventDispatcher.
|
||||
* @internal
|
||||
*/
|
||||
class SymfonyEventDispatcher implements SymfonyDispatcherInterface
|
||||
{
|
||||
/**
|
||||
* @var PsrDispatcherInterface
|
||||
*/
|
||||
private $psrDispatcher;
|
||||
|
||||
public function __construct(PsrDispatcherInterface $psrDispatcher)
|
||||
{
|
||||
$this->psrDispatcher = $psrDispatcher;
|
||||
}
|
||||
|
||||
public function addListener($eventName, $listener, $priority = 0)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public function addSubscriber(EventSubscriberInterface $subscriber)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public function removeListener($eventName, $listener)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public function removeSubscriber(EventSubscriberInterface $subscriber)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public function getListeners($eventName = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public function dispatch($event)
|
||||
{
|
||||
$this->psrDispatcher->dispatch($event);
|
||||
}
|
||||
|
||||
public function getListenerPriority($eventName, $listener)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public function hasListeners($eventName = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user