Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 08b836b

Browse files
authored
Merge pull request #451 from beyondcode/refactor/app-providers
[2.x] Refactor App Providers
2 parents 815eabc + 099d90b commit 08b836b

File tree

8 files changed

+27
-27
lines changed

8 files changed

+27
-27
lines changed

config/websockets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
|
4141
*/
4242

43-
'app' => \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider::class,
43+
'app' => \BeyondCode\LaravelWebSockets\Apps\ConfigAppManager::class,
4444

4545
/*
4646
|--------------------------------------------------------------------------

src/Apps/App.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ class App
3535

3636
public static function findById($appId)
3737
{
38-
return app(AppProvider::class)->findById($appId);
38+
return app(AppManager::class)->findById($appId);
3939
}
4040

4141
public static function findByKey(string $appKey): ?self
4242
{
43-
return app(AppProvider::class)->findByKey($appKey);
43+
return app(AppManager::class)->findByKey($appKey);
4444
}
4545

4646
public static function findBySecret(string $appSecret): ?self
4747
{
48-
return app(AppProvider::class)->findBySecret($appSecret);
48+
return app(AppManager::class)->findBySecret($appSecret);
4949
}
5050

5151
public function __construct($appId, string $appKey, string $appSecret)

src/Apps/AppProvider.php renamed to src/Apps/AppManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BeyondCode\LaravelWebSockets\Apps;
44

5-
interface AppProvider
5+
interface AppManager
66
{
77
/** @return array[BeyondCode\LaravelWebSockets\AppProviders\App] */
88
public function all(): array;

src/Apps/ConfigAppProvider.php renamed to src/Apps/ConfigAppManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Support\Collection;
66

7-
class ConfigAppProvider implements AppProvider
7+
class ConfigAppManager implements AppManager
88
{
99
/** @var Collection */
1010
protected $apps;
@@ -14,7 +14,7 @@ public function __construct()
1414
$this->apps = collect(config('websockets.apps'));
1515
}
1616

17-
/** @return array[\BeyondCode\LaravelWebSockets\AppProviders\App] */
17+
/** @return array[\BeyondCode\LaravelWebSockets\Apps\App] */
1818
public function all(): array
1919
{
2020
return $this->apps

src/Dashboard/Http/Controllers/ShowDashboard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
44

5-
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
5+
use BeyondCode\LaravelWebSockets\Apps\AppManager;
66
use Illuminate\Http\Request;
77

88
class ShowDashboard
99
{
10-
public function __invoke(Request $request, AppProvider $apps)
10+
public function __invoke(Request $request, AppManager $apps)
1111
{
1212
return view('websockets::dashboard', [
1313
'apps' => $apps->all(),

src/Statistics/Rules/AppId.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
namespace BeyondCode\LaravelWebSockets\Statistics\Rules;
44

5-
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
5+
use BeyondCode\LaravelWebSockets\Apps\AppManager;
66
use Illuminate\Contracts\Validation\Rule;
77

88
class AppId implements Rule
99
{
1010
public function passes($attribute, $value)
1111
{
12-
$appProvider = app(AppProvider::class);
12+
$manager = app(AppManager::class);
1313

14-
return $appProvider->findById($value) ? true : false;
14+
return $manager->findById($value) ? true : false;
1515
}
1616

1717
public function message()
1818
{
19-
return 'There is no app registered with the given id. Make sure the websockets config file contains an app for this id or that your custom AppProvider returns an app for this id.';
19+
return 'There is no app registered with the given id. Make sure the websockets config file contains an app for this id or that your custom AppManager returns an app for this id.';
2020
}
2121
}

src/WebSocketsServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace BeyondCode\LaravelWebSockets;
44

5-
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
5+
use BeyondCode\LaravelWebSockets\Apps\AppManager;
66
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
77
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController;
88
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
@@ -101,7 +101,7 @@ public function register()
101101
return new $channelManager;
102102
});
103103

104-
$this->app->singleton(AppProvider::class, function () {
104+
$this->app->singleton(AppManager::class, function () {
105105
return $this->app->make(config('websockets.managers.app'));
106106
});
107107
}

tests/ClientProviders/ConfigAppProviderTest.php renamed to tests/ClientProviders/ConfigAppManagerTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
44

5-
use BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider;
5+
use BeyondCode\LaravelWebSockets\Apps\ConfigAppManager;
66
use BeyondCode\LaravelWebSockets\Tests\TestCase;
77

8-
class ConfigAppProviderTest extends TestCase
8+
class ConfigAppManagerTest extends TestCase
99
{
10-
/** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider */
11-
protected $configAppProvider;
10+
/** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppManager */
11+
protected $appManager;
1212

1313
public function setUp(): void
1414
{
1515
parent::setUp();
1616

17-
$this->configAppProvider = new ConfigAppProvider();
17+
$this->appManager = new ConfigAppManager;
1818
}
1919

2020
/** @test */
2121
public function it_can_get_apps_from_the_config_file()
2222
{
23-
$apps = $this->configAppProvider->all();
23+
$apps = $this->appManager->all();
2424

2525
$this->assertCount(1, $apps);
2626

@@ -38,11 +38,11 @@ public function it_can_get_apps_from_the_config_file()
3838
/** @test */
3939
public function it_can_find_app_by_id()
4040
{
41-
$app = $this->configAppProvider->findById(0000);
41+
$app = $this->appManager->findById(0000);
4242

4343
$this->assertNull($app);
4444

45-
$app = $this->configAppProvider->findById(1234);
45+
$app = $this->appManager->findById(1234);
4646

4747
$this->assertEquals('Test App', $app->name);
4848
$this->assertEquals(1234, $app->id);
@@ -55,11 +55,11 @@ public function it_can_find_app_by_id()
5555
/** @test */
5656
public function it_can_find_app_by_key()
5757
{
58-
$app = $this->configAppProvider->findByKey('InvalidKey');
58+
$app = $this->appManager->findByKey('InvalidKey');
5959

6060
$this->assertNull($app);
6161

62-
$app = $this->configAppProvider->findByKey('TestKey');
62+
$app = $this->appManager->findByKey('TestKey');
6363

6464
$this->assertEquals('Test App', $app->name);
6565
$this->assertEquals(1234, $app->id);
@@ -72,11 +72,11 @@ public function it_can_find_app_by_key()
7272
/** @test */
7373
public function it_can_find_app_by_secret()
7474
{
75-
$app = $this->configAppProvider->findBySecret('InvalidSecret');
75+
$app = $this->appManager->findBySecret('InvalidSecret');
7676

7777
$this->assertNull($app);
7878

79-
$app = $this->configAppProvider->findBySecret('TestSecret');
79+
$app = $this->appManager->findBySecret('TestSecret');
8080

8181
$this->assertEquals('Test App', $app->name);
8282
$this->assertEquals(1234, $app->id);

0 commit comments

Comments
 (0)