This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added test for generate-tools command and refactored the command to make it cleaner. - Added test for init-command.
- Loading branch information
1 parent
5b95b16
commit 00908b9
Showing
13 changed files
with
403 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Support\Artifacts; | ||
|
||
abstract class AbstractArtifact implements Artifact | ||
{ | ||
/** | ||
* Create a new instance of the Artifact. | ||
* | ||
* @param array $args | ||
* | ||
* @return Artifact | ||
*/ | ||
public static function make(...$args): Artifact | ||
{ | ||
return new static(...$args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Support\Artifacts; | ||
|
||
interface Artifact | ||
{ | ||
/** | ||
* Create a new instance of the Artifact. | ||
* | ||
* @param array $args | ||
* | ||
* @return Artifact | ||
*/ | ||
public static function make(...$args): Artifact; | ||
|
||
/** | ||
* Saves the artifact and return true | ||
* if saved was successful. | ||
* | ||
* @return bool | ||
*/ | ||
public function save(): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Support\Artifacts; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class Containers extends AbstractArtifact | ||
{ | ||
/** | ||
* The path of the stub file. | ||
* | ||
* @var string | ||
*/ | ||
protected $stub; | ||
|
||
/** | ||
* Containers constructor. | ||
* | ||
* @param string $stubPath | ||
*/ | ||
public function __construct(string $stubPath = null) | ||
{ | ||
$this->stub = $stubPath ?? $this->stubDefaultPath(); | ||
} | ||
|
||
/** | ||
* Saves the artifact and return true | ||
* if saved was successful. | ||
* | ||
* @return bool | ||
*/ | ||
public function save(): bool | ||
{ | ||
// Copy file to Working directory. | ||
$wasSaved = Storage::disk('work_dir')->put('containers', $this->stubContents()); | ||
|
||
// Make file executed. | ||
app(Filesystem::class)->chmod( | ||
Storage::disk('work_dir')->path('containers'), 0755 | ||
); | ||
|
||
return $wasSaved; | ||
} | ||
|
||
/** | ||
* Get the command line tools content. | ||
* | ||
* @return string | ||
*/ | ||
protected function stubContents(): string | ||
{ | ||
return file_get_contents($this->stub); | ||
} | ||
|
||
/** | ||
* Get the default path where containers stub is | ||
* stored. | ||
* | ||
* @return string | ||
*/ | ||
protected function stubDefaultPath(): string | ||
{ | ||
return app_path('Commands' . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'containers.stub'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Support\Concerns; | ||
|
||
trait CommandResponsable | ||
{ | ||
/** | ||
* Show a sucess message and the exit the program. | ||
* | ||
* @param string $message | ||
* | ||
* @return bool | ||
*/ | ||
protected function sendSuccessResponse(string $message = null): bool | ||
{ | ||
$message = $message ?? 'Command successfully ran!'; | ||
|
||
$this->info($message); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Show an error message and then exits the program. | ||
* | ||
* @param string $message | ||
* | ||
* @return bool | ||
*/ | ||
protected function sendErrorResponse(string $message = null): bool | ||
{ | ||
$message = $message ?? 'Command failed !'; | ||
|
||
$this->error($message); | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.