Skip to content

Commit ac87e6e

Browse files
authored
Merge pull request doctrine#12038 from doctrine/3.5.x
Merge 3.5.x up into 4.0.x
2 parents 016d9d2 + edfaa37 commit ac87e6e

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/Proxy/Autoloader.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ORM\Proxy;
66

77
use Closure;
8+
use Doctrine\Deprecations\Deprecation;
89

910
use function file_exists;
1011
use function ltrim;
@@ -15,6 +16,7 @@
1516
use function substr;
1617

1718
use const DIRECTORY_SEPARATOR;
19+
use const PHP_VERSION_ID;
1820

1921
/**
2022
* Special Autoloader for Proxy classes, which are not PSR-0 compliant.
@@ -34,6 +36,15 @@ final class Autoloader
3436
*/
3537
public static function resolveFile(string $proxyDir, string $proxyNamespace, string $className): string
3638
{
39+
if (PHP_VERSION_ID >= 80400) {
40+
Deprecation::trigger(
41+
'doctrine/orm',
42+
'https://github.com/doctrine/orm/pull/12005',
43+
'Class "%s" is deprecated. Use native lazy objects instead.',
44+
self::class,
45+
);
46+
}
47+
3748
if (! str_starts_with($className, $proxyNamespace)) {
3849
throw new NotAProxyClass($className, $proxyNamespace);
3950
}
@@ -59,6 +70,15 @@ public static function register(
5970
string $proxyNamespace,
6071
Closure|null $notFoundCallback = null,
6172
): Closure {
73+
if (PHP_VERSION_ID >= 80400) {
74+
Deprecation::trigger(
75+
'doctrine/orm',
76+
'https://github.com/doctrine/orm/pull/12005',
77+
'Class "%s" is deprecated. Use native lazy objects instead.',
78+
self::class,
79+
);
80+
}
81+
6282
$proxyNamespace = ltrim($proxyNamespace, '\\');
6383

6484
$autoloader = /** @param class-string $className */ static function (string $className) use ($proxyDir, $proxyNamespace, $notFoundCallback): void {

src/Proxy/DefaultProxyClassNameResolver.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
namespace Doctrine\ORM\Proxy;
66

7+
use Doctrine\Deprecations\Deprecation;
78
use Doctrine\Persistence\Mapping\ProxyClassNameResolver;
89
use Doctrine\Persistence\Proxy;
910

1011
use function strrpos;
1112
use function substr;
1213

14+
use const PHP_VERSION_ID;
15+
1316
/**
1417
* Class-related functionality for objects that might or not be proxy objects
1518
* at the moment.
@@ -18,6 +21,15 @@ final class DefaultProxyClassNameResolver implements ProxyClassNameResolver
1821
{
1922
public function resolveClassName(string $className): string
2023
{
24+
if (PHP_VERSION_ID >= 80400) {
25+
Deprecation::triggerIfCalledFromOutside(
26+
'doctrine/orm',
27+
'https://github.com/doctrine/orm/pull/12005',
28+
'Class "%s" is deprecated. Use native lazy objects instead.',
29+
self::class,
30+
);
31+
}
32+
2133
$pos = strrpos($className, '\\' . Proxy::MARKER . '\\');
2234

2335
if ($pos === false) {
@@ -30,6 +42,15 @@ public function resolveClassName(string $className): string
3042
/** @return class-string */
3143
public static function getClass(object $object): string
3244
{
45+
if (PHP_VERSION_ID >= 80400) {
46+
Deprecation::triggerIfCalledFromOutside(
47+
'doctrine/orm',
48+
'https://github.com/doctrine/orm/pull/12005',
49+
'Class "%s" is deprecated. Use native lazy objects instead.',
50+
self::class,
51+
);
52+
}
53+
3354
return (new self())->resolveClassName($object::class);
3455
}
3556
}

tests/Tests/Proxy/AutoloaderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\ORM\Proxy\Autoloader;
88
use PHPUnit\Framework\Attributes\DataProvider;
9+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
910
use PHPUnit\Framework\TestCase;
1011

1112
use function class_exists;
@@ -31,6 +32,7 @@ public static function dataResolveFile(): iterable
3132

3233
/** @param class-string $className */
3334
#[DataProvider('dataResolveFile')]
35+
#[WithoutErrorHandler]
3436
public function testResolveFile(
3537
string $proxyDir,
3638
string $proxyNamespace,
@@ -41,6 +43,7 @@ public function testResolveFile(
4143
self::assertEquals($expectedProxyFile, $actualProxyFile);
4244
}
4345

46+
#[WithoutErrorHandler]
4447
public function testAutoload(): void
4548
{
4649
if (file_exists(sys_get_temp_dir() . '/AutoloaderTestClass.php')) {

0 commit comments

Comments
 (0)