Skip to content

Commit 4a8c56b

Browse files
committed
Create an alias command and mark the old style as deprecated for future major release.
1 parent ef3341a commit 4a8c56b

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Coderflex\LaravelPresenter\Console;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class PresenterMakeCommand extends GeneratorCommand
8+
{
9+
public $name = 'presenter:make';
10+
11+
public $description = '(Deprecated) Create a new presenter class';
12+
13+
/**
14+
* The type of class being generated.
15+
*
16+
* @var string
17+
*/
18+
protected $type = 'Presenter';
19+
20+
/**
21+
* Determine if the class already exists.
22+
*
23+
* @param string $rawName
24+
* @return bool
25+
*/
26+
protected function alreadyExists($rawName)
27+
{
28+
return class_exists($rawName) ||
29+
$this->files->exists($this->getPath($this->qualifyClass($rawName)));
30+
}
31+
32+
/**
33+
* Get the stub file for the generator.
34+
*
35+
* @return string
36+
*/
37+
protected function getStub()
38+
{
39+
return $this->resolveStubPath('/stubs/presenter.stub');
40+
}
41+
42+
/**
43+
* Resolve the fully-qualified path to the stub.
44+
*
45+
* @param string $stub
46+
* @return string
47+
*/
48+
protected function resolveStubPath($stub)
49+
{
50+
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
51+
? $customPath
52+
: __DIR__ . $stub;
53+
}
54+
55+
/**
56+
* Get the default namespace for the class.
57+
*
58+
* @param string $rootNamespace
59+
* @return string
60+
*/
61+
protected function getDefaultNamespace($rootNamespace)
62+
{
63+
$configNamespace = config('laravel-presenter.presenter_namespace');
64+
65+
return is_null($configNamespace)
66+
? $rootNamespace . '\Presenters'
67+
: $configNamespace;
68+
}
69+
}

0 commit comments

Comments
 (0)