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

TASK: Avoid deprecated Doctrine ORM proxy #2772

Merged
merged 1 commit into from
Mar 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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
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
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
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