-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Micro-PHP/release-1.1
v1.1 release
- Loading branch information
Showing
10 changed files
with
294 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Micro\Plugin\EventEmitter\Business\Factory; | ||
|
||
use Micro\Component\EventEmitter\EventEmitterInterface; | ||
use Micro\Component\EventEmitter\EventEmitterFactory as BaseEventEmitterFactory; | ||
use Micro\Plugin\EventEmitter\Business\Provider\ProviderFactoryInterface; | ||
|
||
class EventEmitterFactory extends BaseEventEmitterFactory | ||
{ | ||
/** | ||
* @param ProviderFactoryInterface $providerFactoryInterface | ||
*/ | ||
public function __construct( | ||
private readonly ProviderFactoryInterface $providerFactoryInterface | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function create(): EventEmitterInterface | ||
{ | ||
$emitter = parent::create(); | ||
|
||
$emitter->addListenerProvider( | ||
$this->providerFactoryInterface->create() | ||
); | ||
|
||
return $emitter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Micro\Plugin\EventEmitter\Business\Locator; | ||
|
||
use Micro\Component\EventEmitter\EventListenerInterface; | ||
use Micro\Plugin\Locator\Facade\LocatorFacadeInterface; | ||
|
||
class EventListenerClassLocator implements EventListenerClassLocatorInterface | ||
{ | ||
/** | ||
* @param LocatorFacadeInterface $locatorFacade | ||
*/ | ||
public function __construct( | ||
private readonly LocatorFacadeInterface $locatorFacade | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function lookupListenerClasses(): iterable | ||
{ | ||
$listenerClassCollection = []; | ||
|
||
foreach ($this->locatorFacade->lookup(EventListenerInterface::class) as $listenerClass) { | ||
$listenerClassCollection[] = $listenerClass; | ||
} | ||
|
||
return $listenerClassCollection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Micro\Plugin\EventEmitter\Business\Locator; | ||
|
||
use Micro\Plugin\Locator\Facade\LocatorFacadeInterface; | ||
|
||
class EventListenerClassLocatorFactory implements EventListenerClassLocatorFactoryInterface | ||
{ | ||
/** | ||
* @param LocatorFacadeInterface $locatorFacade | ||
*/ | ||
public function __construct( | ||
private readonly LocatorFacadeInterface $locatorFacade | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function create(): EventListenerClassLocatorInterface | ||
{ | ||
return new EventListenerClassLocator( | ||
$this->locatorFacade, | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Business/Locator/EventListenerClassLocatorFactoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Micro\Plugin\EventEmitter\Business\Locator; | ||
|
||
interface EventListenerClassLocatorFactoryInterface | ||
{ | ||
/** | ||
* @return EventListenerClassLocatorInterface | ||
*/ | ||
public function create(): EventListenerClassLocatorInterface; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Business/Locator/EventListenerClassLocatorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Micro\Plugin\EventEmitter\Business\Locator; | ||
|
||
use Micro\Component\EventEmitter\EventListenerInterface; | ||
|
||
interface EventListenerClassLocatorInterface | ||
{ | ||
/** | ||
* @return iterable<class-string<EventListenerInterface>> | ||
*/ | ||
public function lookupListenerClasses(): iterable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Micro\Plugin\EventEmitter\Business\Provider; | ||
|
||
use Micro\Component\DependencyInjection\Autowire\AutowireHelperInterface; | ||
use Micro\Component\EventEmitter\EventInterface; | ||
use Micro\Component\EventEmitter\ListenerProviderInterface; | ||
|
||
class ApplicationListenerProvider implements ListenerProviderInterface | ||
{ | ||
/** | ||
* @param AutowireHelperInterface $autowireHelper | ||
* @param iterable $eventListenersClasses | ||
*/ | ||
public function __construct( | ||
private readonly AutowireHelperInterface $autowireHelper, | ||
private readonly iterable $eventListenersClasses, | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getListenersForEvent(EventInterface $event): iterable | ||
{ | ||
foreach ($this->getEventListeners() as $listenerClass) { | ||
if(!$listenerClass::supports($event)) { | ||
continue; | ||
} | ||
|
||
$callback = $this->autowireHelper->autowire($listenerClass); | ||
|
||
yield $callback(); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return $this->getName() ?? get_class($this); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'events.listener_provider.default'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getEventListeners(): iterable | ||
{ | ||
return $this->eventListenersClasses; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Micro\Plugin\EventEmitter\Business\Provider; | ||
|
||
use Micro\Component\DependencyInjection\Autowire\AutowireHelperFactoryInterface; | ||
use Micro\Component\DependencyInjection\Autowire\AutowireHelperInterface; | ||
use Micro\Component\EventEmitter\EventListenerInterface; | ||
use Micro\Component\EventEmitter\ListenerProviderInterface; | ||
use Micro\Plugin\EventEmitter\Business\Locator\EventListenerClassLocatorFactoryInterface; | ||
|
||
class ProviderFactory implements ProviderFactoryInterface | ||
{ | ||
/** | ||
* @param AutowireHelperInterface $autowireHelper | ||
* @param EventListenerClassLocatorFactoryInterface $eventListenerClassLocatorFactory | ||
*/ | ||
public function __construct( | ||
private readonly AutowireHelperInterface $autowireHelper, | ||
private readonly EventListenerClassLocatorFactoryInterface $eventListenerClassLocatorFactory | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
*{@inheritDoc} | ||
*/ | ||
public function create(): ListenerProviderInterface | ||
{ | ||
$listeners = $this->eventListenerClassLocatorFactory | ||
->create() | ||
->lookupListenerClasses(); | ||
|
||
return $this->createProvider($listeners); | ||
} | ||
|
||
/** | ||
* @param iterable<class-string<EventListenerInterface>> $listeners | ||
* | ||
* @return ListenerProviderInterface | ||
*/ | ||
protected function createProvider(iterable $listeners): ListenerProviderInterface | ||
{ | ||
return new ApplicationListenerProvider( | ||
$this->autowireHelper, | ||
$listeners | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Micro\Plugin\EventEmitter\Business\Provider; | ||
|
||
use Micro\Component\EventEmitter\ListenerProviderInterface; | ||
|
||
interface ProviderFactoryInterface | ||
{ | ||
/** | ||
* @return ListenerProviderInterface | ||
*/ | ||
public function create(): ListenerProviderInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters