Skip to content
Open
Changes from 1 commit
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
31 changes: 28 additions & 3 deletions lib/Doctrine/Common/Proxy/ProxyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public function __construct(?\Closure $initializer = null, ?\Closure $cloner = n

$toUnset = array_map(static function (string $name): string {
return '$this->' . $name;
}, $this->getLazyLoadedPublicPropertiesNames($class));
}, $this->getWriteableLazyLoadedPublicPropertiesNames($class));

return $constructorImpl . ($toUnset === [] ? '' : ' unset(' . implode(', ', $toUnset) . ");\n")
. <<<'EOT'
Expand Down Expand Up @@ -591,7 +591,7 @@ public function {$returnReference}__get($parametersString)$returnTypeHint
*/
private function generateMagicSet(ClassMetadata $class)
{
$lazyPublicProperties = $this->getLazyLoadedPublicPropertiesNames($class);
$lazyPublicProperties = $this->getWriteableLazyLoadedPublicPropertiesNames($class);
$reflectionClass = $class->getReflectionClass();
$hasParentSet = false;
$inheritDoc = '';
Expand Down Expand Up @@ -808,7 +808,7 @@ private function generateWakeupImpl(ClassMetadata $class)
$hasParentWakeup = $reflectionClass->hasMethod('__wakeup');

$unsetPublicProperties = [];
foreach ($this->getLazyLoadedPublicPropertiesNames($class) as $lazyPublicProperty) {
foreach ($this->getWriteableLazyLoadedPublicPropertiesNames($class) as $lazyPublicProperty) {
$unsetPublicProperties[] = '$this->' . $lazyPublicProperty;
}

Expand Down Expand Up @@ -1005,6 +1005,31 @@ private function isShortIdentifierGetter($method, ClassMetadata $class)
return false;
}

/**
* Generates the list of public properties to be lazy loaded, that are writable.
*
* @return array<int, string>
*/
public function getWriteableLazyLoadedPublicPropertiesNames(ClassMetadata $class): array
{
$properties = [];

foreach ($class->getReflectionClass()->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
$name = $property->getName();

if ((! $class->hasField($name) && ! $class->hasAssociation($name))
|| $class->isIdentifier($name)
|| (method_exists($property, 'isReadOnly') && $property->isReadOnly())
) {
continue;
}

$properties[] = $name;
}

return $properties;
}

/**
* Generates the list of public properties to be lazy loaded.
*
Expand Down