Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Refactor ServiceConfig::class. #81

Merged
merged 1 commit into from
Jun 28, 2024
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
12 changes: 6 additions & 6 deletions src/Console/Commands/OrchestrateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Payavel\Orchestration\Fluent\ServiceConfig;
use Payavel\Orchestration\ServiceConfig;
use Payavel\Orchestration\Traits\AsksQuestions;
use Payavel\Orchestration\Traits\GeneratesFiles;

Expand Down Expand Up @@ -39,7 +39,7 @@ class OrchestrateProvider extends Command
/**
* The provider's service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
* @var \Payavel\Orchestration\ServiceConfig
*/
protected $serviceConfig;

Expand Down Expand Up @@ -144,13 +144,13 @@ protected function setService()
error("Service with id {$this->option('service')} does not exist.");

return false;
} elseif (! isset($serviceConfig) && ($existingConfigs = ServiceConfig::all())->isNotEmpty()) {
$id = select(
} elseif (! isset($serviceConfig) && ($serviceConfigs = ServiceConfig::all())->isNotEmpty()) {
$index = select(
label: 'Which service will the provider be offering?',
options: $existingConfigs->map(fn ($existingConfig) => $existingConfig->id)->all()
options: $serviceConfigs->map(fn ($serviceConfig) => $serviceConfig->id)->all()
);

$serviceConfig = $existingConfigs->all()[$id];
$serviceConfig = $serviceConfigs->get($index);
}

if (! isset($serviceConfig)) {
Expand Down
16 changes: 8 additions & 8 deletions src/Console/Commands/OrchestrateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use Payavel\Orchestration\Fluent\ServiceConfig;
use Payavel\Orchestration\ServiceConfig;
use Payavel\Orchestration\Traits\AsksQuestions;
use Payavel\Orchestration\Traits\GeneratesFiles;

Expand Down Expand Up @@ -39,7 +39,7 @@ class OrchestrateService extends Command
/**
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
* @var \Payavel\Orchestration\ServiceConfig
*/
protected $serviceConfig;

Expand Down Expand Up @@ -163,10 +163,12 @@ protected function generateProviders()
*/
protected function setServiceConfig()
{
$this->serviceConfig = new ServiceConfig([
'name' => $name = trim($this->argument('service') ?? $this->askName('service')),
'id' => $this->option('id') ?? $this->askId('service', $name),
]);
$name = trim($this->argument('service') ?? $this->askName('service'));
$id = $this->option('id') ?? $this->askId('service', $name);

Config::set("orchestration.services.{$id}", Str::slug($id));

$this->serviceConfig = tap(ServiceConfig::find($id), fn ($serviceConfig) => $serviceConfig->set('name', $name));
}

/**
Expand Down Expand Up @@ -251,8 +253,6 @@ protected function setAccounts()
*/
protected function makeSureOrchestraIsReady()
{
Config::set("orchestration.services.{$this->serviceConfig->id}", Str::slug($this->serviceConfig->id));

if (file_exists(config_path('orchestration.php'))) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/ConfigDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Payavel\Orchestration\Contracts\Providable;
use Payavel\Orchestration\Fluent\Account;
use Payavel\Orchestration\Fluent\Provider;
use Payavel\Orchestration\Fluent\ServiceConfig;
use Payavel\Orchestration\ServiceConfig;
use Payavel\Orchestration\ServiceDriver;
use Payavel\Orchestration\Traits\GeneratesFiles;

Expand Down Expand Up @@ -169,7 +169,7 @@ public function resolveGateway(Providable $provider, Accountable $account)
/**
* Generate the service skeleton based on the current driver.
*
* @param \Payavel\Orchestration\Fluent\ServiceConfig $serviceConfig
* @param \Payavel\Orchestration\ServiceConfig $serviceConfig
* @param \Illuminate\Support\Collection $providers
* @param \Illuminate\Support\Collection $accounts
* @param array $defaults
Expand Down
6 changes: 3 additions & 3 deletions src/Drivers/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use Illuminate\Support\Str;
use Payavel\Orchestration\Contracts\Accountable;
use Payavel\Orchestration\Contracts\Providable;
use Payavel\Orchestration\Fluent\ServiceConfig;
use Payavel\Orchestration\Models\Account;
use Payavel\Orchestration\Models\Provider;
use Payavel\Orchestration\ServiceConfig;
use Payavel\Orchestration\ServiceDriver;
use Payavel\Orchestration\Traits\GeneratesFiles;

Expand Down Expand Up @@ -123,7 +123,7 @@ public function resolveGateway(Providable $provider, Accountable $account)
$this->check($provider, $account);

$gateway = $this->serviceConfig->get('test_mode')
? $this->serviceConfig->test_gateway
? $this->serviceConfig->get('test_gateway')
: $provider->gateway;

if (! class_exists($gateway)) {
Expand All @@ -140,7 +140,7 @@ public function resolveGateway(Providable $provider, Accountable $account)
/**
* Generate the service skeleton based on the current driver.
*
* @param \Payavel\Orchestration\Fluent\ServiceConfig $serviceConfig
* @param \Payavel\Orchestration\ServiceConfig $serviceConfig
* @param \Illuminate\Support\Collection $providers
* @param \Illuminate\Support\Collection $accounts
* @param array $defaults
Expand Down
4 changes: 2 additions & 2 deletions src/Fluent/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Payavel\Orchestration\Fluent;

use Illuminate\Support\Collection;
use Illuminate\Support\Fluent;
use Payavel\Orchestration\Contracts\Accountable;
use Payavel\Orchestration\ServiceConfig;

class Account extends Fluent implements Accountable
{
/**
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
* @var \Payavel\Orchestration\ServiceConfig
*/
private ServiceConfig $serviceConfig;

Expand Down
3 changes: 2 additions & 1 deletion src/Fluent/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use Illuminate\Support\Fluent;
use Payavel\Orchestration\Contracts\Providable;
use Payavel\Orchestration\ServiceConfig;

class Provider extends Fluent implements Providable
{
/**
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
* @var \Payavel\Orchestration\ServiceConfig
*/
public ServiceConfig $serviceConfig;

Expand Down
81 changes: 0 additions & 81 deletions src/Fluent/ServiceConfig.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Payavel\Orchestration\Contracts\Accountable;
use Payavel\Orchestration\Fluent\ServiceConfig;
use Payavel\Orchestration\ServiceConfig;
use Payavel\Orchestration\Traits\HasFactory;

class Account extends Model implements Accountable
Expand All @@ -29,7 +29,7 @@ class Account extends Model implements Accountable
/**
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
* @var \Payavel\Orchestration\ServiceConfig
*/
private ServiceConfig $serviceConfig;

Expand Down
4 changes: 2 additions & 2 deletions src/Models/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Payavel\Orchestration\Contracts\Providable;
use Payavel\Orchestration\Fluent\ServiceConfig;
use Payavel\Orchestration\ServiceConfig;
use Payavel\Orchestration\Traits\HasFactory;

class Provider extends Model implements Providable
Expand All @@ -29,7 +29,7 @@ class Provider extends Model implements Providable
/**
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
* @var \Payavel\Orchestration\ServiceConfig
*/
private ServiceConfig $serviceConfig;

Expand Down
6 changes: 3 additions & 3 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Payavel\Orchestration;

use Exception;
use Payavel\Orchestration\Fluent\ServiceConfig;
use Payavel\Orchestration\ServiceConfig;
use Payavel\Orchestration\Traits\SimulatesAttributes;

class Service
Expand All @@ -13,7 +13,7 @@ class Service
/**
* The service config.
*
* @var \Payavel\Orchestration\Fluent\ServiceConfig
* @var \Payavel\Orchestration\ServiceConfig
*/
private $config;

Expand Down Expand Up @@ -48,7 +48,7 @@ class Service
/**
* Sets the service config and the driver for it.
*
* @param \Payavel\Orchestration\Fluent\ServiceConfig|string|int $serviceConfig
* @param \Payavel\Orchestration\ServiceConfig|string|int $serviceConfig
* @return void
*
* @throws Exception
Expand Down
Loading
Loading