1. Go to this page and download the library: Download scones/nexus library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
scones / nexus example snippets
use Psr\EventDispatcher\MessageInterface;
use Nexus\StandardListenerProvider;
use Nexus\SynchronousNotifier;
class SomeMessage implements MessageInterface
{
}
class SomeOtherMessage implements MessageInterface
{
}
$provider = new StandardListenerProvider();
$notifier = new SynchronousNotifier($provider);
$provider->addListener(function (SomeMessage $someMessage) {
echo "some cool message reaction code goes here\n";
});
$provider->addListener(function (SomeMessage $someMessage) {
echo "this message seems worth logging!\n";
});
$provider->addListener(function (SomeOtherMessage $someOtherMessage) {
echo "oh, the other message was dispatched!\n";
});
$testMessage = new SomeMessage();
$notifier->notify($testMessage);
use Nexus\StandardListenerProvider;
use Nexus\SynchronousProcessor;
use Psr\EventDispatcher\TaskInterface;
class SomeTask implements TaskInterface
{
private $accessCounter = 0;
public function increaseCounter(): void
{
$this->accessCounter++;
}
public function getCounter(): int
{
return $this->accessCounter;
}
}
class SomeOtherTask implements TaskInterface
{
}
$provider = new StandardListenerProvider();
$processor = new SynchronousProcessor($provider);
$provider->addListener(function (SomeTask $someTask) {
echo "some task working!\n";
$someTask->increaseCounter();
return $someTask;
});
$provider->addListener(function (SomeTask $someTask) {
echo "some task working again!\n";
$someTask->increaseCounter();
$someTask->increaseCounter();
return $someTask;
});
$provider->addListener(function (SomeOtherTask $someOtherTask) {
echo "the other Task!";
return $someOtherTask;
});
$testTask = new SomeTask();
$testTaskResult = $processor->process($testTask);
echo "task result was: {$testTaskResult->getCounter()}\n";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.