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

[2.x] Refactor App Providers #451

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/websockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
|
*/

'app' => \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider::class,
'app' => \BeyondCode\LaravelWebSockets\Apps\ConfigAppManager::class,

/*
|--------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/Apps/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class App

public static function findById($appId)
{
return app(AppProvider::class)->findById($appId);
return app(AppManager::class)->findById($appId);
}

public static function findByKey(string $appKey): ?self
{
return app(AppProvider::class)->findByKey($appKey);
return app(AppManager::class)->findByKey($appKey);
}

public static function findBySecret(string $appSecret): ?self
{
return app(AppProvider::class)->findBySecret($appSecret);
return app(AppManager::class)->findBySecret($appSecret);
}

public function __construct($appId, string $appKey, string $appSecret)
Expand Down
2 changes: 1 addition & 1 deletion src/Apps/AppProvider.php → src/Apps/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BeyondCode\LaravelWebSockets\Apps;

interface AppProvider
interface AppManager
{
/** @return array[BeyondCode\LaravelWebSockets\AppProviders\App] */
public function all(): array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\Collection;

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

/** @return array[\BeyondCode\LaravelWebSockets\AppProviders\App] */
/** @return array[\BeyondCode\LaravelWebSockets\Apps\App] */
public function all(): array
{
return $this->apps
Expand Down
4 changes: 2 additions & 2 deletions src/Dashboard/Http/Controllers/ShowDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;

use BeyondCode\LaravelWebSockets\Apps\AppProvider;
use BeyondCode\LaravelWebSockets\Apps\AppManager;
use Illuminate\Http\Request;

class ShowDashboard
{
public function __invoke(Request $request, AppProvider $apps)
public function __invoke(Request $request, AppManager $apps)
{
return view('websockets::dashboard', [
'apps' => $apps->all(),
Expand Down
8 changes: 4 additions & 4 deletions src/Statistics/Rules/AppId.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

namespace BeyondCode\LaravelWebSockets\Statistics\Rules;

use BeyondCode\LaravelWebSockets\Apps\AppProvider;
use BeyondCode\LaravelWebSockets\Apps\AppManager;
use Illuminate\Contracts\Validation\Rule;

class AppId implements Rule
{
public function passes($attribute, $value)
{
$appProvider = app(AppProvider::class);
$manager = app(AppManager::class);

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

public function message()
{
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.';
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.';
}
}
4 changes: 2 additions & 2 deletions src/WebSocketsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BeyondCode\LaravelWebSockets;

use BeyondCode\LaravelWebSockets\Apps\AppProvider;
use BeyondCode\LaravelWebSockets\Apps\AppManager;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
Expand Down Expand Up @@ -101,7 +101,7 @@ public function register()
return new $channelManager;
});

$this->app->singleton(AppProvider::class, function () {
$this->app->singleton(AppManager::class, function () {
return $this->app->make(config('websockets.managers.app'));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;

use BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider;
use BeyondCode\LaravelWebSockets\Apps\ConfigAppManager;
use BeyondCode\LaravelWebSockets\Tests\TestCase;

class ConfigAppProviderTest extends TestCase
class ConfigAppManagerTest extends TestCase
{
/** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider */
protected $configAppProvider;
/** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppManager */
protected $appManager;

public function setUp(): void
{
parent::setUp();

$this->configAppProvider = new ConfigAppProvider();
$this->appManager = new ConfigAppManager;
}

/** @test */
public function it_can_get_apps_from_the_config_file()
{
$apps = $this->configAppProvider->all();
$apps = $this->appManager->all();

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

Expand All @@ -38,11 +38,11 @@ public function it_can_get_apps_from_the_config_file()
/** @test */
public function it_can_find_app_by_id()
{
$app = $this->configAppProvider->findById(0000);
$app = $this->appManager->findById(0000);

$this->assertNull($app);

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

$this->assertEquals('Test App', $app->name);
$this->assertEquals(1234, $app->id);
Expand All @@ -55,11 +55,11 @@ public function it_can_find_app_by_id()
/** @test */
public function it_can_find_app_by_key()
{
$app = $this->configAppProvider->findByKey('InvalidKey');
$app = $this->appManager->findByKey('InvalidKey');

$this->assertNull($app);

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

$this->assertEquals('Test App', $app->name);
$this->assertEquals(1234, $app->id);
Expand All @@ -72,11 +72,11 @@ public function it_can_find_app_by_key()
/** @test */
public function it_can_find_app_by_secret()
{
$app = $this->configAppProvider->findBySecret('InvalidSecret');
$app = $this->appManager->findBySecret('InvalidSecret');

$this->assertNull($app);

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

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