diff --git a/src/DI/PhpGenerator.php b/src/DI/PhpGenerator.php index 8a1a66835..9b4ff9ef2 100644 --- a/src/DI/PhpGenerator.php +++ b/src/DI/PhpGenerator.php @@ -12,8 +12,7 @@ use Nette; use Nette\DI\Definitions\Reference; use Nette\DI\Definitions\Statement; -use Nette\PhpGenerator\Helpers as PhpHelpers; -use Nette\PhpGenerator\PhpLiteral; +use Nette\PhpGenerator as Php; use Nette\Utils\Strings; @@ -40,10 +39,10 @@ public function __construct(ContainerBuilder $builder) /** * Generates PHP classes. First class is the container. */ - public function generate(string $className): Nette\PhpGenerator\ClassType + public function generate(string $className): Php\ClassType { $this->className = $className; - $class = new Nette\PhpGenerator\ClassType($this->className); + $class = new Php\ClassType($this->className); $class->setExtends(Container::class); $class->addMethod('__construct') ->addBody('parent::__construct($params);') @@ -73,7 +72,7 @@ public function generate(string $className): Nette\PhpGenerator\ClassType } - public function toString(Nette\PhpGenerator\ClassType $class): string + public function toString(Php\ClassType $class): string { return '/** @noinspection PhpParamsInspection,PhpMethodMayBeStaticInspection */ @@ -83,7 +82,7 @@ public function toString(Nette\PhpGenerator\ClassType $class): string } - public function addInitialization(Nette\PhpGenerator\ClassType $class, CompilerExtension $extension): void + public function addInitialization(Php\ClassType $class, CompilerExtension $extension): void { $closure = $extension->getInitialization(); if ($closure->getBody()) { @@ -94,11 +93,11 @@ public function addInitialization(Nette\PhpGenerator\ClassType $class, CompilerE } - public function generateMethod(Definitions\Definition $def): Nette\PhpGenerator\Method + public function generateMethod(Definitions\Definition $def): Php\Method { $name = $def->getName(); try { - $method = new Nette\PhpGenerator\Method(Container::getMethodName($name)); + $method = new Php\Method(Container::getMethodName($name)); $method->setPublic(); $method->setReturnType($def->getType()); $def->generateMethod($method, $this); @@ -171,33 +170,33 @@ public function formatPhp(string $statement, array $args): string { array_walk_recursive($args, function (&$val): void { if ($val instanceof Statement) { - $val = new PhpLiteral($this->formatStatement($val)); + $val = new Php\Literal($this->formatStatement($val)); } elseif ($val instanceof Reference) { $name = $val->getValue(); if ($val->isSelf()) { - $val = new PhpLiteral('$service'); + $val = new Php\Literal('$service'); } elseif ($name === ContainerBuilder::THIS_CONTAINER) { - $val = new PhpLiteral('$this'); + $val = new Php\Literal('$this'); } else { $val = ContainerBuilder::literal('$this->getService(?)', [$name]); } } }); - return PhpHelpers::formatArgs($statement, $args); + return Php\Helpers::formatArgs($statement, $args); } /** * Converts parameters from Definition to PhpGenerator. - * @return Nette\PhpGenerator\Parameter[] + * @return Php\Parameter[] */ public function convertParameters(array $parameters): array { $res = []; foreach ($parameters as $k => $v) { $tmp = explode(' ', is_int($k) ? $v : $k); - $param = $res[] = new Nette\PhpGenerator\Parameter(end($tmp)); + $param = $res[] = new Php\Parameter(end($tmp)); if (!is_int($k)) { $param->setDefaultValue($v); }