scones /
nexus
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | require __DIR__ . '/../vendor/autoload.php'; |
||
| 6 | |||
| 7 | use Nexus\StandardListenerProvider; |
||
| 8 | use Nexus\SynchronousProcessor; |
||
| 9 | use Psr\EventDispatcher\TaskInterface; |
||
| 10 | |||
| 11 | class SomeTask implements TaskInterface |
||
| 12 | { |
||
| 13 | private $accessCounter = 0; |
||
| 14 | |||
| 15 | public function increaseCounter(): void |
||
| 16 | { |
||
| 17 | $this->accessCounter++; |
||
| 18 | } |
||
| 19 | |||
| 20 | public function getCounter(): int |
||
| 21 | { |
||
| 22 | return $this->accessCounter; |
||
| 23 | } |
||
| 24 | } |
||
| 25 | |||
| 26 | class SomeOtherTask implements TaskInterface |
||
| 27 | { |
||
| 28 | } |
||
| 29 | |||
| 30 | $provider = new StandardListenerProvider(); |
||
| 31 | $processor = new SynchronousProcessor($provider); |
||
| 32 | |||
| 33 | $provider->addListener(function (SomeTask $someTask) { |
||
| 34 | echo "some task working!\n"; |
||
| 35 | $someTask->increaseCounter(); |
||
| 36 | return $someTask; |
||
| 37 | }); |
||
| 38 | $provider->addListener(function (SomeTask $someTask) { |
||
| 39 | echo "some task working again!\n"; |
||
| 40 | $someTask->increaseCounter(); |
||
| 41 | $someTask->increaseCounter(); |
||
| 42 | return $someTask; |
||
| 43 | }); |
||
| 44 | $provider->addListener(function (SomeOtherTask $someOtherTask) { |
||
| 45 | echo "the other Task!"; |
||
| 46 | return $someOtherTask; |
||
| 47 | }); |
||
| 48 | |||
| 49 | $testTask = new SomeTask(); |
||
| 50 | $testTaskResult = $processor->process($testTask); |
||
| 51 | |||
| 52 | echo "task result was: {$testTaskResult->getCounter()}\n"; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 53 |