1. Go to this page and download the library: Download alexpts/php-simple-events 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/ */
alexpts / php-simple-events example snippets
$emitter = new \PTS\Events\EventEmitter;
$emitter->on('user.created', function (User $user) use ($logger) {
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
});
$filters = new \PTS\Events\Filters;
$filters->on('post:title', 'trim');
$title = $filters->filter('post:title', ' Raw title '); // `Raw title`
use PTS\Events\Bus\EventBusTrait;
class Service {
use EventBusTrait;
public function getPost()
{
$post = ...;
// you can to modify $post via filter/event
$post = $this->filter('getPost', $post); // from EventBusTrait
return $post;
}
}
use PTS\Events\Filter\FilterEmitter;
use PTS\Events\EventEmitter;
class Request extend FilterEmitter { // extend EventEmitter
public function parseHeader()
{
$rawHttpRequest = '...';
$headers = $this->filter('parseHeader', $rawHttpRequest);
return $headers;
}
}
$request = new Request;
$parseHeader = new ParserHeader;
$request->on('parseHeader', [$parseHeader, 'parse']);
$headers = $request->parseHeader();
use PTS\Events\Filter\FilterEmitterTrait;
use PTS\Events\EventEmitterTrait;
class Request
use FilterEmitterTrait;
public function parseHeader()
{
$rawHttpRequest = '...';
$headers = $this->filter('parseHeader', $rawHttpRequest);
return $headers;
}
}
$request = new Request;
$parseHeader = new ParserHeader;
$request->on('parseHeader', [$parseHeader, 'parse']);
$headers = $request->parseHeader();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.