Skip to content

Commit 52bf7f4

Browse files
authored
chore(v3): remove proxies (#1094)
* chore: remove proxies * refactor: remove ProxyGenerator
1 parent d18c192 commit 52bf7f4

File tree

60 files changed

+187
-2970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+187
-2970
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"symfony/polyfill-php85": "^1.33",
2323
"symfony/property-access": "^8.0",
2424
"symfony/property-info": "^8.0",
25-
"symfony/var-exporter": "^8.0",
2625
"zenstruck/assert": "^1.4"
2726
},
2827
"require-dev": {

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ parameters:
2222
- bin/tools/phpbench/vendor/autoload.php
2323

2424
ignoreErrors:
25-
# suppress strange behavior of PHPStan where it considers proxy() return type as *NEVER*
26-
- message: '#Return type of call to function Zenstruck\\Foundry\\Persistence\\proxy contains unresolvable type#'
27-
path: src/Persistence/ProxyRepositoryDecorator.php
28-
2925
# prevent PHPStan to force to type data providers
3026
- identifier: missingType.iterableValue
3127
path: tests/

phpunit-deprecation-baseline.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,6 @@
44
<line number="25" hash="c6af5d66288d0667e424978000f29571e4954b81">
55
<issue><![CDATA[Since symfony/framework-bundle 6.4: Not setting the "framework.php_errors.log" config option is deprecated. It will default to "true" in 7.0.]]></issue>
66

7-
<issue><![CDATA[Since symfony/var-exporter 7.3: Generating lazy proxy for class "Zenstruck\Foundry\Tests\Integration\ForceFactoriesTraitUsage\SomeObject" is deprecated; leverage native lazy objects instead.]]></issue>
8-
<issue><![CDATA[Since symfony/var-exporter 7.3: Using ProxyHelper::generateLazyGhost() is deprecated, use native lazy objects instead.]]></issue>
9-
<issue><![CDATA[Since symfony/var-exporter 7.3: The "Symfony\Component\VarExporter\LazyGhostTrait" trait is deprecated, use native lazy objects instead.]]></issue>
10-
<issue><![CDATA[Since symfony/var-exporter 7.3: The "Symfony\Component\VarExporter\LazyProxyTrait" trait is deprecated, use native lazy objects instead.]]></issue>
11-
<issue><![CDATA[Since symfony/var-exporter 7.3: Generating lazy proxy for class "Zenstruck\Foundry\Tests\Fixture\Entity\GlobalEntity" is deprecated; leverage native lazy objects instead.]]></issue>
12-
13-
<issue><![CDATA[Since zenstruck/foundry 2.7: Proxy usage is deprecated in PHP 8.4. Use directly PersistentObjectFactory, Foundry now leverages the native PHP lazy system to auto-refresh objects.]]></issue>
14-
<issue><![CDATA[Since zenstruck/foundry 2.7: Proxy usage is deprecated in PHP 8.4. You should extend directly PersistentObjectFactory in your factories.
15-
Foundry now leverages the native PHP lazy system to auto-refresh objects (it can be enabled with "zenstruck_foundry.enable_auto_refresh_with_lazy_objects" configuration).
16-
See https://github.com/zenstruck/foundry/blob/2.x/UPGRADE-2.7.md to upgrade.]]></issue>
17-
<issue><![CDATA[Since zenstruck/foundry 2.7: Function proxy() is deprecated and will be removed in Foundry 3.
18-
Proxy usage is deprecated in PHP 8.4. You should extend directly PersistentObjectFactory in your factories.
19-
Foundry now leverages the native PHP lazy system to auto-refresh objects (it can be enabled with "zenstruck_foundry.enable_auto_refresh_with_lazy_objects" configuration).
20-
See https://github.com/zenstruck/foundry/blob/2.x/UPGRADE-2.7.md to upgrade.]]></issue>
21-
227
<issue><![CDATA[Since zenstruck/foundry 2.9: Trait Zenstruck\Foundry\Test\Factories is deprecated and will be removed in Foundry 3. See https://github.com/zenstruck/foundry/blob/2.x/UPGRADE-2.9.md to upgrade.]]></issue>
238
<issue><![CDATA[Since zenstruck/foundry 2.9: Not using Foundry's PHPUnit extension is deprecated and will throw an error in Foundry 3. See https://github.com/zenstruck/foundry/blob/2.x/UPGRADE-2.9.md to upgrade.]]></issue>
249

src/Configuration.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,4 @@ public static function autoRefreshWithLazyObjectsIsEnabled(): bool
180180
return self::isBooted() && self::instance()->enableAutoRefreshWithLazyObjects;
181181
}
182182

183-
public static function triggerProxyDeprecation(?string $additionalMessage = null): void
184-
{
185-
if (\PHP_VERSION_ID < 80400) {
186-
return;
187-
}
188-
189-
if (!\trait_exists(\Symfony\Component\VarExporter\LazyProxyTrait::class)) {
190-
// Deprecation is not needed: PersistentProxyObjectFactory will actually throw when create() is called.
191-
return;
192-
}
193-
194-
$message = <<<DEPRECATION
195-
Proxy usage is deprecated in PHP 8.4. You should extend directly PersistentObjectFactory in your factories.
196-
Foundry now leverages the native PHP lazy system to auto-refresh objects (it can be enabled with "zenstruck_foundry.enable_auto_refresh_with_lazy_objects" configuration).
197-
See https://github.com/zenstruck/foundry/blob/2.x/UPGRADE-2.7.md to upgrade.
198-
DEPRECATION;
199-
200-
if ($additionalMessage) {
201-
$message = "{$additionalMessage}\n{$message}";
202-
}
203-
204-
trigger_deprecation('zenstruck/foundry', '2.7', $message);
205-
}
206183
}

src/Maker/Factory/MakeFactoryData.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1919
use Zenstruck\Foundry\ObjectFactory;
2020
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
21-
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
22-
use Zenstruck\Foundry\Persistence\Proxy;
23-
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
21+
use Zenstruck\Foundry\Persistence\RepositoryDecorator;
2422

2523
/**
2624
* @internal
@@ -55,13 +53,9 @@ public function __construct(
5553
$object->getName(),
5654
];
5755

58-
if ($this->persisted) {
59-
$this->uses[] = Proxy::class;
60-
}
61-
6256
if ($repository) {
6357
$this->uses[] = $repository->getName();
64-
$this->uses[] = ProxyRepositoryDecorator::class;
58+
$this->uses[] = RepositoryDecorator::class;
6559
if (!\str_starts_with($repository->getName(), 'Doctrine')) {
6660
$this->uses[] = \is_a($repository->getName(), DocumentRepository::class, allow_string: true) ? DocumentRepository::class : EntityRepository::class;
6761
}
@@ -86,9 +80,7 @@ public function getObjectShortName(): string
8680
*/
8781
public function getFactoryClass(): string
8882
{
89-
return $this->isPersisted()
90-
? (\PHP_VERSION_ID >= 80400 ? PersistentObjectFactory::class : PersistentProxyObjectFactory::class)
91-
: ObjectFactory::class;
83+
return $this->isPersisted() ? PersistentObjectFactory::class : ObjectFactory::class;
9284
}
9385

9486
public function getFactoryClassShortName(): string

src/Maker/Factory/MakeFactoryPHPDocMethod.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ public function toString(?string $staticAnalysisTool = null): string
6363

6464
if ($this->repository) {
6565
$returnType = match ((bool) $staticAnalysisTool) {
66-
false => "{$this->repository->getShortName()}|ProxyRepositoryDecorator",
66+
false => "{$this->repository->getShortName()}|RepositoryDecorator",
6767
true => \sprintf(
68-
"ProxyRepositoryDecorator<{$this->objectName}, %s>",
68+
"RepositoryDecorator<{$this->objectName}, %s>",
6969
\is_a($this->repository->getName(), DocumentRepository::class, allow_string: true)
7070
? "DocumentRepository<{$this->objectName}>"
7171
: "EntityRepository<{$this->objectName}>"
7272
),
7373
};
7474
} else {
7575
$returnType = match ([$this->returnsCollection, (bool) $staticAnalysisTool]) {
76-
[true, true] => "list<{$this->objectName}&Proxy<{$this->objectName}>>",
77-
[true, false] => "{$this->objectName}[]|Proxy[]",
78-
[false, true] => "{$this->objectName}&Proxy<{$this->objectName}>",
79-
[false, false] => "{$this->objectName}|Proxy",
76+
[true, true] => "list<{$this->objectName}>",
77+
[true, false] => "{$this->objectName}[]",
78+
[false, true] => "{$this->objectName}",
79+
[false, false] => "{$this->objectName}",
8080
};
8181
}
8282

src/Maker/Factory/NoPersistenceObjectsAutoCompleter.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ public function getAutocompleteValues(): array
4040

4141
$class = $this->toPSR4($rootPath, $phpFile, $namespacePrefix);
4242

43-
if (\in_array($class, ['Zenstruck\Foundry\Proxy', 'Zenstruck\Foundry\RepositoryProxy', 'Zenstruck\Foundry\RepositoryAssertions'])) {
44-
// do not load legacy Proxy: prevents deprecations in tests.
45-
continue;
46-
}
47-
4843
try {
4944
// @phpstan-ignore-next-line $class is not always a class-string
5045
$reflection = new \ReflectionClass($class);

src/Maker/MakeFactory.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
7777

7878
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
7979
{
80-
if ($input->getOption('with-phpdoc') && \PHP_VERSION_ID >= 80400) {
81-
trigger_deprecation(
82-
'zenstruck/foundry',
83-
'2.7',
84-
'The --with-phpdoc option is deprecated and will be removed in 3.0.',
85-
);
86-
}
87-
8880
if (!$this->doctrineEnabled() && !$input->getOption('no-persistence')) {
8981
$io->text('// Note: Doctrine not enabled: auto-activating <fg=yellow>--no-persistence</> option.');
9082
$io->newLine();

src/ObjectFactory.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Zenstruck\Foundry\Object\Event\AfterInstantiate;
1515
use Zenstruck\Foundry\Object\Event\BeforeInstantiate;
1616
use Zenstruck\Foundry\Object\Instantiator;
17-
use Zenstruck\Foundry\Persistence\ProxyGenerator;
1817

1918
/**
2019
* @author Kevin Bond <kevinbond@gmail.com>
@@ -144,8 +143,6 @@ final public function reuse(object ...$objects): static
144143
$clone = clone $this;
145144

146145
foreach ($objects as $object) {
147-
$object = ProxyGenerator::unwrap($object, withAutoRefresh: false);
148-
149146
if ($object instanceof Factory) {
150147
throw new \InvalidArgumentException('Cannot reuse a factory.');
151148
}

src/PHPUnit/DataProvider/TriggerDataProviderPersistenceOnTestPrepared.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPUnit\Event;
1515
use PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException;
1616
use PHPUnit\Util\Test;
17-
use Zenstruck\Foundry\Persistence\ProxyGenerator;
1817

1918
/**
2019
* @internal
@@ -38,7 +37,20 @@ public function notify(Event\Test\Prepared $event): void
3837

3938
$providedData = $testCase->providedData(); // @phpstan-ignore method.internal
4039
if ($providedData) {
41-
ProxyGenerator::unwrap($providedData);
40+
self::initializeLazyObjects($providedData);
41+
}
42+
}
43+
44+
private static function initializeLazyObjects(mixed $what): void
45+
{
46+
if (\is_array($what)) {
47+
\array_map(self::initializeLazyObjects(...), $what);
48+
49+
return;
50+
}
51+
52+
if (\is_object($what) && (new \ReflectionClass($what))->isUninitializedLazyObject($what)) {
53+
(new \ReflectionClass($what))->initializeLazyObject($what);
4254
}
4355
}
4456
}

0 commit comments

Comments
 (0)