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

[2.x] Fix orchestrate commands not working on Windows. #68

Merged
merged 4 commits into from
Apr 27, 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
9 changes: 5 additions & 4 deletions src/Console/Commands/OrchestrateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use function Laravel\Prompts\error;
use function Laravel\Prompts\info;
use function Laravel\Prompts\select;
use function Illuminate\Filesystem\join_paths;

class OrchestrateProvider extends Command
{
Expand Down Expand Up @@ -106,7 +107,7 @@ protected function generateProvider()
$provider = Str::studly($this->id);

static::putFile(
app_path($requestPath = "Services/{$service}/{$provider}{$service}Request.php"),
app_path($requestPath = join_paths('Services', $service, "{$provider}{$service}Request.php")),
static::makeFile(
static::getStub('service-request', $this->service->getId()),
[
Expand All @@ -116,10 +117,10 @@ protected function generateProvider()
)
);

info("Gateway [app/{$requestPath}] created successfully.");
info('Gateway ['.join_paths('app', $requestPath).'] created successfully.');

static::putFile(
app_path($responsePath = "Services/{$service}/{$provider}{$service}Response.php"),
app_path($responsePath = join_paths('Services', $service, "{$provider}{$service}Response.php")),
static::makeFile(
static::getStub('service-response', $this->service->getId()),
[
Expand All @@ -129,7 +130,7 @@ protected function generateProvider()
)
);

info("Gateway [app/{$responsePath}] created successfully.");
info('Gateway ['.join_paths('app', $responsePath).'] created successfully.');
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/Console/Commands/OrchestrateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function Laravel\Prompts\info;
use function Laravel\Prompts\multiselect;
use function Laravel\Prompts\select;
use function Illuminate\Filesystem\join_paths;

class OrchestrateService extends Command
{
Expand Down Expand Up @@ -111,7 +112,7 @@ protected function generateService()
$studlyService = Str::studly($this->service->getId());

static::putFile(
app_path($requesterPath = "Services/{$studlyService}/Contracts/{$studlyService}Requester.php"),
app_path($requesterPath = join_paths('Services', $studlyService, 'Contracts', "{$studlyService}Requester.php")),
static::makeFile(
static::getStub('service-requester', $this->service->getId()),
[
Expand All @@ -120,10 +121,10 @@ protected function generateService()
)
);

info("Contract [app/{$requesterPath}] created successfully.");
info('Contract ['.join_paths('app', $requesterPath).'] created successfully.');

static::putFile(
app_path($responderPath = "Services/{$studlyService}/Contracts/{$studlyService}Responder.php"),
app_path($responderPath = join_paths('Services', $studlyService, 'Contracts', "{$studlyService}Responder.php")),
static::makeFile(
static::getStub('service-responder', $this->service->getId()),
[
Expand All @@ -132,7 +133,7 @@ protected function generateService()
)
);

info("Contract [app/{$responderPath}] created successfully.");
info('Contract ['.join_paths('app', $responderPath).'] created successfully.');
}

/**
Expand Down Expand Up @@ -267,6 +268,6 @@ protected function makeSureOrchestraIsReady()
)
);

info("Config [config/{$configPath}] created successfully.");
info('Config ['.join_paths('config', $configPath).'] created successfully.');
}
}
3 changes: 2 additions & 1 deletion src/Console/Commands/OrchestrateStubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use function Laravel\Prompts\error;
use function Laravel\Prompts\info;
use function Illuminate\Filesystem\join_paths;

class OrchestrateStubs extends Command
{
Expand Down Expand Up @@ -88,7 +89,7 @@ public function handle()

foreach($stubs as $stub) {
static::putFile(
base_path("{$directory}/{$stub}.stub"),
base_path(join_paths($directory, "{$stub}.stub")),
file_get_contents(__DIR__."/../../../stubs/{$stub}.stub")
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/DataTransferObjects/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ public function getService()
public function getProviders()
{
if (! isset($this->providers)) {
$this->attributes['providers'] = (new Collection(ServiceConfig::get($this->service, 'accounts.' . $this->attributes['id'] . '.providers', [])))
$this->attributes['providers'] = (new Collection(ServiceConfig::get($this->service, 'accounts.'.$this->attributes['id'].'.providers', [])))
->map(
fn ($provider, $key) => is_array($provider)
? array_merge(
['id' => $key],
ServiceConfig::get($this->service, 'providers.' . $key),
ServiceConfig::get($this->service, 'providers.'.$key),
$provider
)
: array_merge(
['id' => $provider],
ServiceConfig::get($this->service, 'providers.' . $provider)
ServiceConfig::get($this->service, 'providers.'.$provider)
)
);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Drivers/ConfigDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Payavel\Orchestration\Support\ServiceConfig;

use function Laravel\Prompts\info;
use function Illuminate\Filesystem\join_paths;

class ConfigDriver extends ServiceDriver
{
Expand Down Expand Up @@ -195,7 +196,7 @@ public static function generateService(Serviceable $service, Collection $provide

$config['accounts'] = $accounts->reduce(
fn ($config, $account) =>
$config . static::makeFile(
$config.static::makeFile(
static::getStub('config-service-account', $service->getId()),
[
'id' => $account['id'],
Expand All @@ -216,7 +217,7 @@ public static function generateService(Serviceable $service, Collection $provide
);

static::putFile(
config_path($configPath = Str::slug($service->getId()) . '.php'),
config_path($configPath = Str::slug($service->getId()).'.php'),
static::makeFile(
static::getStub('config-service', $service->getId()),
[
Expand All @@ -233,7 +234,7 @@ public static function generateService(Serviceable $service, Collection $provide
)
);

info("Config [config/{$configPath}] created successfully.");
info('Config ['.join_paths('config', $configPath).'] created successfully.');

Config::set(Str::slug($service->getId()), require(config_path($configPath)));
}
Expand Down
15 changes: 8 additions & 7 deletions src/Drivers/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Payavel\Orchestration\Support\ServiceConfig;

use function Laravel\Prompts\info;
use function Illuminate\Filesystem\join_paths;

class DatabaseDriver extends ServiceDriver
{
Expand All @@ -32,7 +33,7 @@ class DatabaseDriver extends ServiceDriver
public function resolveProvider($provider)
{
if (! $provider instanceof Provider) {
$serviceProvider = ServiceConfig::get($this->service, 'models.' . Provider::class, Provider::class);
$serviceProvider = ServiceConfig::get($this->service, 'models.'.Provider::class, Provider::class);

$provider = $serviceProvider::find($provider);
}
Expand Down Expand Up @@ -68,7 +69,7 @@ public function getDefaultProvider(Accountable $account = null)
public function resolveAccount($account)
{
if (! $account instanceof Account) {
$serviceAccount = ServiceConfig::get($this->service, 'models.' . Account::class, Account::class);
$serviceAccount = ServiceConfig::get($this->service, 'models.'.Account::class, Account::class);

$account = $serviceAccount::find($account);
}
Expand Down Expand Up @@ -151,7 +152,7 @@ public static function generateService(Serviceable $service, Collection $provide
Artisan::call('vendor:publish', ['--tag' => 'payavel-orchestration-migrations']);

static::putFile(
config_path($configPath = Str::slug($service->getId()) . '.php'),
config_path($configPath = Str::slug($service->getId()).'.php'),
static::makeFile(
static::getStub('config-service-database', $service->getId()),
[
Expand All @@ -166,13 +167,13 @@ public static function generateService(Serviceable $service, Collection $provide
)
);

info("Config [config/{$configPath}] created successfully.");
info('Config ['.join_paths('config', $configPath).'] created successfully.');

Config::set(Str::slug($service->getId()), require(config_path($configPath)));

$providers = $providers->reduce(
fn ($array, $provider, $index) =>
$array . static::makeFile(
$array.static::makeFile(
static::getStub('migration-service-providers', $service->getId()),
[
'id' => $provider['id'],
Expand All @@ -186,7 +187,7 @@ public static function generateService(Serviceable $service, Collection $provide

$accounts = $accounts->reduce(
fn ($array, $account, $index) =>
$array . static::makeFile(
$array.static::makeFile(
static::getStub('migration-service-accounts', $service->getId()),
[
'id' => $account['id'],
Expand All @@ -199,7 +200,7 @@ public static function generateService(Serviceable $service, Collection $provide
);

static::putFile(
database_path($migrationPath = 'migrations/' . Carbon::now()->format('Y_m_d_His') . '_add_providers_and_accounts_to_' . Str::slug($service->getId(), '_') . '_service.php'),
database_path($migrationPath = join_paths('migrations', Carbon::now()->format('Y_m_d_His').'_add_providers_and_accounts_to_'.Str::slug($service->getId(), '_')).'_service.php'),
static::makeFile(
static::getStub('migration-service', $service->getId()),
[
Expand Down
4 changes: 2 additions & 2 deletions src/OrchestrationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public function boot()
public function register()
{
$this->mergeConfigFrom(
__DIR__ . '/../config/orchestration.php',
__DIR__.'/../config/orchestration.php',
'orchestration'
);
}

protected function registerPublishableAssets()
{
$this->publishes([
__DIR__ . '/../database/migrations/2024_01_01_000001_create_base_orchestration_tables.php' => database_path('migrations/2024_01_01_000001_create_base_orchestration_tables.php'),
__DIR__.'/../database/migrations/2024_01_01_000001_create_base_orchestration_tables.php' => database_path('migrations/2024_01_01_000001_create_base_orchestration_tables.php'),
], ['payavel', 'payavel-orchestration', 'payavel-migrations', 'payavel-orchestration-migrations']);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct($service)

$this->service = $service;

if (! class_exists($driver = ServiceConfig::get($this->service, 'drivers.' . ServiceConfig::get($this->service, 'defaults.driver')))) {
if (! class_exists($driver = ServiceConfig::get($this->service, 'drivers.'.ServiceConfig::get($this->service, 'defaults.driver')))) {
throw new Exception('Invalid driver provided.');
}

Expand Down
2 changes: 1 addition & 1 deletion src/ServiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function setUp()
public function request($method, $params)
{
if (! method_exists($this, $method)) {
throw new \BadMethodCallException(get_class($this) . "::{$method}() not found.");
throw new \BadMethodCallException(get_class($this)."::{$method}() not found.");
}

$response = $this->{$method}(...$params);
Expand Down
12 changes: 6 additions & 6 deletions src/Support/ServiceConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public static function get($service, $key, $default = null)
$service = $service->getId();
}

$config = Config::get('orchestration.services.' . $service, Str::slug($service));
$config = Config::get('orchestration.services.'.$service, Str::slug($service));

if (is_array($config)) {
return Config::get('orchestration.services.' . $service . '.' . $key, $default);
return Config::get('orchestration.services.'.$service.'.'.$key, $default);
}

return Config::get(
$config . '.' . $key,
$config.'.'.$key,
Config::get(
'orchestration.' . $key,
'orchestration.'.$key,
$default
)
);
Expand All @@ -51,10 +51,10 @@ public static function set($service, string $key, $value)
$service = $service->getId();
}

$config = Config::get('orchestration.services.' . $service, Str::slug($service));
$config = Config::get('orchestration.services.'.$service, Str::slug($service));

Config::set(
(is_array($config) ? 'orchestration.services.' . $service : $config) . '.' . $key,
(is_array($config) ? 'orchestration.services.'.$service : $config).'.'.$key,
$value
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/AsksQuestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ protected function askId($entity, $name)
*/
private function formatService($entity)
{
return ($this->service ? ($this->service->getName() . ' ') : '') . $entity;
return ($this->service ? ($this->service->getName().' ') : '').$entity;
}
}
6 changes: 3 additions & 3 deletions src/Traits/GeneratesFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected static function makeFile($stub, $data)
$file = file_get_contents($stub);

foreach ($data as $search => $replace) {
$file = Str::replace('{{ ' . $search . ' }}', $replace, $file);
$file = Str::replace('{{ '.$search.' }}', $replace, $file);
}

return $file;
Expand All @@ -36,7 +36,7 @@ protected static function putFile($path, $file)
{
$fileSystem = new Filesystem();

$directory = collect(explode('/', $path, -1))->join('/');
$directory = collect(explode(DIRECTORY_SEPARATOR, $path, -1))->join(DIRECTORY_SEPARATOR);
$fileSystem->ensureDirectoryExists($directory);

$fileSystem->put($path, $file);
Expand Down Expand Up @@ -65,6 +65,6 @@ protected static function getStub($stub, $service = null)
return $file;
}

return __DIR__ . "/../../stubs/{$stub}.stub";
return __DIR__."/../../stubs/{$stub}.stub";
}
}
4 changes: 2 additions & 2 deletions src/Traits/SimulatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait SimulatesAttributes
*/
public function __get($key)
{
if (! method_exists(self::class, $method = 'get' . Str::studly($key))) {
if (! method_exists(self::class, $method = 'get'.Str::studly($key))) {
return $this->getAttribute($key);
}

Expand All @@ -37,7 +37,7 @@ public function __get($key)
*/
public function __set($key, $value): void
{
if (! method_exists(self::class, $method = 'set' . Str::studly($key))) {
if (! method_exists(self::class, $method = 'set'.Str::studly($key))) {
$this->setAttribute($key, $value);

return;
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/ThrowsRuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ trait ThrowsRuntimeException
*/
private function throwRuntimeException($method)
{
throw new RuntimeException(get_class($this) . "::class does not implement the {$method}() method.");
throw new RuntimeException(get_class($this)."::class does not implement the {$method}() method.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ class ConfigOrchestrateServiceCommandTest extends TestOrchestrateServiceCommand

protected function makeSureProviderExists(Serviceable $service, Providable $provider)
{
$config = require(config_path(Str::slug($service->getId()) . '.php'));
$config = require(config_path(Str::slug($service->getId()).'.php'));

$this->assertIsArray($config['providers']);
$this->assertIsArray($config['providers'][$provider->getId()]);
$this->assertEquals(
'App\\Services\\' . Str::studly($service->getId()) . '\\' . Str::studly($provider->getId()) . Str::studly($service->getId()) . 'Request',
'App\\Services\\'.Str::studly($service->getId()).'\\'.Str::studly($provider->getId()).Str::studly($service->getId()).'Request',
$config['providers'][$provider->getId()]['gateway']
);
}

protected function makeSureAccountExists(Serviceable $service, Accountable $account)
{
$config = require(config_path(Str::slug($service->getId()) . '.php'));
$config = require(config_path(Str::slug($service->getId()).'.php'));

$this->assertIsArray($config['accounts']);
$this->assertIsArray($config['accounts'][$account->getId()]);
Expand All @@ -38,7 +38,7 @@ protected function makeSureAccountExists(Serviceable $service, Accountable $acco

protected function makeSureProviderIsLinkedToAccount(Serviceable $service, Providable $provider, Accountable $account)
{
$config = require(config_path(Str::slug($service->getId()) . '.php'));
$config = require(config_path(Str::slug($service->getId()).'.php'));

$this->assertIsArray($config['accounts'][$account->getId()]['providers'][$provider->getId()]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function makeSureProviderExists(Serviceable $service, Providable $prov

$this->assertNotNull($provider);
$this->assertEquals(
'App\\Services\\' . Str::studly($service->getId()) . '\\' . Str::studly($provider->getId()) . Str::studly($service->getId()) . 'Request',
'App\\Services\\'.Str::studly($service->getId()).'\\'.Str::studly($provider->getId()).Str::studly($service->getId()).'Request',
$provider->gateway
);
}
Expand Down
Loading