forked from rebing/graphql-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputMakeCommand.php
45 lines (36 loc) · 1.14 KB
/
InputMakeCommand.php
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
<?php
declare(strict_types = 1);
namespace Rebing\GraphQL\Console;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand('make:graphql:input')]
class InputMakeCommand extends GeneratorCommand
{
protected $signature = 'make:graphql:input {name}';
protected $description = 'Create a new GraphQL input class';
protected $type = 'Input';
protected function getStub(): string
{
return __DIR__ . '/stubs/input.stub';
}
protected function getDefaultNamespace($rootNamespace): string
{
return $rootNamespace . '\GraphQL\Inputs';
}
protected function buildClass($name): string
{
$stub = parent::buildClass($name);
return $this->replaceGraphqlName($stub);
}
protected function replaceGraphqlName(string $stub): string
{
$graphqlName = $this->getNameInput();
$graphqlName = str_replace('InputObject', 'Input', $graphqlName);
$graphqlName = \Safe\preg_replace('/Type$/', '', $graphqlName);
return str_replace(
'DummyGraphqlName',
$graphqlName,
$stub
);
}
}