Repository navigation
Expand file tree
/
Copy pathResourceCommand.php
More file actions
59 lines (50 loc) · 1.54 KB
/
Copy pathResourceCommand.php
File metadata and controls
59 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Devtool\Generator;
use Hyperf\Command\Annotation\Command;
use Hyperf\Stringable\Str;
use Symfony\Component\Console\Input\InputOption;
#[Command]
class ResourceCommand extends GeneratorCommand
{
public function __construct()
{
parent::__construct('gen:resource');
}
public function configure()
{
parent::configure();
$this->setDescription('create a new resource');
$this->addOption('collection', 'c', InputOption::VALUE_NONE, 'Create a resource collection');
$this->addOption('grpc', null, InputOption::VALUE_NONE, 'Create a grpc resource');
}
protected function getStub(): string
{
return $this->isGrpc()
? __DIR__ . '/stubs/resource-grpc.stub'
: ($this->isCollection()
? __DIR__ . '/stubs/resource-collection.stub'
: __DIR__ . '/stubs/resource.stub');
}
protected function getDefaultNamespace(): string
{
return $this->getConfig()['namespace'] ?? 'App\Resource';
}
protected function isCollection(): bool
{
return $this->input->getOption('collection')
|| Str::endsWith($this->input->getArgument('name'), 'Collection');
}
protected function isGrpc(): bool
{
return $this->input->getOption('grpc');
}
}