Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit983e903

Browse files
committed
[Workflow] Catch error when trying to get an uninitialized marking
1 parent2607b66 commit983e903

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

‎src/Symfony/Component/Workflow/MarkingStore/MethodMarkingStore.php‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ public function getMarking($subject): Marking
5454
thrownewLogicException(sprintf('The method "%s::%s()" does not exist.',\get_class($subject),$method));
5555
}
5656

57-
$marking =$subject->{$method}();
57+
$marking =null;
58+
try {
59+
$marking =$subject->{$method}();
60+
}catch (\Error$e) {
61+
if (!preg_match('/^Typed property ([\w\\\\@]+)::\$(\w+) must not be accessed before initialization$/',$e->getMessage())) {
62+
throw$e;
63+
}
64+
}
5865

5966
if (null ===$marking) {
6067
returnnewMarking();

‎src/Symfony/Component/Workflow/Tests/MarkingStore/MethodMarkingStoreTest.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ public function testGetMarkingWithValueObject()
7878
$this->assertSame('first_place', (string)$subject->getMarking());
7979
}
8080

81+
/**
82+
* @requires PHP 7.4
83+
*/
84+
publicfunctiontestGetMarkingWithUninitializedProperty()
85+
{
86+
$subject =newSubjectWithType();
87+
88+
$markingStore =newMethodMarkingStore(true);
89+
90+
$marking =$markingStore->getMarking($subject);
91+
92+
$this->assertInstanceOf(Marking::class,$marking);
93+
$this->assertCount(0,$marking->getPlaces());
94+
}
95+
8196
privatefunctioncreateValueObject(string$markingValue)
8297
{
8398
returnnewclass($markingValue) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespaceSymfony\Component\Workflow\Tests\MarkingStore;
4+
5+
class SubjectWithType
6+
{
7+
privatestring$marking;
8+
9+
publicfunctiongetMarking():string
10+
{
11+
return$this->marking;
12+
}
13+
14+
publicfunctionsetMarking(string$type):void
15+
{
16+
$this->marking =$type;
17+
}
18+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp