|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Modelarium; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Inflector\InflectorFactory; |
|
6
|
|
|
use GraphQL\Type\Definition\Type; |
|
7
|
|
|
use Illuminate\Support\Str; |
|
8
|
|
|
use Modelarium\Exception\Exception; |
|
9
|
|
|
use Modelarium\GeneratedCollection; |
|
10
|
|
|
use Modelarium\Parser; |
|
11
|
|
|
|
|
12
|
|
|
trait GeneratorNameTrait |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $name = ''; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $studlyName = ''; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $lowerName = ''; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $lowerNamePlural = ''; |
|
33
|
|
|
|
|
34
|
|
|
public function getInflector(): \Doctrine\Inflector\Inflector |
|
35
|
|
|
{ |
|
36
|
|
|
static $inflector = null; |
|
37
|
|
|
if (!$inflector) { |
|
38
|
|
|
$inflector = InflectorFactory::create()->build(); |
|
39
|
|
|
} |
|
40
|
|
|
return $inflector; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function setName(string $name): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->name = $name; |
|
46
|
|
|
$this->studlyName = Str::studly($this->name); |
|
47
|
|
|
$this->lowerName = mb_strtolower($this->name); |
|
48
|
|
|
$this->lowerNamePlural = $this->getInflector()->pluralize($this->lowerName); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function splitClassName(string $fullclass): array |
|
52
|
|
|
{ |
|
53
|
|
|
$classTokens = explode('\\', $fullclass); |
|
54
|
|
|
$className = array_pop($classTokens); |
|
55
|
|
|
$classNamespace = implode('\\', $classTokens); |
|
56
|
|
|
$relativePath = implode('/', $classTokens); |
|
57
|
|
|
return [$classNamespace, $className, $relativePath]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the base path (where composer.json is located) |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $file The filename |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public static function getBasePath(string $file = null): string |
|
67
|
|
|
{ |
|
68
|
|
|
$basepath = dirname(\Composer\Factory::getComposerFile()); |
|
69
|
|
|
if ($file) { |
|
70
|
|
|
$basepath .= '/' . $file; |
|
71
|
|
|
} |
|
72
|
|
|
return $basepath; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get the value of name |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getName() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->name; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get the value of studlyName |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getStudlyName() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->studlyName; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|