mirror of
https://github.com/doctrine/reflection.git
synced 2026-03-24 08:42:07 +01:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55e71912df | ||
|
|
fbc77cc1c8 | ||
|
|
1a5837f909 | ||
|
|
1ab281861b | ||
|
|
b699ecc7f2 | ||
|
|
cd4811c644 | ||
|
|
aa0689034e | ||
|
|
2fc2828857 | ||
|
|
c7588e0baa | ||
|
|
d9cf1f3deb | ||
|
|
12fea966b2 | ||
|
|
c390808aca |
@@ -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
1
.gitattributes
vendored
@@ -1,3 +1,4 @@
|
||||
/docs export-ignore
|
||||
/tests export-ignore
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
|
||||
@@ -16,7 +16,7 @@ build:
|
||||
- phpcs-run
|
||||
dependencies:
|
||||
override:
|
||||
- composer install -noa
|
||||
- COMPOSER_ROOT_VERSION=1.2 composer install -noa
|
||||
|
||||
tools:
|
||||
external_code_coverage:
|
||||
|
||||
@@ -2,6 +2,10 @@ dist: trusty
|
||||
sudo: false
|
||||
language: php
|
||||
|
||||
env:
|
||||
global:
|
||||
- COMPOSER_ROOT_VERSION=1.2
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
"dev-master": "1.2.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 && $this->hasType() && ! $this->getType()->allowsNull()) {
|
||||
$propertyName = $this->getName();
|
||||
|
||||
$unsetter = function () use ($propertyName) {
|
||||
unset($this->$propertyName);
|
||||
};
|
||||
$unsetter = $unsetter->bindTo($object, $this->getDeclaringClass()->getName());
|
||||
$unsetter();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
parent::setValue($object, $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,64 @@ 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);
|
||||
|
||||
self::assertTrue($reflection->isInitialized($object));
|
||||
|
||||
$reflection->setValue($object, null);
|
||||
|
||||
self::assertNull($reflection->getValue($object));
|
||||
self::assertFalse($reflection->isInitialized($object));
|
||||
}
|
||||
|
||||
public function testSetValueNullOnNullableProperty() : void
|
||||
{
|
||||
$reflection = new TypedNoDefaultReflectionProperty(TypedNullableFoo::class, 'value');
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
$object = new TypedNullableFoo();
|
||||
|
||||
$reflection->setValue($object, null);
|
||||
|
||||
self::assertNull($reflection->getValue($object));
|
||||
self::assertTrue($reflection->isInitialized($object));
|
||||
self::assertNull($object->getValue());
|
||||
}
|
||||
}
|
||||
|
||||
class TypedNoDefaultReflectionPropertyTestClass
|
||||
{
|
||||
public string $test;
|
||||
}
|
||||
|
||||
class TypedFoo
|
||||
{
|
||||
private int $id;
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
}
|
||||
|
||||
class TypedNullableFoo
|
||||
{
|
||||
private ?string $value;
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user