From c1df4676012e572c7af36f5afa0ad4e9eef39d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 14 Aug 2019 17:15:47 +0200 Subject: [PATCH 1/6] [1.7.0] Add Events system (#93) * Add TenantManagerEvents * Apply fixes from StyleCI * Fix typos, add tests * end() events --- src/Traits/BootstrapsTenancy.php | 10 +++++ src/Traits/TenantManagerEvents.php | 70 ++++++++++++++++++++++++++++++ tests/TenantManagerTest.php | 69 +++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 src/Traits/TenantManagerEvents.php diff --git a/src/Traits/BootstrapsTenancy.php b/src/Traits/BootstrapsTenancy.php index 5f2b74d3..cbfd9465 100644 --- a/src/Traits/BootstrapsTenancy.php +++ b/src/Traits/BootstrapsTenancy.php @@ -9,6 +9,8 @@ use Stancl\Tenancy\Exceptions\PhpRedisNotInstalledException; trait BootstrapsTenancy { + use TenantManagerEvents; + public $originalSettings = []; /** * Was tenancy initialized/bootstrapped? @@ -19,6 +21,10 @@ trait BootstrapsTenancy public function bootstrap() { + array_map(function ($listener) { + $listener($this); + }, $this->listeners['bootstrapping']); + $this->initialized = true; $this->switchDatabaseConnection(); @@ -27,6 +33,10 @@ trait BootstrapsTenancy } $this->tagCache(); $this->suffixFilesystemRootPaths(); + + array_map(function ($listener) { + $listener($this); + }, $this->listeners['bootstrapped']); } public function end() diff --git a/src/Traits/TenantManagerEvents.php b/src/Traits/TenantManagerEvents.php new file mode 100644 index 00000000..c54b322b --- /dev/null +++ b/src/Traits/TenantManagerEvents.php @@ -0,0 +1,70 @@ + [], + 'bootstrapped' => [], + 'ending' => [], + 'ended' => [], + ]; + + /** + * Register a listener that will be executed before tenancy is bootstrapped. + * + * @param callable $callback + * @return self + */ + public function bootstrapping(callable $callback) + { + $this->listeners['bootstrapping'][] = $callback; + + return $this; + } + + /** + * Register a listener that will be executed after tenancy is bootstrapped. + * + * @param callable $callback + * @return self + */ + public function bootstrapped(callable $callback) + { + $this->listeners['bootstrapped'][] = $callback; + + return $this; + } + + /** + * Register a listener that will be executed before tenancy is ended. + * + * @param callable $callback + * @return self + */ + public function ending(callable $callback) + { + $this->listeners['ending'][] = $callback; + + return $this; + } + + /** + * Register a listener that will be executed after tenancy is ended. + * + * @param callable $callback + * @return self + */ + public function ended(callable $callback) + { + $this->listeners['ended'][] = $callback; + + return $this; + } +} diff --git a/tests/TenantManagerTest.php b/tests/TenantManagerTest.php index 453730ea..faa2da3d 100644 --- a/tests/TenantManagerTest.php +++ b/tests/TenantManagerTest.php @@ -2,6 +2,7 @@ namespace Stancl\Tenancy\Tests; +use Tenancy; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Stancl\Tenancy\Exceptions\CannotChangeUuidOrDomainException; @@ -241,4 +242,72 @@ class TenantManagerTest extends TestCase $this->expectException(CannotChangeUuidOrDomainException::class); tenant()->put(['uuid' => 'foo']); } + + /** @test */ + public function bootstrapping_event_works() + { + $uuid = tenant()->create('foo.localhost')['uuid']; + + Tenancy::bootstrapping(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + $this->assertSame(null, config('tenancy.foo')); + tenancy()->init('foo.localhost'); + $this->assertSame('bar', config('tenancy.foo')); + } + + /** @test */ + public function bootstrapped_event_works() + { + $uuid = tenant()->create('foo.localhost')['uuid']; + + Tenancy::bootstrapped(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + $this->assertSame(null, config('tenancy.foo')); + tenancy()->init('foo.localhost'); + $this->assertSame('bar', config('tenancy.foo')); + } + + /** @test */ + public function ending_event_works() + { + $uuid = tenant()->create('foo.localhost')['uuid']; + + Tenancy::ending(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + $this->assertSame(null, config('tenancy.foo')); + tenancy()->init('foo.localhost'); + $this->assertSame(null, config('tenancy.foo')); + tenancy()->end(); + $this->assertSame('bar', config('tenancy.foo')); + } + + /** @test */ + public function ended_event_works() + { + $uuid = tenant()->create('foo.localhost')['uuid']; + + Tenancy::ended(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + $this->assertSame(null, config('tenancy.foo')); + tenancy()->init('foo.localhost'); + $this->assertSame(null, config('tenancy.foo')); + tenancy()->end(); + $this->assertSame('bar', config('tenancy.foo')); + } } From 1a88cad4d684ad8b474db324693bfe4a527bcbe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 14 Aug 2019 17:32:33 +0200 Subject: [PATCH 2/6] [1.7.0] Fix Events system (#94) * Add TenantManagerEvents * Apply fixes from StyleCI * Fix typos, add tests * end() events * Travis should be failing * Uncomment ending --- src/Traits/BootstrapsTenancy.php | 8 ++++++++ test | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Traits/BootstrapsTenancy.php b/src/Traits/BootstrapsTenancy.php index cbfd9465..624b2180 100644 --- a/src/Traits/BootstrapsTenancy.php +++ b/src/Traits/BootstrapsTenancy.php @@ -41,6 +41,10 @@ trait BootstrapsTenancy public function end() { + array_map(function ($listener) { + $listener($this); + }, $this->listeners['ending']); + $this->initialized = false; $this->disconnectDatabase(); @@ -49,6 +53,10 @@ trait BootstrapsTenancy } $this->untagCache(); $this->resetFileSystemRootPaths(); + + array_map(function ($listener) { + $listener($this); + }, $this->listeners['ended']); } public function switchDatabaseConnection() diff --git a/test b/test index 5516ec57..ff55e60b 100755 --- a/test +++ b/test @@ -1,4 +1,5 @@ #!/bin/bash +set -e # for development docker-compose up -d @@ -6,4 +7,4 @@ printf "Variant 1\n\n" TENANCY_TEST_REDIS_TENANCY=1 TENANCY_TEST_REDIS_CLIENT=phpredis docker-compose exec test vendor/bin/phpunit --coverage-php coverage/1.cov "$@" printf "Variant 2\n\n" TENANCY_TEST_REDIS_TENANCY=0 TENANCY_TEST_REDIS_CLIENT=predis docker-compose exec test vendor/bin/phpunit --coverage-php coverage/2.cov "$@" -docker-compose exec test vendor/bin/phpcov merge --clover clover.xml coverage/ \ No newline at end of file +docker-compose exec test vendor/bin/phpcov merge --clover clover.xml coverage/ From 4aa35322dae6e3126b6c88e1c8b62f43dc7fd9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 14 Aug 2019 22:16:51 +0200 Subject: [PATCH 3/6] Add event prevents, Tenant facade --- composer.json | 1 + src/DatabaseManager.php | 10 ++- src/TenantManager.php | 4 +- src/Traits/BootstrapsTenancy.php | 59 +++++++++------ src/Traits/TenantManagerEvents.php | 15 ++++ tests/FacadeTest.php | 11 +++ tests/TenantManagerEventsTest.php | 114 +++++++++++++++++++++++++++++ tests/TenantManagerTest.php | 69 ----------------- tests/TestCase.php | 1 + 9 files changed, 187 insertions(+), 97 deletions(-) create mode 100644 tests/TenantManagerEventsTest.php diff --git a/composer.json b/composer.json index 1bd0a0aa..78357d1c 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,7 @@ ], "aliases": { "Tenancy": "Stancl\\Tenancy\\TenancyFacade", + "Tenant": "Stancl\\Tenancy\\TenancyFacade", "GlobalCache": "Stancl\\Tenancy\\GlobalCacheFacade" } } diff --git a/src/DatabaseManager.php b/src/DatabaseManager.php index 47bee9fc..e494ac69 100644 --- a/src/DatabaseManager.php +++ b/src/DatabaseManager.php @@ -6,7 +6,7 @@ use Stancl\Tenancy\Jobs\QueuedTenantDatabaseCreator; use Stancl\Tenancy\Jobs\QueuedTenantDatabaseDeleter; use Illuminate\Database\DatabaseManager as BaseDatabaseManager; -class DatabaseManager +final class DatabaseManager { public $originalDefaultConnection; @@ -19,8 +19,7 @@ class DatabaseManager public function connect(string $database) { $this->createTenantConnection($database); - $this->database->setDefaultConnection('tenant'); - $this->database->reconnect('tenant'); + $this->useConnection('tenant'); } public function connectToTenant($tenant) @@ -105,4 +104,9 @@ class DatabaseManager $database_name = $this->getDriver() === 'sqlite' ? database_path($database_name) : $database_name; config()->set(['database.connections.tenant.database' => $database_name]); } + + public function useConnection(string $connection) { + $this->database->setDefaultConnection($connection); + $this->database->reconnect($connection); + } } diff --git a/src/TenantManager.php b/src/TenantManager.php index 006bcce2..9d5531bb 100644 --- a/src/TenantManager.php +++ b/src/TenantManager.php @@ -7,7 +7,7 @@ use Stancl\Tenancy\Traits\BootstrapsTenancy; use Illuminate\Contracts\Foundation\Application; use Stancl\Tenancy\Exceptions\CannotChangeUuidOrDomainException; -class TenantManager +final class TenantManager { use BootstrapsTenancy; @@ -30,7 +30,7 @@ class TenantManager * * @var DatabaseManager */ - protected $database; + public $database; /** * Current tenant. diff --git a/src/Traits/BootstrapsTenancy.php b/src/Traits/BootstrapsTenancy.php index 624b2180..b7188968 100644 --- a/src/Traits/BootstrapsTenancy.php +++ b/src/Traits/BootstrapsTenancy.php @@ -21,42 +21,55 @@ trait BootstrapsTenancy public function bootstrap() { - array_map(function ($listener) { - $listener($this); - }, $this->listeners['bootstrapping']); - + $prevented = $this->event('bootstrapping'); $this->initialized = true; - $this->switchDatabaseConnection(); - if ($this->app['config']['tenancy.redis.tenancy']) { - $this->setPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']); + if (! $prevented->contains('database')) { + $this->switchDatabaseConnection(); } - $this->tagCache(); - $this->suffixFilesystemRootPaths(); - array_map(function ($listener) { - $listener($this); - }, $this->listeners['bootstrapped']); + if (! $prevented->contains('redis')) { + if ($this->app['config']['tenancy.redis.tenancy']) { + $this->setPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']); + } + } + + if (! $prevented->contains('cache')) { + $this->tagCache(); + } + + if (! $prevented->contains('filesystem')) { + $this->suffixFilesystemRootPaths(); + } + + $this->event('bootstrapped'); } public function end() { - array_map(function ($listener) { - $listener($this); - }, $this->listeners['ending']); + $prevented = $this->event('ending'); $this->initialized = false; - $this->disconnectDatabase(); - if ($this->app['config']['tenancy.redis.tenancy']) { - $this->resetPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']); + if (! $prevented->contains('database')) { + $this->disconnectDatabase(); } - $this->untagCache(); - $this->resetFileSystemRootPaths(); - array_map(function ($listener) { - $listener($this); - }, $this->listeners['ended']); + if (! $prevented->contains('redis')) { + if ($this->app['config']['tenancy.redis.tenancy']) { + $this->resetPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']); + } + } + + if (! $prevented->contains('cache')) { + $this->untagCache(); + } + + if (! $prevented->contains('filesystem')) { + $this->resetFileSystemRootPaths(); + } + + $this->event('ended'); } public function switchDatabaseConnection() diff --git a/src/Traits/TenantManagerEvents.php b/src/Traits/TenantManagerEvents.php index c54b322b..b4cb7455 100644 --- a/src/Traits/TenantManagerEvents.php +++ b/src/Traits/TenantManagerEvents.php @@ -2,6 +2,8 @@ namespace Stancl\Tenancy\Traits; +use Illuminate\Support\Collection; + trait TenantManagerEvents { /** @@ -67,4 +69,17 @@ trait TenantManagerEvents return $this; } + + /** + * Fire an event. + * + * @param string $name Event name + * @return Collection Prevented events + */ + public function event(string $name): Collection + { + return array_reduce($this->listeners[$name], function ($prevents, $listener) { + return $prevents->merge($listener($this)); + }, collect([])); + } } diff --git a/tests/FacadeTest.php b/tests/FacadeTest.php index a218f0dd..45da854c 100644 --- a/tests/FacadeTest.php +++ b/tests/FacadeTest.php @@ -2,6 +2,7 @@ namespace Stancl\Tenancy\Tests; +use Tenant; use Tenancy; class FacadeTest extends TestCase @@ -15,4 +16,14 @@ class FacadeTest extends TestCase $this->assertSame('bar', Tenancy::get('foo')); $this->assertSame('xyz', Tenancy::get('abc')); } + + /** @test */ + public function tenant_manager_can_be_accessed_using_the_Tenant_facade() + { + tenancy()->put('foo', 'bar'); + Tenant::put('abc', 'xyz'); + + $this->assertSame('bar', Tenant::get('foo')); + $this->assertSame('xyz', Tenant::get('abc')); + } } diff --git a/tests/TenantManagerEventsTest.php b/tests/TenantManagerEventsTest.php new file mode 100644 index 00000000..1863a2cc --- /dev/null +++ b/tests/TenantManagerEventsTest.php @@ -0,0 +1,114 @@ +create('foo.localhost')['uuid']; + + Tenancy::bootstrapping(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + $this->assertSame(null, config('tenancy.foo')); + tenancy()->init('foo.localhost'); + $this->assertSame('bar', config('tenancy.foo')); + } + + /** @test */ + public function bootstrapped_event_works() + { + $uuid = tenant()->create('foo.localhost')['uuid']; + + Tenancy::bootstrapped(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + $this->assertSame(null, config('tenancy.foo')); + tenancy()->init('foo.localhost'); + $this->assertSame('bar', config('tenancy.foo')); + } + + /** @test */ + public function ending_event_works() + { + $uuid = tenant()->create('foo.localhost')['uuid']; + + Tenancy::ending(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + $this->assertSame(null, config('tenancy.foo')); + tenancy()->init('foo.localhost'); + $this->assertSame(null, config('tenancy.foo')); + tenancy()->end(); + $this->assertSame('bar', config('tenancy.foo')); + } + + /** @test */ + public function ended_event_works() + { + $uuid = tenant()->create('foo.localhost')['uuid']; + + Tenancy::ended(function ($tenantManager) use ($uuid) { + if ($tenantManager->tenant['uuid'] === $uuid) { + config(['tenancy.foo' => 'bar']); + } + }); + + $this->assertSame(null, config('tenancy.foo')); + tenancy()->init('foo.localhost'); + $this->assertSame(null, config('tenancy.foo')); + tenancy()->end(); + $this->assertSame('bar', config('tenancy.foo')); + } + + /** @test */ + public function event_returns_a_collection() + { + // Note: The event() method should not be called by your code. + tenancy()->bootstrapping(function ($tenancy) { + return ['database']; + }); + tenancy()->bootstrapping(function ($tenancy) { + return ['redis', 'cache']; + }); + + $prevents = tenancy()->event('bootstrapping'); + $this->assertEquals(collect(['database', 'redis', 'cache']), $prevents); + } + + /** @test */ + public function database_can_be_reconnected_using_event_hooks() + { + config(['database.connections.tenantabc' => [ + 'driver' => 'sqlite', + 'database' => database_path('some_special_database.sqlite'), + ]]); + + $uuid = Tenant::create('abc.localhost')['uuid']; + + Tenancy::bootstrapping(function ($tenancy) use ($uuid) { + if ($tenancy->tenant['uuid'] === $uuid) { + $tenancy->database->useConnection('tenantabc'); + return ['database']; + } + }); + + $this->assertNotSame('tenantabc', \DB::connection()->getConfig()['name']); + tenancy()->init('abc.localhost'); + $this->assertSame('tenantabc', \DB::connection()->getConfig()['name']); + } +} \ No newline at end of file diff --git a/tests/TenantManagerTest.php b/tests/TenantManagerTest.php index faa2da3d..453730ea 100644 --- a/tests/TenantManagerTest.php +++ b/tests/TenantManagerTest.php @@ -2,7 +2,6 @@ namespace Stancl\Tenancy\Tests; -use Tenancy; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Stancl\Tenancy\Exceptions\CannotChangeUuidOrDomainException; @@ -242,72 +241,4 @@ class TenantManagerTest extends TestCase $this->expectException(CannotChangeUuidOrDomainException::class); tenant()->put(['uuid' => 'foo']); } - - /** @test */ - public function bootstrapping_event_works() - { - $uuid = tenant()->create('foo.localhost')['uuid']; - - Tenancy::bootstrapping(function ($tenantManager) use ($uuid) { - if ($tenantManager->tenant['uuid'] === $uuid) { - config(['tenancy.foo' => 'bar']); - } - }); - - $this->assertSame(null, config('tenancy.foo')); - tenancy()->init('foo.localhost'); - $this->assertSame('bar', config('tenancy.foo')); - } - - /** @test */ - public function bootstrapped_event_works() - { - $uuid = tenant()->create('foo.localhost')['uuid']; - - Tenancy::bootstrapped(function ($tenantManager) use ($uuid) { - if ($tenantManager->tenant['uuid'] === $uuid) { - config(['tenancy.foo' => 'bar']); - } - }); - - $this->assertSame(null, config('tenancy.foo')); - tenancy()->init('foo.localhost'); - $this->assertSame('bar', config('tenancy.foo')); - } - - /** @test */ - public function ending_event_works() - { - $uuid = tenant()->create('foo.localhost')['uuid']; - - Tenancy::ending(function ($tenantManager) use ($uuid) { - if ($tenantManager->tenant['uuid'] === $uuid) { - config(['tenancy.foo' => 'bar']); - } - }); - - $this->assertSame(null, config('tenancy.foo')); - tenancy()->init('foo.localhost'); - $this->assertSame(null, config('tenancy.foo')); - tenancy()->end(); - $this->assertSame('bar', config('tenancy.foo')); - } - - /** @test */ - public function ended_event_works() - { - $uuid = tenant()->create('foo.localhost')['uuid']; - - Tenancy::ended(function ($tenantManager) use ($uuid) { - if ($tenantManager->tenant['uuid'] === $uuid) { - config(['tenancy.foo' => 'bar']); - } - }); - - $this->assertSame(null, config('tenancy.foo')); - tenancy()->init('foo.localhost'); - $this->assertSame(null, config('tenancy.foo')); - tenancy()->end(); - $this->assertSame('bar', config('tenancy.foo')); - } } diff --git a/tests/TestCase.php b/tests/TestCase.php index b5d28acd..0183cc5a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -101,6 +101,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase { return [ 'Tenancy' => \Stancl\Tenancy\TenancyFacade::class, + 'Tenant' => \Stancl\Tenancy\TenancyFacade::class, 'GlobalCache' => \Stancl\Tenancy\GlobalCacheFacade::class, ]; } From 155ef0da5a255da66d75aa6c443a5471140641d1 Mon Sep 17 00:00:00 2001 From: stancl Date: Wed, 14 Aug 2019 20:17:04 +0000 Subject: [PATCH 4/6] Apply fixes from StyleCI --- src/DatabaseManager.php | 3 ++- tests/TenantManagerEventsTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/DatabaseManager.php b/src/DatabaseManager.php index e494ac69..68e0cde0 100644 --- a/src/DatabaseManager.php +++ b/src/DatabaseManager.php @@ -105,7 +105,8 @@ final class DatabaseManager config()->set(['database.connections.tenant.database' => $database_name]); } - public function useConnection(string $connection) { + public function useConnection(string $connection) + { $this->database->setDefaultConnection($connection); $this->database->reconnect($connection); } diff --git a/tests/TenantManagerEventsTest.php b/tests/TenantManagerEventsTest.php index 1863a2cc..095629a6 100644 --- a/tests/TenantManagerEventsTest.php +++ b/tests/TenantManagerEventsTest.php @@ -103,6 +103,7 @@ class TenantManagerEventsTest extends TestCase Tenancy::bootstrapping(function ($tenancy) use ($uuid) { if ($tenancy->tenant['uuid'] === $uuid) { $tenancy->database->useConnection('tenantabc'); + return ['database']; } }); @@ -111,4 +112,4 @@ class TenantManagerEventsTest extends TestCase tenancy()->init('abc.localhost'); $this->assertSame('tenantabc', \DB::connection()->getConfig()['name']); } -} \ No newline at end of file +} From 9c269b087eaf637a0fa3b02c6455838fdeb1f133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 14 Aug 2019 22:18:18 +0200 Subject: [PATCH 5/6] Add one more test for prevents --- tests/TenantManagerEventsTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/TenantManagerEventsTest.php b/tests/TenantManagerEventsTest.php index 1863a2cc..28fc35fa 100644 --- a/tests/TenantManagerEventsTest.php +++ b/tests/TenantManagerEventsTest.php @@ -111,4 +111,26 @@ class TenantManagerEventsTest extends TestCase tenancy()->init('abc.localhost'); $this->assertSame('tenantabc', \DB::connection()->getConfig()['name']); } + + /** @test */ + public function database_cannot_be_reconnected_without_using_prevents() + { + config(['database.connections.tenantabc' => [ + 'driver' => 'sqlite', + 'database' => database_path('some_special_database.sqlite'), + ]]); + + $uuid = Tenant::create('abc.localhost')['uuid']; + + Tenancy::bootstrapping(function ($tenancy) use ($uuid) { + if ($tenancy->tenant['uuid'] === $uuid) { + $tenancy->database->useConnection('tenantabc'); + // return ['database']; + } + }); + + $this->assertNotSame('tenantabc', \DB::connection()->getConfig()['name']); + tenancy()->init('abc.localhost'); + $this->assertSame('tenant', \DB::connection()->getConfig()['name']); + } } \ No newline at end of file From aca5567c101910b39b07b298822e9a69a1b22cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 14 Aug 2019 22:55:18 +0200 Subject: [PATCH 6/6] Add empty array default --- src/Traits/TenantManagerEvents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/TenantManagerEvents.php b/src/Traits/TenantManagerEvents.php index b4cb7455..416ebd72 100644 --- a/src/Traits/TenantManagerEvents.php +++ b/src/Traits/TenantManagerEvents.php @@ -79,7 +79,7 @@ trait TenantManagerEvents public function event(string $name): Collection { return array_reduce($this->listeners[$name], function ($prevents, $listener) { - return $prevents->merge($listener($this)); + return $prevents->merge($listener($this) ?? []); }, collect([])); } }