Skip to content

Commit 7773e7b

Browse files
authored
Merge pull request #2772 from kdambekalns/task/avoid-deprecated-orm-proxy
TASK: Avoid deprecated Doctrine ORM proxy
2 parents fd246dc + c3eb9de commit 7773e7b

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

Neos.Flow/Classes/ObjectManagement/DependencyInjection/ProxyClassBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ protected function buildLifecycleInitializationCode(Configuration $objectConfigu
561561
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_RECREATED) {
562562
$code .= "\n" . ' $classParents = class_parents($this);';
563563
$code .= "\n" . ' $classImplements = class_implements($this);';
564-
$code .= "\n" . ' $isClassProxy = array_search(\'' . $className . '\', $classParents) !== false && array_search(\'Doctrine\ORM\Proxy\Proxy\', $classImplements) !== false;' . "\n";
564+
$code .= "\n" . ' $isClassProxy = array_search(\'' . $className . '\', $classParents) !== false && array_search(\'Doctrine\Persistence\Proxy\', $classImplements) !== false;' . "\n";
565565
$code .= "\n" . ' if ($isSameClass || $isClassProxy) {' . "\n";
566566
} else {
567567
$code .= "\n" . ' if ($isSameClass) {' . "\n";
@@ -589,7 +589,7 @@ protected function buildLifecycleShutdownCode(Configuration $objectConfiguration
589589
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_RECREATED) {
590590
$code .= "\n" . ' $classParents = class_parents($this);';
591591
$code .= "\n" . ' $classImplements = class_implements($this);';
592-
$code .= "\n" . ' $isClassProxy = array_search(\'' . $className . '\', $classParents) !== false && array_search(\'Doctrine\ORM\Proxy\Proxy\', $classImplements) !== false;' . "\n";
592+
$code .= "\n" . ' $isClassProxy = array_search(\'' . $className . '\', $classParents) !== false && array_search(\'Doctrine\Persistence\Proxy\', $classImplements) !== false;' . "\n";
593593
$code .= "\n" . ' if ($isSameClass || $isClassProxy) {' . "\n";
594594
} else {
595595
$code .= "\n" . ' if ($isSameClass) {' . "\n";

Neos.Flow/Classes/ObjectManagement/Proxy/ObjectSerializationTrait.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
use Doctrine\Common\Collections\Collection;
15-
use Doctrine\ORM\Proxy\Proxy as OrmProxy;
15+
use Doctrine\Persistence\Proxy as DoctrineProxy;
1616
use Neos\Flow\Core\Bootstrap;
1717
use Neos\Flow\ObjectManagement\Configuration\Configuration;
1818
use Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy;
@@ -61,7 +61,7 @@ private function Flow_serializeRelatedEntities(array $transientProperties, array
6161
}
6262
}
6363
if (is_object($this->$propertyName) && !$this->$propertyName instanceof Collection) {
64-
if ($this->$propertyName instanceof OrmProxy) {
64+
if ($this->$propertyName instanceof DoctrineProxy) {
6565
$className = get_parent_class($this->$propertyName);
6666
} else {
6767
if (isset($propertyVarTags[$propertyName])) {
@@ -71,13 +71,13 @@ private function Flow_serializeRelatedEntities(array $transientProperties, array
7171
$className = Bootstrap::$staticObjectManager->getObjectNameByClassName(get_class($this->$propertyName));
7272
}
7373
}
74-
if ($this->$propertyName instanceof PersistenceMagicInterface && !Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->isNewObject($this->$propertyName) || $this->$propertyName instanceof OrmProxy) {
74+
if ($this->$propertyName instanceof PersistenceMagicInterface && !Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->isNewObject($this->$propertyName) || $this->$propertyName instanceof DoctrineProxy) {
7575
if (!property_exists($this, 'Flow_Persistence_RelatedEntities') || !is_array($this->Flow_Persistence_RelatedEntities)) {
7676
$this->Flow_Persistence_RelatedEntities = [];
7777
$this->Flow_Object_PropertiesToSerialize[] = 'Flow_Persistence_RelatedEntities';
7878
}
7979
$identifier = Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->getIdentifierByObject($this->$propertyName);
80-
if (!$identifier && $this->$propertyName instanceof OrmProxy) {
80+
if (!$identifier && $this->$propertyName instanceof DoctrineProxy) {
8181
$identifier = current(ObjectAccess::getProperty($this->$propertyName, '_identifier', true));
8282
}
8383
$this->Flow_Persistence_RelatedEntities[$propertyName] = [
@@ -111,18 +111,18 @@ private function Flow_searchForEntitiesAndStoreIdentifierArray($path, $propertyV
111111
foreach ($propertyValue as $key => $value) {
112112
$this->Flow_searchForEntitiesAndStoreIdentifierArray($path . '.' . $key, $value, $originalPropertyName);
113113
}
114-
} elseif ($propertyValue instanceof PersistenceMagicInterface && !Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->isNewObject($propertyValue) || $propertyValue instanceof OrmProxy) {
114+
} elseif ($propertyValue instanceof PersistenceMagicInterface && !Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->isNewObject($propertyValue) || $propertyValue instanceof DoctrineProxy) {
115115
if (!property_exists($this, 'Flow_Persistence_RelatedEntities') || !is_array($this->Flow_Persistence_RelatedEntities)) {
116116
$this->Flow_Persistence_RelatedEntities = [];
117117
$this->Flow_Object_PropertiesToSerialize[] = 'Flow_Persistence_RelatedEntities';
118118
}
119-
if ($propertyValue instanceof OrmProxy) {
119+
if ($propertyValue instanceof DoctrineProxy) {
120120
$className = get_parent_class($propertyValue);
121121
} else {
122122
$className = Bootstrap::$staticObjectManager->getObjectNameByClassName(get_class($propertyValue));
123123
}
124124
$identifier = Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->getIdentifierByObject($propertyValue);
125-
if (!$identifier && $propertyValue instanceof OrmProxy) {
125+
if (!$identifier && $propertyValue instanceof DoctrineProxy) {
126126
$identifier = current(ObjectAccess::getProperty($propertyValue, '_identifier', true));
127127
}
128128
$this->Flow_Persistence_RelatedEntities[$originalPropertyName . '.' . $path] = [

Neos.Flow/Classes/Property/TypeConverter/ArrayFromObjectConverter.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* source code.
1212
*/
1313

14+
use Doctrine\Persistence\Proxy as DoctrineProxy;
1415
use Neos\Flow\Annotations as Flow;
1516
use Neos\Error\Messages\Error;
1617
use Neos\Flow\Persistence\Aspect\PersistenceMagicInterface;
@@ -97,7 +98,7 @@ public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappi
9798
public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
9899
{
99100
$properties = ObjectAccess::getGettableProperties($source);
100-
if ($source instanceof \Doctrine\ORM\Proxy\Proxy) {
101+
if ($source instanceof DoctrineProxy) {
101102
$className = get_parent_class($source);
102103
} else {
103104
$className = get_class($source);

Neos.Flow/Classes/Reflection/ReflectionService.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use Doctrine\Common\Annotations\PhpParser;
1616
use Doctrine\ORM\Mapping as ORM;
17+
use Doctrine\Persistence\Proxy as DoctrineProxy;
1718
use Neos\Flow\Annotations as Flow;
1819
use Neos\Cache\Frontend\FrontendInterface;
1920
use Neos\Cache\Frontend\StringFrontend;
@@ -1236,7 +1237,7 @@ protected function reflectClass($className)
12361237
$this->log(sprintf('Reflecting class %s', $className), LogLevel::DEBUG);
12371238

12381239
$className = $this->cleanClassName($className);
1239-
if (strpos($className, 'Neos\Flow\Persistence\Doctrine\Proxies') === 0 && in_array(\Doctrine\ORM\Proxy\Proxy::class, class_implements($className))) {
1240+
if (strpos($className, 'Neos\Flow\Persistence\Doctrine\Proxies') === 0 && in_array(DoctrineProxy::class, class_implements($className))) {
12401241
// Somebody tried to reflect a doctrine proxy, which will have severe side effects.
12411242
// see bug http://forge.typo3.org/issues/29449 for details.
12421243
throw new Exception\InvalidClassException('The class with name "' . $className . '" is a Doctrine proxy. It is not supported to reflect doctrine proxy classes.', 1314944681);

Neos.Flow/Classes/Validation/Validator/GenericObjectValidator.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* source code.
1212
*/
1313

14+
use Doctrine\Persistence\Proxy as DoctrineProxy;
1415
use Neos\Utility\ObjectAccess;
1516
use Neos\Error\Messages\Result as ErrorResult;
1617

@@ -87,7 +88,7 @@ protected function isValid($object)
8788
*/
8889
protected function isUninitializedProxy($object)
8990
{
90-
return ($object instanceof \Doctrine\ORM\Proxy\Proxy && $object->__isInitialized() === false);
91+
return ($object instanceof DoctrineProxy && $object->__isInitialized() === false);
9192
}
9293

9394
/**
@@ -119,7 +120,7 @@ protected function isValidatedAlready($object)
119120
*/
120121
protected function getPropertyValue($object, $propertyName)
121122
{
122-
if ($object instanceof \Doctrine\ORM\Proxy\Proxy) {
123+
if ($object instanceof DoctrineProxy) {
123124
$object->__load();
124125
}
125126

Neos.Utility.ObjectHandling/Classes/TypeHandling.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
use Doctrine\Common\Collections\Collection;
15-
use Doctrine\ORM\Proxy\Proxy;
15+
use Doctrine\Persistence\Proxy;
1616
use Neos\Utility\Exception\InvalidTypeException;
1717

1818
/**

0 commit comments

Comments
 (0)