Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: No usage of dynamic properties #3032

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions Neos.Flow/Classes/Aop/Builder/ProxyClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public function buildProxyClass(string $targetClassName, array &$aspectContainer
$proxyClass->addProperty($propertyName, var_export($propertyIntroduction->getInitialValue(), true), $propertyIntroduction->getPropertyVisibility(), $propertyIntroduction->getPropertyDocComment());
}

$proxyClass->getMethod('Flow_Aop_Proxy_buildMethodsAndAdvicesArray')->addPreParentCallCode(" if (method_exists(get_parent_class(), 'Flow_Aop_Proxy_buildMethodsAndAdvicesArray') && is_callable('parent::Flow_Aop_Proxy_buildMethodsAndAdvicesArray')) parent::Flow_Aop_Proxy_buildMethodsAndAdvicesArray();\n");
$proxyClass->getMethod('Flow_Aop_Proxy_buildMethodsAndAdvicesArray')->addPreParentCallCode(" if (method_exists(get_parent_class(), 'Flow_Aop_Proxy_buildMethodsAndAdvicesArray') && is_callable([parent::class, 'Flow_Aop_Proxy_buildMethodsAndAdvicesArray'])) parent::Flow_Aop_Proxy_buildMethodsAndAdvicesArray();\n");
$proxyClass->getMethod('Flow_Aop_Proxy_buildMethodsAndAdvicesArray')->addPreParentCallCode($this->buildMethodsAndAdvicesArrayCode($interceptedMethods));
$proxyClass->getMethod('Flow_Aop_Proxy_buildMethodsAndAdvicesArray')->overrideMethodVisibility('protected');

Expand All @@ -462,7 +462,7 @@ public function buildProxyClass(string $targetClassName, array &$aspectContainer
$proxyClass->getMethod('__clone')->addPreParentCallCode($callBuildMethodsAndAdvicesArrayCode);

if (!$this->reflectionService->hasMethod($targetClassName, '__wakeup')) {
$proxyClass->getMethod('__wakeup')->addPostParentCallCode(" if (method_exists(get_parent_class(), '__wakeup') && is_callable('parent::__wakeup')) parent::__wakeup();\n");
$proxyClass->getMethod('__wakeup')->addPostParentCallCode(" if (method_exists(get_parent_class(), '__wakeup') && is_callable([parent::class, '__wakeup'])) parent::__wakeup();\n");
}

$proxyClass->addTraits(['\\' . AdvicesTrait::class]);
Expand Down Expand Up @@ -531,7 +531,7 @@ protected function addBuildMethodsAndAdvicesCodeToClass(string $className, Class
return $treatedSubClasses;
}

$callBuildMethodsAndAdvicesArrayCode = " if (method_exists(get_parent_class(), 'Flow_Aop_Proxy_buildMethodsAndAdvicesArray') && is_callable('parent::Flow_Aop_Proxy_buildMethodsAndAdvicesArray')) parent::Flow_Aop_Proxy_buildMethodsAndAdvicesArray();\n";
$callBuildMethodsAndAdvicesArrayCode = " if (method_exists(get_parent_class(), 'Flow_Aop_Proxy_buildMethodsAndAdvicesArray') && is_callable([parent::class, 'Flow_Aop_Proxy_buildMethodsAndAdvicesArray'])) parent::Flow_Aop_Proxy_buildMethodsAndAdvicesArray();\n";
$proxyClass->getConstructor()->addPreParentCallCode($callBuildMethodsAndAdvicesArrayCode);
$proxyClass->getMethod('__wakeup')->addPreParentCallCode($callBuildMethodsAndAdvicesArrayCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
trait PropertyInjectionTrait
{
protected array $Flow_Injected_Properties = [];

/**
* Does a property injection lazily with fallbacks.
* Used in proxy classes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
*/
trait ObjectSerializationTrait
{
protected array $Flow_Object_PropertiesToSerialize = [];

protected ?array $Flow_Persistence_RelatedEntities = null;

/**
* Code to find and serialize entities on sleep
*
Expand All @@ -45,17 +49,20 @@ private function Flow_serializeRelatedEntities(array $transientProperties, array
if (in_array($propertyName, [
'Flow_Aop_Proxy_targetMethodsAndGroupedAdvices',
'Flow_Aop_Proxy_groupedAdviceChains',
'Flow_Aop_Proxy_methodIsInAdviceMode'
'Flow_Aop_Proxy_methodIsInAdviceMode',
'Flow_Persistence_RelatedEntities',
'Flow_Object_PropertiesToSerialize',
'Flow_Injected_Properties',
])) {
continue;
}
if (isset($this->Flow_Injected_Properties) && is_array($this->Flow_Injected_Properties) && in_array($propertyName, $this->Flow_Injected_Properties)) {
if (property_exists($this, 'Flow_Injected_Properties') && is_array($this->Flow_Injected_Properties) && in_array($propertyName, $this->Flow_Injected_Properties, true)) {
continue;
}
if ($reflectionProperty->isStatic() || in_array($propertyName, $transientProperties)) {
if ($reflectionProperty->isStatic() || in_array($propertyName, $transientProperties, true)) {
continue;
}
if (is_array($this->$propertyName) || (is_object($this->$propertyName) && ($this->$propertyName instanceof \ArrayObject || $this->$propertyName instanceof \SplObjectStorage || $this->$propertyName instanceof Collection))) {
if (is_array($this->$propertyName) || ($this->$propertyName instanceof \ArrayObject || $this->$propertyName instanceof \SplObjectStorage || $this->$propertyName instanceof Collection)) {
if (count($this->$propertyName) > 0) {
foreach ($this->$propertyName as $key => $value) {
$this->Flow_searchForEntitiesAndStoreIdentifierArray((string)$key, $value, $propertyName);
Expand All @@ -69,14 +76,14 @@ private function Flow_serializeRelatedEntities(array $transientProperties, array
if (isset($propertyVarTags[$propertyName])) {
$className = trim($propertyVarTags[$propertyName], '\\');
} else {
$className = $reflectionProperty->getType()->getName();
$className = $reflectionProperty->getType()?->getName();
}
if (Bootstrap::$staticObjectManager->isRegistered($className) === false) {
$className = Bootstrap::$staticObjectManager->getObjectNameByClassName(get_class($this->$propertyName));
}
}
if ($this->$propertyName instanceof PersistenceMagicInterface && !Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->isNewObject($this->$propertyName) || $this->$propertyName instanceof DoctrineProxy) {
if (!property_exists($this, 'Flow_Persistence_RelatedEntities') || !is_array($this->Flow_Persistence_RelatedEntities)) {
if ($this->$propertyName instanceof DoctrineProxy || ($this->$propertyName instanceof PersistenceMagicInterface && !Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->isNewObject($this->$propertyName))) {
if (!isset($this->Flow_Persistence_RelatedEntities) || !is_array($this->Flow_Persistence_RelatedEntities)) {
$this->Flow_Persistence_RelatedEntities = [];
$this->Flow_Object_PropertiesToSerialize[] = 'Flow_Persistence_RelatedEntities';
}
Expand Down Expand Up @@ -109,14 +116,14 @@ private function Flow_serializeRelatedEntities(array $transientProperties, array
* @param string $originalPropertyName
* @return void
*/
private function Flow_searchForEntitiesAndStoreIdentifierArray(string $path, mixed $propertyValue, string $originalPropertyName)
private function Flow_searchForEntitiesAndStoreIdentifierArray(string $path, mixed $propertyValue, string $originalPropertyName): void
{
if (is_array($propertyValue) || ($propertyValue instanceof \ArrayObject || $propertyValue instanceof \SplObjectStorage)) {
foreach ($propertyValue as $key => $value) {
$this->Flow_searchForEntitiesAndStoreIdentifierArray($path . '.' . $key, $value, $originalPropertyName);
}
} elseif ($propertyValue instanceof PersistenceMagicInterface && !Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->isNewObject($propertyValue) || $propertyValue instanceof DoctrineProxy) {
if (!property_exists($this, 'Flow_Persistence_RelatedEntities') || !is_array($this->Flow_Persistence_RelatedEntities)) {
} elseif ($propertyValue instanceof DoctrineProxy || ($propertyValue instanceof PersistenceMagicInterface && !Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->isNewObject($propertyValue))) {
if (!isset($this->Flow_Persistence_RelatedEntities) || !is_array($this->Flow_Persistence_RelatedEntities)) {
$this->Flow_Persistence_RelatedEntities = [];
$this->Flow_Object_PropertiesToSerialize[] = 'Flow_Persistence_RelatedEntities';
}
Expand Down Expand Up @@ -145,9 +152,9 @@ private function Flow_searchForEntitiesAndStoreIdentifierArray(string $path, mix
*
* @return void
*/
private function Flow_setRelatedEntities()
private function Flow_setRelatedEntities(): void
{
if (property_exists($this, 'Flow_Persistence_RelatedEntities') && is_array($this->Flow_Persistence_RelatedEntities)) {
if (isset($this->Flow_Persistence_RelatedEntities)) {
$persistenceManager = Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class);
foreach ($this->Flow_Persistence_RelatedEntities as $entityInformation) {
$entity = $persistenceManager->getObjectByIdentifier($entityInformation['identifier'], $entityInformation['entityType'], true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function complexPropertyTypesArePreserved()
$reflectionClass = new ClassReflection(Fixtures\PHP8\ClassWithUnionTypes::class);
/** @var PropertyReflection $property */
foreach ($reflectionClass->getProperties() as $property) {
if ($property->getName() !== 'propertyA' && $property->getName() !== 'propertyB') {
if (str_starts_with($property->getName(), 'property') && $property->getName() !== 'propertyA' && $property->getName() !== 'propertyB') {
self::assertInstanceOf(\ReflectionUnionType::class, $property->getType(), $property->getName() . ': ' . $property->getType());
}
}
Expand Down