1. Go to this page and download the library: Download phpgears/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/ */
phpgears / event example snippets
use Gears\Event\AbstractEvent;
class CreateUserEvent extends AbstractEvent
{
public static function fromPersonalData(
string $name,
string lastname,
\DateTimeImmutable $birthDate
): self {
return static::occurred([
'name' => $name,
'lastname' => $lastname,
'birthDate' => $birthDate->format('U'),
]);
}
}
use Gears\Event\AbstractEvent;
class CreateUserEvent extends AbstractEmptyEvent
{
public static function instance(): self {
return self::occurred();
}
}
class CreateUserEventHandler extends AbstractEventHandler
{
protected function getSupportedEventType(): string
{
return CreateUserEvent::class;
}
protected function handleEvent(Event $event): void
{
/* @var CreateUserEvent $event */
$user = new User(
$event->getName(),
$event->getLastname(),
$event->getBirthDate()
);
[...]
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.