-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make facade, more trait templates, signatures
- Loading branch information
Showing
13 changed files
with
225 additions
and
10 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
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,91 @@ | ||
<?php | ||
|
||
namespace Creativeorange\LaravelStubs\Console\Make; | ||
|
||
use Creativeorange\LaravelStubs\Console\CustomGeneratorCommand; | ||
use Illuminate\Support\Str; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
class MakeFacade extends CustomGeneratorCommand | ||
{ | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'make:facade'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new facade'; | ||
|
||
protected $signature = 'make:facade | ||
{name : The name of the facade} | ||
{accessor : The accessor for the facade}'; | ||
|
||
protected $type = 'Facade'; | ||
|
||
public function handle() | ||
{ | ||
parent::handle(); | ||
} | ||
|
||
protected function getStub() | ||
{ | ||
|
||
return $this->resolveStubPath('/../stubs/facade.stub'); | ||
} | ||
|
||
protected function replaceNamespace(&$stub, $name) | ||
{ | ||
$this->parseAccessor($stub); | ||
|
||
return parent::replaceNamespace($stub, $name); | ||
} | ||
|
||
protected function parseAccessor(&$stub) | ||
{ | ||
|
||
$accessor = $this->argument('accessor'); | ||
$accessor = Str::endsWith($accessor, '/') | ||
? $accessor | ||
: '/' . $accessor; | ||
|
||
$accessor = \str_replace('/', '\\', $accessor); | ||
|
||
$stub = \str_replace('DummyAccessor', $accessor, $stub); | ||
} | ||
|
||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
|
||
return (empty(config('laravel-stubs.make.facade.namespace'))) | ||
? $rootNamespace | ||
: config('laravel-stubs.make.facade.namespace'); | ||
} | ||
|
||
protected function getNameInput() | ||
{ | ||
|
||
$name = trim($this->argument('name')); | ||
|
||
$name = Str::endsWith($name, 'Facade') | ||
? $name | ||
: $name . 'Facade'; | ||
|
||
return $name; | ||
} | ||
|
||
protected function getArguments() | ||
{ | ||
return [ | ||
['name', InputArgument::REQUIRED, 'The name of the facade'], | ||
['accessor', InputArgument::REQUIRED, 'The accessor for the facade'] | ||
]; | ||
} | ||
} |
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
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
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
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,21 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
/** | ||
* Class DummyClass | ||
* @package DummyNamespace | ||
*/ | ||
class DummyClass extends Facade | ||
{ | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return DummyAccessor::class; | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
trait DummyClass | ||
{ | ||
|
||
/** | ||
* Bootstrap the trait. | ||
* | ||
* The following functions can be called statically: | ||
* retrieved, creating, created, updating, updated, | ||
* saving, saved, deleting, deleted, restoring, restored | ||
* | ||
* @return void | ||
*/ | ||
public static function bootDummyClass(): void | ||
{ | ||
|
||
static::deleted(function ($model) { | ||
|
||
foreach (self::$anonymousFields as $field) { | ||
$model->$field = null; | ||
} | ||
|
||
$model->save(); | ||
}); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
trait DummyClass | ||
{ | ||
|
||
/** | ||
* Bootstrap the trait. | ||
* | ||
* The following functions can be called statically: | ||
* retrieved, creating, created, updating, updated, | ||
* saving, saved, deleting, deleted, restoring, restored | ||
* | ||
* @return void | ||
*/ | ||
public static function bootDummyClass(): void | ||
{ | ||
|
||
static::creating(function ($model) { | ||
|
||
$model->$uuidField = Str::uuid(); | ||
}); | ||
} | ||
} |