Skip to content

Commit

Permalink
Merge pull request #2772 from kdambekalns/task/avoid-deprecated-orm-p…
Browse files Browse the repository at this point in the history
…roxy

TASK: Avoid deprecated Doctrine ORM proxy
  • Loading branch information
mficzel committed Mar 26, 2022
2 parents fd246dc + c3eb9de commit 7773e7b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ protected function buildLifecycleInitializationCode(Configuration $objectConfigu
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_RECREATED) {
$code .= "\n" . ' $classParents = class_parents($this);';
$code .= "\n" . ' $classImplements = class_implements($this);';
$code .= "\n" . ' $isClassProxy = array_search(\'' . $className . '\', $classParents) !== false && array_search(\'Doctrine\ORM\Proxy\Proxy\', $classImplements) !== false;' . "\n";
$code .= "\n" . ' $isClassProxy = array_search(\'' . $className . '\', $classParents) !== false && array_search(\'Doctrine\Persistence\Proxy\', $classImplements) !== false;' . "\n";
$code .= "\n" . ' if ($isSameClass || $isClassProxy) {' . "\n";
} else {
$code .= "\n" . ' if ($isSameClass) {' . "\n";
Expand Down Expand Up @@ -589,7 +589,7 @@ protected function buildLifecycleShutdownCode(Configuration $objectConfiguration
if ($cause === ObjectManagerInterface::INITIALIZATIONCAUSE_RECREATED) {
$code .= "\n" . ' $classParents = class_parents($this);';
$code .= "\n" . ' $classImplements = class_implements($this);';
$code .= "\n" . ' $isClassProxy = array_search(\'' . $className . '\', $classParents) !== false && array_search(\'Doctrine\ORM\Proxy\Proxy\', $classImplements) !== false;' . "\n";
$code .= "\n" . ' $isClassProxy = array_search(\'' . $className . '\', $classParents) !== false && array_search(\'Doctrine\Persistence\Proxy\', $classImplements) !== false;' . "\n";
$code .= "\n" . ' if ($isSameClass || $isClassProxy) {' . "\n";
} else {
$code .= "\n" . ' if ($isSameClass) {' . "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Proxy\Proxy as OrmProxy;
use Doctrine\Persistence\Proxy as DoctrineProxy;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\ObjectManagement\Configuration\Configuration;
use Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy;
Expand Down Expand Up @@ -61,7 +61,7 @@ private function Flow_serializeRelatedEntities(array $transientProperties, array
}
}
if (is_object($this->$propertyName) && !$this->$propertyName instanceof Collection) {
if ($this->$propertyName instanceof OrmProxy) {
if ($this->$propertyName instanceof DoctrineProxy) {
$className = get_parent_class($this->$propertyName);
} else {
if (isset($propertyVarTags[$propertyName])) {
Expand All @@ -71,13 +71,13 @@ private function Flow_serializeRelatedEntities(array $transientProperties, array
$className = Bootstrap::$staticObjectManager->getObjectNameByClassName(get_class($this->$propertyName));
}
}
if ($this->$propertyName instanceof PersistenceMagicInterface && !Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->isNewObject($this->$propertyName) || $this->$propertyName instanceof OrmProxy) {
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)) {
$this->Flow_Persistence_RelatedEntities = [];
$this->Flow_Object_PropertiesToSerialize[] = 'Flow_Persistence_RelatedEntities';
}
$identifier = Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->getIdentifierByObject($this->$propertyName);
if (!$identifier && $this->$propertyName instanceof OrmProxy) {
if (!$identifier && $this->$propertyName instanceof DoctrineProxy) {
$identifier = current(ObjectAccess::getProperty($this->$propertyName, '_identifier', true));
}
$this->Flow_Persistence_RelatedEntities[$propertyName] = [
Expand Down Expand Up @@ -111,18 +111,18 @@ private function Flow_searchForEntitiesAndStoreIdentifierArray($path, $propertyV
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 OrmProxy) {
} 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)) {
$this->Flow_Persistence_RelatedEntities = [];
$this->Flow_Object_PropertiesToSerialize[] = 'Flow_Persistence_RelatedEntities';
}
if ($propertyValue instanceof OrmProxy) {
if ($propertyValue instanceof DoctrineProxy) {
$className = get_parent_class($propertyValue);
} else {
$className = Bootstrap::$staticObjectManager->getObjectNameByClassName(get_class($propertyValue));
}
$identifier = Bootstrap::$staticObjectManager->get(PersistenceManagerInterface::class)->getIdentifierByObject($propertyValue);
if (!$identifier && $propertyValue instanceof OrmProxy) {
if (!$identifier && $propertyValue instanceof DoctrineProxy) {
$identifier = current(ObjectAccess::getProperty($propertyValue, '_identifier', true));
}
$this->Flow_Persistence_RelatedEntities[$originalPropertyName . '.' . $path] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* source code.
*/

use Doctrine\Persistence\Proxy as DoctrineProxy;
use Neos\Flow\Annotations as Flow;
use Neos\Error\Messages\Error;
use Neos\Flow\Persistence\Aspect\PersistenceMagicInterface;
Expand Down Expand Up @@ -97,7 +98,7 @@ public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappi
public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
{
$properties = ObjectAccess::getGettableProperties($source);
if ($source instanceof \Doctrine\ORM\Proxy\Proxy) {
if ($source instanceof DoctrineProxy) {
$className = get_parent_class($source);
} else {
$className = get_class($source);
Expand Down
3 changes: 2 additions & 1 deletion Neos.Flow/Classes/Reflection/ReflectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\PhpParser;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Persistence\Proxy as DoctrineProxy;
use Neos\Flow\Annotations as Flow;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\StringFrontend;
Expand Down Expand Up @@ -1236,7 +1237,7 @@ protected function reflectClass($className)
$this->log(sprintf('Reflecting class %s', $className), LogLevel::DEBUG);

$className = $this->cleanClassName($className);
if (strpos($className, 'Neos\Flow\Persistence\Doctrine\Proxies') === 0 && in_array(\Doctrine\ORM\Proxy\Proxy::class, class_implements($className))) {
if (strpos($className, 'Neos\Flow\Persistence\Doctrine\Proxies') === 0 && in_array(DoctrineProxy::class, class_implements($className))) {
// Somebody tried to reflect a doctrine proxy, which will have severe side effects.
// see bug http://forge.typo3.org/issues/29449 for details.
throw new Exception\InvalidClassException('The class with name "' . $className . '" is a Doctrine proxy. It is not supported to reflect doctrine proxy classes.', 1314944681);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* source code.
*/

use Doctrine\Persistence\Proxy as DoctrineProxy;
use Neos\Utility\ObjectAccess;
use Neos\Error\Messages\Result as ErrorResult;

Expand Down Expand Up @@ -87,7 +88,7 @@ protected function isValid($object)
*/
protected function isUninitializedProxy($object)
{
return ($object instanceof \Doctrine\ORM\Proxy\Proxy && $object->__isInitialized() === false);
return ($object instanceof DoctrineProxy && $object->__isInitialized() === false);
}

/**
Expand Down Expand Up @@ -119,7 +120,7 @@ protected function isValidatedAlready($object)
*/
protected function getPropertyValue($object, $propertyName)
{
if ($object instanceof \Doctrine\ORM\Proxy\Proxy) {
if ($object instanceof DoctrineProxy) {
$object->__load();
}

Expand Down
2 changes: 1 addition & 1 deletion Neos.Utility.ObjectHandling/Classes/TypeHandling.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Proxy\Proxy;
use Doctrine\Persistence\Proxy;
use Neos\Utility\Exception\InvalidTypeException;

/**
Expand Down

0 comments on commit 7773e7b

Please sign in to comment.