huangdijia/hyperf-trigger

This package is abandoned and no longer maintained. No replacement package was suggested.

MySQL Trigger for hyperf.

0.1.2 2020-12-30 09:55 UTC

This package is auto-updated.

Last update: 2021-02-25 01:26:46 UTC


README

Latest Stable Version Total Downloads GitHub license

MySQL trigger component for hyperf

⚠️ Move to friendsofhyperf/trigger

Installation

  • Request
composer require huangdijia/hyperf-trigger
  • Publish
php bin/hyperf.php vendor:publish huangdijia/hyperf-trigger

Costom Trigger

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);
    }
}

Costom Subscriber

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
    }
}

Setup Process

  • Default
namespace App\Process;

use Huangdijia\Trigger\Process\ConsumeProcess;
use Hyperf\Process\Annotation\Process;

/**
 * @Process
 */
class TriggerProcess extends ConsumeProcess
{
}
  • Custom replication
namespace App\Process;

use Huangdijia\Trigger\Process\ConsumeProcess;
use Hyperf\Process\Annotation\Process;

/**
 * @Process
 */
class CustomProcess extends ConsumeProcess
{
    protected $replication = 'custom_replication';
}