Skip to content

Commit 3a43e9d

Browse files
author
hdj
committed
fix
1 parent e920980 commit 3a43e9d

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/Manager.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Manager
1313
protected $config;
1414
/**
1515
* Replications
16-
* @var array
16+
* @var Trigger[]
1717
*/
1818
protected $replications;
1919

@@ -33,21 +33,23 @@ public function replication(?string $name = null)
3333
$name = $name ?? $this->config['default'] ?? 'default';
3434

3535
if (!isset($this->replications[$name])) {
36-
throw_if(
37-
!isset($this->config['replications'][$name]),
38-
new InvalidArgumentException("Config 'trigger.replications.{$name}' is undefined", 1)
39-
);
36+
if (!isset($this->config['replications'][$name])) {
37+
new InvalidArgumentException("Config 'trigger.replications.{$name}' is undefined", 1);
38+
}
4039

40+
// load config
4141
$config = $this->config['replications'][$name];
4242

43-
$this->replications[$name] = tap(new Trigger($name, $config), function ($trigger) {
44-
/** @var Trigger $trigger */
45-
$trigger->loadRoutes();
43+
/** @var Trigger[] */
44+
$this->replications[$name] = new Trigger($name, $config);
45+
46+
// load routes
47+
$this->replications[$name]->loadRoutes();
4648

47-
if ($trigger->getConfig('detect')) {
48-
$trigger->detectDatabasesAndTables();
49-
}
50-
});
49+
// auto detect
50+
if ($this->replications[$name]->getConfig('detect')) {
51+
$this->replications[$name]->detectDatabasesAndTables();
52+
}
5153
}
5254

5355
return $this->replications[$name];

src/Trigger.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Huangdijia\Trigger;
44

5-
use Illuminate\Container\Container;
65
use Exception;
76
use Huangdijia\Trigger\EventSubscriber;
7+
use Illuminate\Container\Container;
88
use Illuminate\Contracts\Queue\ShouldQueue;
99
use Illuminate\Support\Arr;
1010
use Illuminate\Support\Carbon;
@@ -18,7 +18,14 @@
1818

1919
class Trigger
2020
{
21+
/**
22+
* @var string
23+
*/
2124
protected $name;
25+
26+
/**
27+
* @var array
28+
*/
2229
protected $config;
2330

2431
/**

0 commit comments

Comments
 (0)