Skip to content

Commit 9b9811f

Browse files
author
Kurt Friars
committed
Make emitted events configurable
1 parent 838b5b8 commit 9b9811f

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

config/schema-events.php

+29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
use Plank\LaravelSchemaEvents\Events\TableChanged;
4+
use Plank\LaravelSchemaEvents\Events\TableCreated;
5+
use Plank\LaravelSchemaEvents\Events\TableDropped;
6+
use Plank\LaravelSchemaEvents\Events\TableRenamed;
37
use Plank\LaravelSchemaEvents\Listeners\MigrationRan;
48
use Plank\LaravelSchemaEvents\Listeners\MigrationsFinished;
59

@@ -25,6 +29,31 @@
2529
'finished' => MigrationsFinished::class,
2630
],
2731

32+
/*
33+
|--------------------------------------------------------------------------
34+
| Listeners
35+
|--------------------------------------------------------------------------
36+
|
37+
| `created`:
38+
| The event emitted when tables are created during migrations.
39+
|
40+
| `changed`:
41+
| The event emitted when tables are altered during migrations.
42+
|
43+
| `renamed`:
44+
| The event emitted when tables are renamed during migrations.
45+
|
46+
| `dropped`:
47+
| The event emitted when tables are dropped during migrations.
48+
|
49+
*/
50+
'events' => [
51+
'created' => TableCreated::class,
52+
'changed' => TableChanged::class,
53+
'renamed' => TableRenamed::class,
54+
'dropped' => TableDropped::class,
55+
],
56+
2857
/*
2958
|--------------------------------------------------------------------------
3059
| Commands

src/Concerns/ListensToSchemaEvents.php

+20-5
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,46 @@ public function create($table, Closure $callback)
3737
{
3838
$blueprint = $this->createBlueprint($table, $callback);
3939

40-
$this->events->push(TableCreated::from($this->connection, $blueprint));
40+
/** @var class-string<TableCreated> $event */
41+
$event = config()->get('schema-events.events.created');
42+
43+
$this->events->push($event::from($this->connection, $blueprint));
4144
}
4245

4346
public function drop($table)
4447
{
45-
$this->events->push(TableDropped::from($this->connection, $table));
48+
/** @var class-string<TableDropped> $event */
49+
$event = config()->get('schema-events.events.dropped');
50+
51+
$this->events->push($event::from($this->connection, $table));
4652
}
4753

4854
public function dropIfExists($table)
4955
{
5056
if ($this->hasTable($table)) {
51-
$this->events->push(TableDropped::from($this->connection, $table));
57+
/** @var class-string<TableDropped> $event */
58+
$event = config()->get('schema-events.events.dropped');
59+
60+
$this->events->push($event::from($this->connection, $table));
5261
}
5362
}
5463

5564
public function table($table, Closure $callback)
5665
{
5766
$blueprint = $this->createBlueprint($table, $callback);
5867

59-
$this->events->push(TableChanged::from($this->connection, $blueprint));
68+
/** @var class-string<TableChanged> $event */
69+
$event = config()->get('schema-events.events.changed');
70+
71+
$this->events->push($event::from($this->connection, $blueprint));
6072
}
6173

6274
public function rename($from, $to)
6375
{
64-
$this->events->push(TableRenamed::from($this->connection, $from, $to));
76+
/** @var class-string<TableCreated> $event */
77+
$event = config()->get('schema-events.events.renamed');
78+
79+
$this->events->push($event::from($this->connection, $from, $to));
6580
}
6681

6782
public function hasTable($table)

0 commit comments

Comments
 (0)