Skip to content

Joker-desire/trigger

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trigger

Latest Stable Version Total Downloads License

MySQL trigger component for Hyperf, Based on a great work of creators:krowinski/php-mysql-replication

Installation

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

Add listener

// config/autoload/listeners.php

return [
    FriendsOfHyperf\Trigger\Listener\BindTriggerProcessesListener::class => PHP_INT_MAX,
];

Define a trigger

namespace App\Trigger;

use FriendsOfHyperf\Trigger\Annotation\Trigger;
use FriendsOfHyperf\Trigger\Trigger\AbstractTrigger;
use MySQLReplication\Event\DTO\EventDTO;

#[Trigger(table:"table", events:"*", connection:"default")]
class FooTrigger 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);
    }
}

Define a subscriber

namespace App\Subscriber;

use FriendsOfHyperf\Trigger\Annotation\Subscriber;
use FriendsOfHyperf\Trigger\Subscriber\AbstractSubscriber;
use MySQLReplication\Event\DTO\EventDTO;

#[Subscriber(connection:"default")]
class BarSubscriber extends AbstractSubscriber
{
    protected function allEvents(EventDTO $event): void
    {
        // some code
    }
}

Contact

License

MIT

About

[READ-ONLY]MySQL Trigger for hyperf.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%