PHP code example of switon / event
1. Go to this page and download the library: Download switon/event 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/ */
switon / event example snippets
use App\Event\UserCreated;
use Psr\EventDispatcher\EventDispatcherInterface;
use Switon\Core\Attribute\Autowired;
use Switon\Core\Attribute\EventListener;
class UserService
{
#[Autowired] protected EventDispatcherInterface $events;
public function register(string $email): void
{
$this->events->dispatch(new UserCreated(123, $email));
}
}
class UserListener
{
#[EventListener]
public function onUserCreated(UserCreated $event): void
{
// react to the event
}
}