for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace Modelarium;
use GraphQL\Type\Definition\Type;
use Modelarium\Exception\Exception;
use Modelarium\Parser;
use function Safe\class_implements;
use function Safe\date;
abstract class BaseGenerator implements GeneratorInterface
{
use GeneratorNameTrait;
/**
* @var string
*/
protected $stubDir = null;
* @var Parser
protected $parser = null;
* @var Type
protected $type = null;
* @param Parser $parser
* @param string $name The target type name.
* @param Type|string $type
public function __construct(Parser $parser, string $name, $type = null)
$this->parser = $parser;
$this->setBaseName($name);
if ($type instanceof Type) {
$this->type = $type;
} elseif (!$type) {
$this->type = $parser->getSchema()->getType($name);
} else {
throw new Exception('Invalid model');
}
protected function phpHeader(): string
$date = date('c');
return <<<EOF
* This file was automatically generated by Modelarium on $date
EOF;
* Gets the classname for a directive implementation interface class.
*
* @param string $directive The directive name.
* @param string $type
* @return string|null
protected function getDirectiveClass(
string $directive,
string $type = ''
): ?string {
$ns = 'Modelarium\\Laravel\\Directives';
$className = $ns . '\\' . ucfirst($directive);
if (!$type) {
$type = str_replace('Generator', '', get_called_class());
if (class_exists($className) && in_array($type . 'DirectiveInterface', class_implements($className))) {
return $className;
return null;