1. Go to this page and download the library: Download huangdijia/hyperf-trigger 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/ */
huangdijia / hyperf-trigger example snippets
namespace App\Trigger;
use Huangdijia\Trigger\Annotation\Trigger;
use Huangdijia\Trigger\Trigger\AbstractTrigger;
use MySQLReplication\Event\DTO\EventDTO;
/**
* single
* @Trigger(table="table" on="write", replication="default")
* or multi events by array
* @Trigger(table="table" on={"write", "update", "delete"}, replication="default")
* or multi events by string
* @Trigger(table="table" on="write,update,delete", replication="default")
* or all events
* @Trigger(table="table" on="*", replication="default")
*/
class SomeTableTrigger extends AbstractTrigger
{
public function onWrite(array $new)
{
var_dump($new);
}
public function onUpdate(array $old, array $new)
{
var_dump($old, $new);
}
public function onDelete(array $old)
{
var_dump($old);
}
}
namespace App\Subscriber;
use Huangdijia\Trigger\Annotation\Subscriber;
use Huangdijia\Trigger\Subscriber\AbstractEventSubscriber;
use MySQLReplication\Event\DTO\EventDTO;
/**
* @Subscriber(replication="default")
*/
class DemoSubscriber extends AbstractEventSubscriber
{
protected function allEvents(EventDTO $event): void
{
// some code
}
}
namespace App\Process;
use Huangdijia\Trigger\Process\ConsumeProcess;
use Hyperf\Process\Annotation\Process;
/**
* @Process
*/
class TriggerProcess extends ConsumeProcess
{
}