Skip to content

Commit 42fd637

Browse files
committed
Merge remote-tracking branch 'upstream/6.2' into 6.2
2 parents 35663e9 + 58117d7 commit 42fd637

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

src/Symfony/Component/Cache/Traits/Redis6Proxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function bgrewriteaof(): bool
102102
return $this->lazyObjectReal->bgrewriteaof(...\func_get_args());
103103
}
104104

105-
public function bitcount($key, $start = 0, $end = -1)
105+
public function bitcount($key, $start = 0, $end = -1, $bybit = false)
106106
{
107107
return $this->lazyObjectReal->bitcount(...\func_get_args());
108108
}

src/Symfony/Component/VarExporter/LazyGhostTrait.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ public static function createLazyGhost(\Closure $initializer, array $skippedProp
4747
return $instance;
4848
}
4949

50+
/**
51+
* Returns whether the object is initialized.
52+
*/
53+
public function isLazyObjectInitialized(): bool
54+
{
55+
if (!$state = Registry::$states[$this->lazyObjectId ?? ''] ?? null) {
56+
return true;
57+
}
58+
59+
if (LazyObjectState::STATUS_INITIALIZED_PARTIAL === $state->status) {
60+
return \count($state->preInitSetProperties) !== \count((array) $this);
61+
}
62+
63+
return LazyObjectState::STATUS_INITIALIZED_FULL === $state->status;
64+
}
65+
5066
/**
5167
* Forces initialization of a lazy object and returns it.
5268
*/

src/Symfony/Component/VarExporter/LazyObjectInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
interface LazyObjectInterface
1515
{
16+
/**
17+
* Returns whether the object is initialized.
18+
*/
19+
public function isLazyObjectInitialized(): bool;
20+
1621
/**
1722
* Forces initialization of a lazy object and returns it.
1823
*/

src/Symfony/Component/VarExporter/LazyProxyTrait.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public static function createLazyProxy(\Closure $initializer): static
4444
return $instance;
4545
}
4646

47+
/**
48+
* Returns whether the object is initialized.
49+
*/
50+
public function isLazyObjectInitialized(): bool
51+
{
52+
if (0 >= ($this->lazyObjectId ?? 0)) {
53+
return true;
54+
}
55+
56+
return \array_key_exists("\0".self::class."\0lazyObjectReal", (array) $this);
57+
}
58+
4759
/**
4860
* Forces initialization of a lazy object and returns it.
4961
*/

src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function testSerialize()
9898
unset($expected["\0".TestClass::class."\0lazyObjectId"]);
9999
$this->assertSame(array_keys($expected), array_keys((array) $clone));
100100
$this->assertFalse($clone->resetLazyObject());
101+
$this->assertTrue($clone->isLazyObjectInitialized());
101102
}
102103

103104
/**
@@ -162,6 +163,7 @@ public function testResetLazyGhost()
162163

163164
$instance->foo = 234;
164165
$this->assertTrue($instance->resetLazyObject());
166+
$this->assertFalse($instance->isLazyObjectInitialized());
165167
$this->assertSame('bar', $instance->foo);
166168
}
167169

@@ -173,7 +175,9 @@ public function testFullInitialization()
173175
$ghost->__construct();
174176
});
175177

178+
$this->assertFalse($instance->isLazyObjectInitialized());
176179
$this->assertTrue(isset($instance->public));
180+
$this->assertTrue($instance->isLazyObjectInitialized());
177181
$this->assertSame(-4, $instance->public);
178182
$this->assertSame(4, $instance->publicReadonly);
179183
$this->assertSame(1, $counter);
@@ -198,7 +202,9 @@ public function testPartialInitialization()
198202
});
199203

200204
$this->assertSame(["\0".TestClass::class."\0lazyObjectId"], array_keys((array) $instance));
205+
$this->assertFalse($instance->isLazyObjectInitialized());
201206
$this->assertSame(123, $instance->public);
207+
$this->assertTrue($instance->isLazyObjectInitialized());
202208
$this->assertSame(["\0".TestClass::class."\0lazyObjectId", 'public'], array_keys((array) $instance));
203209
$this->assertSame(1, $counter);
204210

@@ -221,7 +227,9 @@ public function testPartialInitializationWithReset()
221227

222228
$instance->public = 123;
223229

230+
$this->assertFalse($instance->isLazyObjectInitialized());
224231
$this->assertSame(234, $instance->publicReadonly);
232+
$this->assertTrue($instance->isLazyObjectInitialized());
225233
$this->assertSame(123, $instance->public);
226234

227235
$this->assertTrue($instance->resetLazyObject());

src/Symfony/Component/VarExporter/Tests/LazyProxyTraitTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ public function testGetter()
3333

3434
$this->assertInstanceOf(TestClass::class, $proxy);
3535
$this->assertSame(0, $initCounter);
36+
$this->assertFalse($proxy->isLazyObjectInitialized());
3637

3738
$dep1 = $proxy->getDep();
39+
$this->assertTrue($proxy->isLazyObjectInitialized());
3840
$this->assertSame(1, $initCounter);
3941

4042
$this->assertTrue($proxy->resetLazyObject());
@@ -55,8 +57,10 @@ public function testInitialize()
5557
});
5658

5759
$this->assertSame(0, $initCounter);
60+
$this->assertFalse($proxy->isLazyObjectInitialized());
5861

5962
$proxy->initializeLazyObject();
63+
$this->assertTrue($proxy->isLazyObjectInitialized());
6064
$this->assertSame(1, $initCounter);
6165

6266
$proxy->initializeLazyObject();
@@ -98,6 +102,8 @@ public function testUnserialize()
98102

99103
$copy = unserialize(serialize($proxy));
100104
$this->assertSame(1, $initCounter);
105+
$this->assertTrue($copy->isLazyObjectInitialized());
106+
$this->assertTrue($proxy->isLazyObjectInitialized());
101107

102108
$this->assertFalse($copy->resetLazyObject());
103109
$this->assertTrue($copy->getDep()->wokeUp);

0 commit comments

Comments
 (0)