Skip to content

[Form] Deprecate not configuring the default_protocol option of the UrlType #50882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions src/Symfony/Component/VarExporter/LazyGhostTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ public function __clone(): void
}

if ((Registry::$parentMethods[self::class] ??= Registry::getParentMethods(self::class))['clone']) {
if ($this->lazyObjectState->skippedProperties) {
$this->initializeLazyObject();
}

parent::__clone();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost;

class MagicCloneClass
{
public ?int $id;
public bool $cloned;

public function __clone()
{
$this->id = null;
$this->cloned = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost;

use Symfony\Component\VarExporter\LazyGhostTrait;
use Symfony\Component\VarExporter\LazyObjectInterface;

class MagicCloneClassProxy extends MagicCloneClass implements LazyObjectInterface
{
use LazyGhostTrait;
}
18 changes: 18 additions & 0 deletions src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ChildTestClass;
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\LazyClass;
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\MagicClass;
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\MagicCloneClassProxy;
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\ReadOnlyClass;
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\TestClass;

Expand Down Expand Up @@ -109,6 +110,23 @@ public function testClone()
$this->assertTrue($clone->resetLazyObject());
}

public function testCloneIsInitializedIfNeeded()
{
$instance = MagicCloneClassProxy::createLazyGhost(function (MagicCloneClassProxy $ghost) {
if (1 === $ghost->id) {
$ghost->cloned = false;
} else {
$this->fail('Ghost must be initialized before its __clone method is called.');
}
}, ['id' => true]);
$instance->id = 1;

$clone = clone $instance;

$this->assertNull($clone->id);
$this->assertTrue($clone->cloned);
}

public function testSerialize()
{
$instance = ChildTestClass::createLazyGhost(function (ChildTestClass $ghost) {
Expand Down