From 98efa3864842e36219f58826ba21843d3890b388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jir=CC=8Ci=CC=81=20Pudil?= Date: Mon, 15 May 2017 14:53:25 +0200 Subject: [PATCH] fixed compatibility with nette/php-generator:3.0.0 --- composer.json | 3 ++- src/DI/ProxyExtension.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index dbc32e5..cf9b51d 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ ], "require": { "ocramius/proxy-manager": "^2.0", - "nette/di": "^2.4" + "nette/di": "^2.4", + "nette/php-generator": "^2.6|^3.0" }, "require-dev": { "phpunit/phpunit": "^5.6", diff --git a/src/DI/ProxyExtension.php b/src/DI/ProxyExtension.php index 38ba69f..0822fee 100644 --- a/src/DI/ProxyExtension.php +++ b/src/DI/ProxyExtension.php @@ -9,7 +9,7 @@ use Nette\DI\Helpers; use Nette\DI\Statement; use Nette\PhpGenerator\ClassType; -use Nette\PhpGenerator\Method; +use Nette\PhpGenerator\Closure; use Nette\Utils\Validators; use ProxyManager\Configuration; use ProxyManager\Factory\LazyLoadingValueHolderFactory; @@ -116,8 +116,8 @@ public function afterCompile(ClassType $class) // modify original method body to return proxy instead $method = $class->getMethod(Container::getMethodName($name)); $method->setBody(sprintf( - "return \$this->getService('%s')->createProxy(\n\t%s::class,\n\tfunction (&\$wrappedObject, \$proxy, \$method, \$parameters, &\$initializer) {\n\t\t\$wrappedObject = (%s)();\n\t\t\$initializer = null;\n\t}\n);", - $this->prefix('lazyLoadingValueHolderFactory'), $type, ltrim(preg_replace('#^#m', "\t\t", (new Method())->addBody($method->getBody()))) + "return \$this->getService('%s')->createProxy(\n\t%s::class,\n\tfunction (&\$wrappedObject, \$proxy, \$method, \$parameters, &\$initializer) {\n\t\t\$wrappedObject = (%s)();\n\t\t\$initializer = null;\n\t\treturn true;\n\t}\n);", + $this->prefix('lazyLoadingValueHolderFactory'), $type, ltrim(preg_replace('#^#m', "\t\t", (new Closure())->addBody($method->getBody()))) )); }