phpooya / events
An event base system.
dev-master
2019-08-15 17:48 UTC
Requires (Dev)
- codeception/codeception: 3.0.3
This package is not auto-updated.
Last update: 2024-11-16 16:47:35 UTC
README
New level architecture to keep your project designed-pattern.
Installation:
composer require phpooya/events
How to use:
add EventTrait
to your class as in example and use $this->trigger()
inside of your code:
<?php
use phpooya\events\EventTrait;
use phpooya\events\EventData;
class UserModel
{
use EventTrait;
public $name;
public $email;
public $password;
public function find() : array
{
$eventData = new EventData($this);
$this->trigger($eventData, "before");
$returnData = []; //retrieve data from DB...
$this->trigger($eventData, "after");
return $returnData;
}
public function save() : bool
{
$eventData = new EventData($this);
$this->trigger($eventData, "before");
$returnData = true; //save data in DB...
$this->trigger($eventData, "after");
return $returnData;
}
}
UserModel::on('before.find', function($data){ /* do something you want... */ });
UserModel::on('after.find', function($data){ $data->target->password = "********"; });
UserModel::on('after.save', function($data){ /* add log for error... */ });