diff --git a/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php b/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php index 4e32501..f2e25c5 100644 --- a/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php +++ b/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php @@ -156,11 +156,15 @@ protected function buildMethod(\ReflectionMethod $reflection_method) { $function_name = $reflection_method->getName(); + $reference = ''; + if ($reflection_method->returnsReference()) { + $reference = '&'; + } if ($reflection_method->isStatic()) { - $signature_line = 'public static function ' . $function_name . '('; + $signature_line = 'public static function ' . $reference . $function_name . '('; } else { - $signature_line = 'public function ' . $function_name . '('; + $signature_line = 'public function ' . $reference . $function_name . '('; } $signature_line .= implode(', ', $parameters); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 8a993d6..6d9f4b6 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -7,7 +7,6 @@ namespace Drupal\Core; -use Drupal\Component\ProxyBuilder\ProxyBuilder; use Drupal\Component\ProxyBuilder\ProxyDumper; use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Timer; @@ -24,6 +23,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\PageCache\RequestPolicyInterface; use Drupal\Core\PhpStorage\PhpStorageFactory; +use Drupal\Core\ProxyBuilder\ProxyBuilder; use Drupal\Core\Site\Settings; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php b/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php index 306fdaa..45074a5 100644 --- a/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php +++ b/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php @@ -121,6 +121,28 @@ public function complexMethod($parameter, callable $function, \Drupal\Tests\Comp /** * @covers ::buildMethod() + * @covers ::buildMethodBody() + */ + public function testBuildReturnReference() { + $class = 'Drupal\Tests\Component\ProxyBuilder\TestServiceReturnReference'; + + $result = $this->proxyBuilder->build($class); + + // @todo Solve the silly linebreak for array() + $method_body = <<<'EOS' + + public function &returnReference() + { + return $this->lazyLoadItself()->returnReference(); + } + +EOS; + + $this->assertEquals($this->buildExpectedClass($class, $method_body), $result); + } + + /** + * @covers ::buildMethod() * @covers ::buildParameter() * @covers ::buildMethodBody() */ @@ -281,6 +303,14 @@ public function complexMethod($parameter, callable $function, TestServiceNoMetho } +class TestServiceReturnReference { + + public function &returnReference() { + + } + +} + interface TestInterface { public function testMethod($parameter);