Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6fb67d5

Browse files
[Bridge\ProxyManager] Dont call __destruct() on non-instantiated services
1 parent8f5141d commit6fb67d5

File tree

6 files changed

+86
-2
lines changed

6 files changed

+86
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bridge\ProxyManager\LazyProxy\Instantiator;
13+
14+
useProxyManager\ProxyGenerator\ProxyGeneratorInterface;
15+
useProxyManager\Factory\LazyLoadingValueHolderFactoryasBaseFactory;
16+
useSymfony\Bridge\ProxyManager\LazyProxy\PhpDumper\LazyLoadingValueHolderGenerator;
17+
18+
/**
19+
* @internal
20+
*/
21+
class LazyLoadingValueHolderFactoryextends BaseFactory
22+
{
23+
private$generator;
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
protectedfunctiongetGenerator() :ProxyGeneratorInterface
29+
{
30+
return$this->generator ?:$this->generator =newLazyLoadingValueHolderGenerator();
31+
}
32+
}

‎src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespaceSymfony\Bridge\ProxyManager\LazyProxy\Instantiator;
1313

1414
useProxyManager\Configuration;
15-
useProxyManager\Factory\LazyLoadingValueHolderFactory;
1615
useProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
1716
useProxyManager\Proxy\LazyLoadingInterface;
1817
useSymfony\Component\DependencyInjection\ContainerInterface;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bridge\ProxyManager\LazyProxy\PhpDumper;
13+
14+
useProxyManager\ProxyGenerator\LazyLoadingValueHolderGeneratorasBaseGenerator;
15+
useZend\Code\Generator\ClassGenerator;
16+
17+
/**
18+
* @internal
19+
*/
20+
class LazyLoadingValueHolderGeneratorextends BaseGenerator
21+
{
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
publicfunctiongenerate(\ReflectionClass$originalClass,ClassGenerator$classGenerator)
26+
{
27+
parent::generate($originalClass,$classGenerator);
28+
29+
if ($classGenerator->hasMethod('__destruct')) {
30+
$destructor =$classGenerator->getMethod('__destruct');
31+
$body =$destructor->getBody();
32+
$newBody =preg_replace('/^(\$this->initializer[\d\w]++) && .*;\n\nreturn (\$this->valueHolder)/','$1 || $2',$body);
33+
34+
if ($body ===$newBody) {
35+
thrownew \UnexpectedValueException(sprintf('Unexpected lazy-proxy format generated for method %s::__destruct()',$originalClass->name));
36+
}
37+
38+
$destructor->setBody($newBody);
39+
}
40+
}
41+
}

‎src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
useProxyManager\Generator\ClassGenerator;
1515
useProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
16-
useProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
1716
useSymfony\Component\DependencyInjection\Container;
1817
useSymfony\Component\DependencyInjection\ContainerInterface;
1918
useSymfony\Component\DependencyInjection\Definition;

‎src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public function testCreateProxyServiceWithRuntimeInstantiator()
3939
/* @var $foo1 \ProxyManager\Proxy\LazyLoadingInterface|\ProxyManager\Proxy\ValueHolderInterface */
4040
$foo1 =$builder->get('foo1');
4141

42+
$foo1->__destruct();
43+
$this->assertSame(0,$foo1::$destructorCount);
44+
4245
$this->assertSame($foo1,$builder->get('foo1'),'The same proxy is retrieved on multiple subsequent calls');
4346
$this->assertInstanceOf('\ProxyManagerBridgeFooClass',$foo1);
4447
$this->assertInstanceOf('\ProxyManager\Proxy\LazyLoadingInterface',$foo1);
@@ -50,5 +53,8 @@ public function testCreateProxyServiceWithRuntimeInstantiator()
5053
$this->assertTrue($foo1->isProxyInitialized());
5154
$this->assertInstanceOf('\ProxyManagerBridgeFooClass',$foo1->getWrappedValueHolderValue());
5255
$this->assertNotInstanceOf('\ProxyManager\Proxy\LazyLoadingInterface',$foo1->getWrappedValueHolderValue());
56+
57+
$foo1->__destruct();
58+
$this->assertSame(1,$foo1::$destructorCount);
5359
}
5460
}

‎src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/includes/foo.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
class ProxyManagerBridgeFooClass
44
{
5+
publicstatic$destructorCount =0;
6+
57
public$foo;
68
public$moo;
79

@@ -38,4 +40,9 @@ public function setBar($value = null)
3840
{
3941
$this->bar =$value;
4042
}
43+
44+
publicfunction__destruct()
45+
{
46+
++self::$destructorCount;
47+
}
4148
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp