8 Commits

Author SHA1 Message Date
Benjamin Eberlei
b699ecc7f2 Merge pull request #35 from doctrine/GH-34-SetValueUnitialized
[GH-34] Instead of NULL, unitialize typed properties without default.
2020-03-21 12:34:59 +01:00
Benjamin Eberlei
cd4811c644 [GH-34] Instead of NULL, unitialize typed properties without default. 2020-03-16 09:38:51 +01:00
Maciej Malarz
aa0689034e Merge pull request #31 from Spomky/patch-1
No doc files for distribution
2020-02-28 21:27:16 +01:00
Florent Morselli
2fc2828857 No doc files for distribution
This PR adds the folder `/docs` in .gitattributes so that it will not be present in distribution
2020-02-28 14:43:01 +01:00
Claudio Zizza
c7588e0baa Merge pull request #30 from doctrine/patch-1
Update of project config for latest version
2020-01-29 22:57:36 +01:00
Claudio Zizza
d9cf1f3deb Update of project config for latest version
Because of a failing website build the config for the
latest version was adapted to the same version
syntax like in other Doctrine projects.
2020-01-29 00:23:19 +01:00
Andreas Braun
12fea966b2 Update branch-alias to 1.2.x-dev 2020-01-18 13:09:54 +01:00
Andreas Braun
c390808aca Update maintained branches 2020-01-18 13:09:53 +01:00
5 changed files with 63 additions and 2 deletions

View File

@@ -5,14 +5,26 @@
"docsSlug": "doctrine-reflection",
"versions": [
{
"name": "1.0",
"name": "1.2",
"branchName": "master",
"slug": "latest",
"upcoming": true
},
{
"name": "1.1",
"branchName": "1.1.x",
"slug": "1.1",
"current": true,
"aliases": [
"current",
"stable"
]
},
{
"name": "1.0",
"branchName": "1.0",
"slug": "1.0",
"maintained": false
}
]
}

1
.gitattributes vendored
View File

@@ -1,3 +1,4 @@
/docs export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore

View File

@@ -44,7 +44,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.2.x-dev"
}
}
}

View File

@@ -20,4 +20,29 @@ class TypedNoDefaultReflectionProperty extends ReflectionProperty
{
return $object !== null && $this->isInitialized($object) ? parent::getValue($object) : null;
}
/**
* {@inheritDoc}
*
* Works around the problem with setting typed no default properties to
* NULL which is not supported, instead unset() to uninitialize.
*
* @link https://github.com/doctrine/orm/issues/7999
*/
public function setValue($object, $value = null)
{
if ($value === null) {
$propertyName = $this->getName();
$unsetter = function () use ($propertyName) {
unset($this->$propertyName);
};
$unsetter = $unsetter->bindTo($object, $this->getDeclaringClass()->getName());
$unsetter();
return;
}
parent::setValue($object, $value);
}
}

View File

@@ -23,9 +23,32 @@ class TypedNoDefaultReflectionPropertyTest extends TestCase
self::assertNull($reflProperty->getValue($object));
}
public function testSetValueNull() : void
{
$reflection = new TypedNoDefaultReflectionProperty(TypedFoo::class, 'id');
$reflection->setAccessible(true);
$object = new TypedFoo();
$object->setId(1);
$reflection->setValue($object, null);
self::assertNull($reflection->getValue($object));
}
}
class TypedNoDefaultReflectionPropertyTestClass
{
public string $test;
}
class TypedFoo
{
private int $id;
public function setId($id)
{
$this->id = $id;
}
}