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
Requires
- hyperf/di: ^2.0
- hyperf/event: ^2.0
- hyperf/process: ^2.0
- hyperf/utils: ^2.0
- krowinski/php-mysql-replication: ^6.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.04
- phpstan/phpstan: ^0.12
- swoole/ide-helper: ^4.5
README
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'; }