1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Modelarium; |
4
|
|
|
|
5
|
|
|
use Formularium\Formularium; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
use Nette\PhpGenerator\PhpNamespace; |
8
|
|
|
|
9
|
|
|
final class Util |
10
|
|
|
{ |
11
|
|
|
protected const HEADER = |
12
|
|
|
'<?php declare(strict_types=1); |
13
|
|
|
/** |
14
|
|
|
* This file is automatically generated by Formularium. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
'; |
18
|
|
|
|
19
|
|
|
public static function scalars(): string |
20
|
|
|
{ |
21
|
|
|
$graphql = [ |
22
|
|
|
'""" |
23
|
|
|
This file is auto generated. |
24
|
|
|
"""' |
25
|
|
|
]; |
26
|
|
|
$printer = new \Nette\PhpGenerator\PsrPrinter; |
27
|
|
|
$datatypes = Formularium::getDatatypeNames(); |
28
|
|
|
foreach ($datatypes as $name) { |
29
|
|
|
$typeName = Str::studly($name); |
30
|
|
|
|
31
|
|
|
if ($typeName === 'String' || |
32
|
|
|
$typeName === 'Boolean' || |
33
|
|
|
$typeName === 'Int' || |
34
|
|
|
$typeName === 'Float' |
35
|
|
|
) { |
36
|
|
|
// base types |
37
|
|
|
continue; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$ns = 'Modelarium\\Types'; |
41
|
|
|
$namespace = new PhpNamespace($ns); |
42
|
|
|
$namespace->addClass('Datatype_' . $name) |
43
|
|
|
->setExtends('FormulariumScalarType'); |
44
|
|
|
|
45
|
|
|
$stub = self::HEADER . $printer->printNamespace($namespace); |
|
|
|
|
46
|
|
|
|
47
|
|
|
// TODO $filename = __DIR__ . '/../Modelarium/Types/Datatype_' . $name . '.php'; |
48
|
|
|
// TODO \Safe\file_put_contents($filename, $stub); |
49
|
|
|
|
50
|
|
|
$graphql[] = "scalar $typeName @scalar(class: \"" . |
51
|
|
|
str_replace('\\', '\\\\', $ns . '\\Datatype_' . $name) . |
52
|
|
|
"\")"; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return implode("\n\n", $graphql); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* TODO |
60
|
|
|
* @throws |
61
|
|
|
* |
62
|
|
|
public static generateDirectives(string $filename): void |
63
|
|
|
{ |
64
|
|
|
\Safe\file_put_contents( |
65
|
|
|
$filename |
66
|
|
|
LaravelProcessor::getDirectivesGraphqlString() |
67
|
|
|
); |
68
|
|
|
} */ |
69
|
|
|
} |
70
|
|
|
|