-
-
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.
Signed-off-by: Mior Muhammad Zaki <[email protected]>
- Loading branch information
Showing
14 changed files
with
255 additions
and
31 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
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,34 @@ | ||
<?php | ||
|
||
namespace Orchestra\Canvas\Core; | ||
|
||
use Illuminate\Foundation\Inspiring; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* @see https://github.com/laravel/framework/blob/10.x/src/Illuminate/Foundation/Console/ComponentMakeCommand.php | ||
*/ | ||
class GeneratesCodeWithComponent extends GeneratesCode | ||
{ | ||
/** | ||
* Handle generating code. | ||
*/ | ||
protected function generatingCode(string $stub, string $name): string | ||
{ | ||
$stub = parent::generatingCode($stub, $name); | ||
|
||
if (! empty($this->options['inline'])) { | ||
$stub = str_replace( | ||
['DummyView', '{{ view }}', '{{view}}'], | ||
"<<<'blade'\n<div>\n ".Inspiring::quote()."\n</div>\nblade", | ||
$stub | ||
); | ||
} | ||
|
||
return str_replace( | ||
['DummyView', '{{ view }}', '{{view}}'], | ||
'view(\'components.'.Str::kebab(class_basename($name)).'\')', | ||
$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,87 @@ | ||
<?php | ||
|
||
namespace Orchestra\Canvas\Core; | ||
|
||
use Illuminate\Support\Str; | ||
use InvalidArgumentException; | ||
|
||
/** | ||
* @see https://github.com/laravel/framework/blob/10.x/src/Illuminate/Foundation/Console/ObserverMakeCommand.php | ||
*/ | ||
class GeneratesCodeWithEloquent extends GeneratesCode | ||
{ | ||
/** | ||
* Handle generating code. | ||
*/ | ||
protected function generatingCode(string $stub, string $name): string | ||
{ | ||
$stub = parent::generatingCode($stub, $name); | ||
|
||
$model = $this->options['model']; | ||
|
||
return ! empty($model) ? $this->replaceModel($stub, $model) : $stub; | ||
} | ||
|
||
/** | ||
* Replace the model for the given stub. | ||
*/ | ||
protected function replaceModel(string $stub, string $model): string | ||
{ | ||
$modelClass = $this->parseModel($model); | ||
|
||
$replace = [ | ||
'DummyFullModelClass' => $modelClass, | ||
'{{ namespacedModel }}' => $modelClass, | ||
'{{namespacedModel}}' => $modelClass, | ||
'DummyModelClass' => class_basename($modelClass), | ||
'{{ model }}' => class_basename($modelClass), | ||
'{{model}}' => class_basename($modelClass), | ||
'DummyModelVariable' => lcfirst(class_basename($modelClass)), | ||
'{{ modelVariable }}' => lcfirst(class_basename($modelClass)), | ||
'{{modelVariable}}' => lcfirst(class_basename($modelClass)), | ||
]; | ||
|
||
return str_replace( | ||
array_keys($replace), array_values($replace), $stub | ||
); | ||
} | ||
|
||
/** | ||
* Get the fully-qualified model class name. | ||
* | ||
* @param string $model | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
protected function parseModel($model): string | ||
{ | ||
if (preg_match('([^A-Za-z0-9_/\\\\])', $model)) { | ||
throw new InvalidArgumentException('Model name contains invalid characters.'); | ||
} | ||
|
||
return $this->qualifyModel($model); | ||
} | ||
|
||
/** | ||
* Qualify the given model class base name. | ||
*/ | ||
protected function qualifyModel(string $model): string | ||
{ | ||
$model = ltrim($model, '\\/'); | ||
|
||
$model = str_replace('/', '\\', $model); | ||
|
||
$rootNamespace = $this->rootNamespace(); | ||
$namespaceModel = $this->preset->modelNamespace().'\\'.$model; | ||
|
||
if (Str::startsWith($model, $namespaceModel)) { | ||
return $model; | ||
} elseif (! \is_null($this->preset->config('model.namespace'))) { | ||
return $namespaceModel; | ||
} | ||
|
||
return is_dir($this->preset->sourcePath().'/Models') | ||
? $rootNamespace.'Models\\'.$model | ||
: $namespaceModel; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace Orchestra\Canvas\Core; | ||
|
||
class GeneratesCodeWithMarkdown extends GeneratesCode | ||
{ | ||
/** | ||
* Handle generating code. | ||
*/ | ||
protected function generatingCode(string $stub, string $name): string | ||
{ | ||
$stub = parent::generatingCode($stub, $name); | ||
|
||
if (! empty($this->options['view'])) { | ||
$stub = str_replace(['DummyView', '{{ view }}', '{{view}}'], $this->options['view'], $stub); | ||
} | ||
|
||
return $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
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
Oops, something went wrong.