Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Sep 18, 2023
1 parent 08c51a8 commit 347115f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Commands/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class GeneratorCommand extends \Illuminate\Console\GeneratorCommand imp
{
use Concerns\CodeGenerator;
use Concerns\TestGenerator;
use Concerns\UsesGeneratorOverrides;

/**
* Create a new controller creator command instance.
Expand Down
7 changes: 6 additions & 1 deletion src/Concerns/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ protected function getPath($name)
{
$name = Str::replaceFirst($this->rootNamespace(), '', $name);

return $this->generatorPreset()->sourcePath().'/'.str_replace('\\', '/', $name).'.php';
return $this->getSourcePath().'/'.str_replace('\\', '/', $name).'.php';
}

protected function getSourcePath()
{
return $this->generatorPreset()->sourcePath();
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/Concerns/CreatesUsingGeneratorPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ protected function generatorPreset()
{
return $this->laravel->make(PresetManager::class)->driver($this->option('preset'));
}


/**
* Get the generator preset source path.
*/
protected function getGeneratorSourcePath(): string
{
return $this->generatorPreset()->sourcePath();
}
}
52 changes: 52 additions & 0 deletions src/Concerns/UsesGeneratorOverrides.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Orchestra\Canvas\Core\Concerns;

trait UsesGeneratorOverrides
{
/**
* Get the destination class path.
*
* @param string $name
* @return string
*/
protected function getPath($name)
{
$name = Str::replaceFirst($this->rootNamespace(), '', $name);

return $this->getGeneratorSourcePath().'/'.str_replace('\\', '/', $name).'.php';
}

/**
* Get the root namespace for the class.
*
* @return string
*/
protected function rootNamespace()
{
return $this->generatorPreset()->rootNamespace();
}

/**
* Get the model for the default guard's user provider.
*
* @return string|null
*/
protected function userProviderModel()
{
return $this->generatorPreset()->userProviderModel();
}

/**
* Get the first view directory path from the application configuration.
*
* @param string $path
* @return string
*/
protected function viewPath($path = '')
{
$views = $this->generatorPreset()->viewPath();

return $views.($path ? DIRECTORY_SEPARATOR.$path : $path);
}
}

0 comments on commit 347115f

Please sign in to comment.