Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"symfony/polyfill-php85": "^1.33",
"symfony/property-access": "^8.0",
"symfony/property-info": "^8.0",
"symfony/var-exporter": "^8.0",
"zenstruck/assert": "^1.4"
},
"require-dev": {
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ parameters:
- bin/tools/phpbench/vendor/autoload.php

ignoreErrors:
# suppress strange behavior of PHPStan where it considers proxy() return type as *NEVER*
- message: '#Return type of call to function Zenstruck\\Foundry\\Persistence\\proxy contains unresolvable type#'
path: src/Persistence/ProxyRepositoryDecorator.php

# prevent PHPStan to force to type data providers
- identifier: missingType.iterableValue
path: tests/
Expand Down
15 changes: 0 additions & 15 deletions phpunit-deprecation-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@
<line number="25" hash="c6af5d66288d0667e424978000f29571e4954b81">
<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>

<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>
<issue><![CDATA[Since symfony/var-exporter 7.3: Using ProxyHelper::generateLazyGhost() is deprecated, use native lazy objects instead.]]></issue>
<issue><![CDATA[Since symfony/var-exporter 7.3: The "Symfony\Component\VarExporter\LazyGhostTrait" trait is deprecated, use native lazy objects instead.]]></issue>
<issue><![CDATA[Since symfony/var-exporter 7.3: The "Symfony\Component\VarExporter\LazyProxyTrait" trait is deprecated, use native lazy objects instead.]]></issue>
<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>

<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>
<issue><![CDATA[Since zenstruck/foundry 2.7: Proxy usage is deprecated in PHP 8.4. You should extend directly PersistentObjectFactory in your factories.
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).
See https://github.com/zenstruck/foundry/blob/2.x/UPGRADE-2.7.md to upgrade.]]></issue>
<issue><![CDATA[Since zenstruck/foundry 2.7: Function proxy() is deprecated and will be removed in Foundry 3.
Proxy usage is deprecated in PHP 8.4. You should extend directly PersistentObjectFactory in your factories.
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).
See https://github.com/zenstruck/foundry/blob/2.x/UPGRADE-2.7.md to upgrade.]]></issue>

<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>
<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>

Expand Down
23 changes: 0 additions & 23 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,4 @@ public static function autoRefreshWithLazyObjectsIsEnabled(): bool
return self::isBooted() && self::instance()->enableAutoRefreshWithLazyObjects;
}

public static function triggerProxyDeprecation(?string $additionalMessage = null): void
{
if (\PHP_VERSION_ID < 80400) {
return;
}

if (!\trait_exists(\Symfony\Component\VarExporter\LazyProxyTrait::class)) {
// Deprecation is not needed: PersistentProxyObjectFactory will actually throw when create() is called.
return;
}

$message = <<<DEPRECATION
Proxy usage is deprecated in PHP 8.4. You should extend directly PersistentObjectFactory in your factories.
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).
See https://github.com/zenstruck/foundry/blob/2.x/UPGRADE-2.7.md to upgrade.
DEPRECATION;

if ($additionalMessage) {
$message = "{$additionalMessage}\n{$message}";
}

trigger_deprecation('zenstruck/foundry', '2.7', $message);
}
}
14 changes: 3 additions & 11 deletions src/Maker/Factory/MakeFactoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Zenstruck\Foundry\ObjectFactory;
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
use Zenstruck\Foundry\Persistence\Proxy;
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
use Zenstruck\Foundry\Persistence\RepositoryDecorator;

/**
* @internal
Expand Down Expand Up @@ -55,13 +53,9 @@ public function __construct(
$object->getName(),
];

if ($this->persisted) {
$this->uses[] = Proxy::class;
}

if ($repository) {
$this->uses[] = $repository->getName();
$this->uses[] = ProxyRepositoryDecorator::class;
$this->uses[] = RepositoryDecorator::class;
if (!\str_starts_with($repository->getName(), 'Doctrine')) {
$this->uses[] = \is_a($repository->getName(), DocumentRepository::class, allow_string: true) ? DocumentRepository::class : EntityRepository::class;
}
Expand All @@ -86,9 +80,7 @@ public function getObjectShortName(): string
*/
public function getFactoryClass(): string
{
return $this->isPersisted()
? (\PHP_VERSION_ID >= 80400 ? PersistentObjectFactory::class : PersistentProxyObjectFactory::class)
: ObjectFactory::class;
return $this->isPersisted() ? PersistentObjectFactory::class : ObjectFactory::class;
}

public function getFactoryClassShortName(): string
Expand Down
12 changes: 6 additions & 6 deletions src/Maker/Factory/MakeFactoryPHPDocMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ public function toString(?string $staticAnalysisTool = null): string

if ($this->repository) {
$returnType = match ((bool) $staticAnalysisTool) {
false => "{$this->repository->getShortName()}|ProxyRepositoryDecorator",
false => "{$this->repository->getShortName()}|RepositoryDecorator",
true => \sprintf(
"ProxyRepositoryDecorator<{$this->objectName}, %s>",
"RepositoryDecorator<{$this->objectName}, %s>",
\is_a($this->repository->getName(), DocumentRepository::class, allow_string: true)
? "DocumentRepository<{$this->objectName}>"
: "EntityRepository<{$this->objectName}>"
),
};
} else {
$returnType = match ([$this->returnsCollection, (bool) $staticAnalysisTool]) {
[true, true] => "list<{$this->objectName}&Proxy<{$this->objectName}>>",
[true, false] => "{$this->objectName}[]|Proxy[]",
[false, true] => "{$this->objectName}&Proxy<{$this->objectName}>",
[false, false] => "{$this->objectName}|Proxy",
[true, true] => "list<{$this->objectName}>",
[true, false] => "{$this->objectName}[]",
[false, true] => "{$this->objectName}",
[false, false] => "{$this->objectName}",
};
}

Expand Down
5 changes: 0 additions & 5 deletions src/Maker/Factory/NoPersistenceObjectsAutoCompleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ public function getAutocompleteValues(): array

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

if (\in_array($class, ['Zenstruck\Foundry\Proxy', 'Zenstruck\Foundry\RepositoryProxy', 'Zenstruck\Foundry\RepositoryAssertions'])) {
// do not load legacy Proxy: prevents deprecations in tests.
continue;
}

try {
// @phpstan-ignore-next-line $class is not always a class-string
$reflection = new \ReflectionClass($class);
Expand Down
8 changes: 0 additions & 8 deletions src/Maker/MakeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ public function configureCommand(Command $command, InputConfiguration $inputConf

public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
{
if ($input->getOption('with-phpdoc') && \PHP_VERSION_ID >= 80400) {
trigger_deprecation(
'zenstruck/foundry',
'2.7',
'The --with-phpdoc option is deprecated and will be removed in 3.0.',
);
}

if (!$this->doctrineEnabled() && !$input->getOption('no-persistence')) {
$io->text('// Note: Doctrine not enabled: auto-activating <fg=yellow>--no-persistence</> option.');
$io->newLine();
Expand Down
3 changes: 0 additions & 3 deletions src/ObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Zenstruck\Foundry\Object\Event\AfterInstantiate;
use Zenstruck\Foundry\Object\Event\BeforeInstantiate;
use Zenstruck\Foundry\Object\Instantiator;
use Zenstruck\Foundry\Persistence\ProxyGenerator;

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

foreach ($objects as $object) {
$object = ProxyGenerator::unwrap($object, withAutoRefresh: false);

if ($object instanceof Factory) {
throw new \InvalidArgumentException('Cannot reuse a factory.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPUnit\Event;
use PHPUnit\Event\Code\NoTestCaseObjectOnCallStackException;
use PHPUnit\Util\Test;
use Zenstruck\Foundry\Persistence\ProxyGenerator;

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

$providedData = $testCase->providedData(); // @phpstan-ignore method.internal
if ($providedData) {
ProxyGenerator::unwrap($providedData);
self::initializeLazyObjects($providedData);
}
}

private static function initializeLazyObjects(mixed $what): void
{
if (\is_array($what)) {
\array_map(self::initializeLazyObjects(...), $what);

return;
}

if (\is_object($what) && (new \ReflectionClass($what))->isUninitializedLazyObject($what)) {
(new \ReflectionClass($what))->initializeLazyObject($what);
}
}
}
181 changes: 0 additions & 181 deletions src/Persistence/IsProxy.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Persistence/PersistedObjectsTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function refresh(): void
*/
public function afterPersistHook(AfterPersist $event): void
{
if ($event->factory instanceof PersistentProxyObjectFactory || !$event->factory->isAutorefreshEnabled()) {
if (!$event->factory->isAutorefreshEnabled()) {
return;
}

Expand Down
Loading
Loading