Skip to content

Commit

Permalink
Merge pull request #98 from holiq/3x
Browse files Browse the repository at this point in the history
refactor(command): change structure infrastructure layer
  • Loading branch information
pemudakoding authored Oct 21, 2023
2 parents e515a2b + 92ba4c8 commit 14a823e
Show file tree
Hide file tree
Showing 34 changed files with 782 additions and 362 deletions.
18 changes: 17 additions & 1 deletion src/Actions/Factory/FactoryContractMakeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use KoalaFacade\DiamondConsole\Actions\Composer\ResolveComposerAutoLoaderAction;
use KoalaFacade\DiamondConsole\Commands\Concerns\InteractsWithConsole;
use KoalaFacade\DiamondConsole\Contracts\Console;
use KoalaFacade\DiamondConsole\DataTransferObjects\NamespaceData;
Expand Down Expand Up @@ -42,8 +44,8 @@ public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: 'Shared',
structures: $this->resolveDomainArgument(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Contracts\\Database\\Factories',
)
Expand All @@ -68,10 +70,24 @@ public function resolveNameArgument(): string
return Str::replaceLast(search: 'Factory', replace: '', subject: $this->console->resolveNameArgument());
}

public function resolveDomainArgument(): string
{
return $this->console->resolveDomainArgument();
}

public function afterCreate(): void
{
$this->console->info(
string: 'Succeed generate Factory Interface at ' . $this->getFullPath()
);
}

public function beforeCreate(): void
{
$filesystem = new Filesystem;

if (! $filesystem->exists(Source::resolveBasePath() . '/Shared')) {
ResolveComposerAutoLoaderAction::resolve()->execute(domain: 'Shared');
}
}
}
92 changes: 92 additions & 0 deletions src/Actions/Model/ModelContractMakeAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace KoalaFacade\DiamondConsole\Actions\Model;

use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem;
use KoalaFacade\DiamondConsole\Actions\Composer\ResolveComposerAutoLoaderAction;
use KoalaFacade\DiamondConsole\Commands\Concerns\InteractsWithConsole;
use KoalaFacade\DiamondConsole\Contracts\Console;
use KoalaFacade\DiamondConsole\DataTransferObjects\NamespaceData;
use KoalaFacade\DiamondConsole\DataTransferObjects\PlaceholderData;
use KoalaFacade\DiamondConsole\Exceptions\FileAlreadyExistException;
use KoalaFacade\DiamondConsole\Foundation\Action;
use KoalaFacade\DiamondConsole\Support\Source;

readonly class ModelContractMakeAction extends Action implements Console
{
use InteractsWithConsole;

public function __construct(
protected Console & Command $console
) {
}

/**
* @throws FileNotFoundException
* @throws FileAlreadyExistException
*/
public function execute(): static
{
$this->handle();

return $this;
}

public function getStubPath(): string
{
return Source::resolveStubForPath(name: 'infrastructure/model-contract');
}

public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
domainArgument: 'Shared',
structures: $this->resolveDomainArgument(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Contracts\\Database\\Models',
)
);
}

public function resolvePlaceholders(): PlaceholderData
{
return new PlaceholderData(
namespace: $this->getNamespace(),
class: $this->getClassName()
);
}

public function resolveForceOption(): bool
{
return $this->console->resolveForceOption();
}

public function resolveNameArgument(): string
{
return $this->console->resolveNameArgument();
}

public function resolveDomainArgument(): string
{
return $this->console->resolveDomainArgument();
}

public function afterCreate(): void
{
$this->console->info(
string: 'Succeed generate Model Interface at ' . $this->getFullPath()
);
}

public function beforeCreate(): void
{
$filesystem = new Filesystem;

if (! $filesystem->exists(Source::resolveBasePath() . '/Shared')) {
ResolveComposerAutoLoaderAction::resolve()->execute(domain: 'Shared');
}
}
}
93 changes: 93 additions & 0 deletions src/Actions/Repository/RepositoryContractMakeAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace KoalaFacade\DiamondConsole\Actions\Repository;

use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use KoalaFacade\DiamondConsole\Actions\Composer\ResolveComposerAutoLoaderAction;
use KoalaFacade\DiamondConsole\Commands\Concerns\InteractsWithConsole;
use KoalaFacade\DiamondConsole\Contracts\Console;
use KoalaFacade\DiamondConsole\DataTransferObjects\NamespaceData;
use KoalaFacade\DiamondConsole\DataTransferObjects\PlaceholderData;
use KoalaFacade\DiamondConsole\Exceptions\FileAlreadyExistException;
use KoalaFacade\DiamondConsole\Foundation\Action;
use KoalaFacade\DiamondConsole\Support\Source;

readonly class RepositoryContractMakeAction extends Action implements Console
{
use InteractsWithConsole;

public function __construct(
protected Console & Command $console
) {
}

/**
* @throws FileNotFoundException
* @throws FileAlreadyExistException
*/
public function execute(): static
{
$this->handle();

return $this;
}

public function getStubPath(): string
{
return Source::resolveStubForPath(name: 'infrastructure/repository-contract');
}

public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
domainArgument: 'Shared',
structures: $this->resolveDomainArgument(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Contracts\\Repositories',
)
);
}

public function resolvePlaceholders(): PlaceholderData
{
return new PlaceholderData(
namespace: $this->getNamespace(),
class: $this->getClassName()
);
}

public function resolveForceOption(): bool
{
return $this->console->resolveForceOption();
}

public function resolveNameArgument(): string
{
return Str::replaceLast(search: 'Repository', replace: '', subject: $this->console->resolveNameArgument());
}

public function resolveDomainArgument(): string
{
return $this->console->resolveDomainArgument();
}

public function afterCreate(): void
{
$this->console->info(
string: 'Succeed generate Repository Interface at ' . $this->getFullPath()
);
}

public function beforeCreate(): void
{
$filesystem = new Filesystem;

if (! $filesystem->exists(Source::resolveBasePath() . '/Shared')) {
ResolveComposerAutoLoaderAction::resolve()->execute(domain: 'Shared');
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/Concerns/HasArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
trait HasArguments
{
protected function resolveDomainArgument(): string
public function resolveDomainArgument(): string
{
/** @var string $argument */
$argument = $this->argument(key: 'domain');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace KoalaFacade\DiamondConsole\Commands\Domain;
namespace KoalaFacade\DiamondConsole\Commands\Infrastructure;

use Illuminate\Console\Command;
use KoalaFacade\DiamondConsole\Commands\Concerns\HasArguments;
Expand All @@ -15,7 +15,7 @@ class BuilderMakeCommand extends Command implements Console
{
use HasArguments, HasOptions, InteractsWithConsole;

protected $signature = 'domain:make:builder {name} {domain} {--model=} {--force}';
protected $signature = 'infrastructure:make:builder {name} {domain} {--model=} {--force}';

protected $description = 'Create a new query builder';

Expand All @@ -33,17 +33,17 @@ public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: 'Shared\\' . $this->resolveDomainArgument(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveInfrastructurePath(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Models\\Builders',
endsWith: 'Database\\Models\\Builders',
)
);
}

public function getStubPath(): string
{
$stub = 'domain/builder';
$stub = 'infrastructure/builder';

if ($this->resolveModelOption()) {
$stub .= '-model';
Expand All @@ -67,10 +67,10 @@ public function resolveModelNamespace(): ?string
if ($this->resolveModelOption()) {
$namespace = Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: 'Shared\\' . $this->resolveDomainArgument(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveInfrastructurePath(),
nameArgument: $this->resolveModelOption(),
endsWith: 'Models\\' . $this->resolveModelOption(),
endsWith: 'Database\\Models',
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Infrastructure/EventMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveInfrastructurePath(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveInfrastructurePath(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Events',
)
Expand Down
12 changes: 6 additions & 6 deletions src/Commands/Infrastructure/FactoryMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function resolvePlaceholders(): PlaceholderData
return new PlaceholderData(
namespace: $this->getNamespace(),
class: $this->resolveNameArgument(),
factoryContract: $this->factoryContractMakeAction->getClassName(),
factoryContractNamespace: $this->factoryContractMakeAction->getNamespace(),
contractName: $this->factoryContractMakeAction->getClassName(),
contractNamespace: $this->factoryContractMakeAction->getNamespace(),
model: $this->resolveModelName(),
modelNamespace: $this->getModelNamespace(),
);
Expand All @@ -64,10 +64,10 @@ protected function getModelNamespace(): ?string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveDomainPath(),
domainArgument: 'Shared\\' . $this->resolveDomainArgument(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveInfrastructurePath(),
nameArgument: $this->resolveModelName(),
endsWith: 'Models',
endsWith: 'Database\\Models',
)
);
}
Expand All @@ -89,8 +89,8 @@ public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveInfrastructurePath(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveInfrastructurePath(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Database\\Factories',
)
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Infrastructure/ListenerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveInfrastructurePath(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveInfrastructurePath(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Listeners',
)
Expand Down Expand Up @@ -73,8 +73,8 @@ public function resolveEventNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveInfrastructurePath(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveInfrastructurePath(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Events\\' . $this->resolveEventOption(),
)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Infrastructure/MailMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function getNamespace(): string
{
return Source::resolveNamespace(
data: new NamespaceData(
structures: Source::resolveInfrastructurePath(),
domainArgument: $this->resolveDomainArgument(),
structures: Source::resolveInfrastructurePath(),
nameArgument: $this->resolveNameArgument(),
endsWith: 'Mails',
)
Expand Down
Loading

0 comments on commit 14a823e

Please sign in to comment.