Skip to content

Commit 6ef731b

Browse files
committed
Merge branch '7.3' into 7.4
* 7.3: do not install ext-zstd on PHP 8.5 [DependencyInjection] Fix proxying services defined with an abstract class and a factory
2 parents f4ca886 + 01074ef commit 6ef731b

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
- php: '8.3'
3535
- php: '8.4'
3636
- php: '8.5'
37+
# to be removed when ext-zstd is ready for PHP 8.5
38+
extensions: amqp,apcu,brotli,igbinary,intl,mbstring,memcached,redis,relay
3739
#mode: experimental
3840
fail-fast: false
3941

@@ -234,7 +236,7 @@ jobs:
234236
- name: Run AssetMapper without ext-brotli nor ext-zstd
235237
if: "! matrix.mode"
236238
run: |
237-
sudo rm /etc/php/*/cli/conf.d/*-{brotli,zstd}.ini
239+
sudo rm -f /etc/php/*/cli/conf.d/*-{brotli,zstd}.ini
238240
./phpunit src/Symfony/Component/AssetMapper
239241
240242
- name: Run tests with SIGCHLD enabled PHP

src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/LazyServiceDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function getProxyClass(Definition $definition, bool $asGhostObject, ?\Ref
197197
return $class->name;
198198
}
199199

200-
if (!$definition->hasTag('proxy') && !$class->isInterface()) {
200+
if (!$definition->hasTag('proxy') && !$class->isAbstract()) {
201201
$parent = $class;
202202
do {
203203
$extendsInternalClass = $parent->isInternal();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
abstract class AbstractSayClass
15+
{
16+
abstract public function say(): string;
17+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
namespace Symfony\Component\DependencyInjection\Tests\LazyProxy\Instantiator;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\Container;
16+
use Symfony\Component\DependencyInjection\Definition;
17+
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\LazyServiceInstantiator;
18+
use Symfony\Component\DependencyInjection\Tests\Fixtures\AbstractSayClass;
19+
20+
class LazyServiceInstantiatorTest extends TestCase
21+
{
22+
public function testInstantiateAbstractClassProxy()
23+
{
24+
$instantiator = new LazyServiceInstantiator();
25+
$instance = new class extends AbstractSayClass {
26+
public int $calls = 0;
27+
28+
public function say(): string
29+
{
30+
++$this->calls;
31+
32+
return 'Hello from the abstract class!';
33+
}
34+
};
35+
36+
$definition = (new Definition(AbstractSayClass::class))
37+
->setLazy(true);
38+
39+
$proxy = $instantiator->instantiateProxy(new Container(), $definition, 'foo', fn () => $instance);
40+
41+
$this->assertSame(0, $instance->calls);
42+
$this->assertSame('Hello from the abstract class!', $proxy->say());
43+
$this->assertSame(1, $instance->calls);
44+
}
45+
}

src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/LazyServiceDumperTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Definition;
1717
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1818
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\LazyServiceDumper;
19+
use Symfony\Component\DependencyInjection\Tests\Fixtures\AbstractSayClass;
1920
use Symfony\Component\DependencyInjection\Tests\Fixtures\ReadOnlyClass;
2021

2122
class LazyServiceDumperTest extends TestCase
@@ -40,6 +41,16 @@ public function testFinalClassInterface()
4041
$this->assertStringContainsString('function get(', $dumper->getProxyCode($definition));
4142
}
4243

44+
public function testAbstractClass()
45+
{
46+
$dumper = new LazyServiceDumper();
47+
$definition = (new Definition(AbstractSayClass::class))
48+
->setLazy(true);
49+
50+
$this->assertTrue($dumper->isProxyCandidate($definition));
51+
$this->assertNotSame(AbstractSayClass::class, $dumper->getProxyClass($definition, false));
52+
}
53+
4354
public function testInvalidClass()
4455
{
4556
$dumper = new LazyServiceDumper();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy