/** * Check if the referenced column name is set (and valid) and if not make sure * it is initialized properly. * * @param array $joinColumns * @param array $mapping * @param \ReflectionProperty $property * @param integer $direction regular or inverse mapping (use is to be coded) * @return array */ protected function buildJoinColumnsIfNeeded(array $joinColumns, array $mapping, \ReflectionProperty $property, $direction = self::MAPPING_REGULAR) { if ($joinColumns === array()) { $joinColumns[] = array('name' => strtolower($property->getName()), 'referencedColumnName' => null); } foreach ($joinColumns as &$joinColumn) { if ($joinColumn['referencedColumnName'] === null || $joinColumn['referencedColumnName'] === 'id') { if ($direction === self::MAPPING_REGULAR) { $idProperties = $this->reflectionService->getPropertyNamesByTag($mapping['targetEntity'], 'id'); $joinColumnName = $this->buildJoinTableColumnName($mapping['targetEntity']); } else { $className = $this->getUnproxiedClassName($property->getDeclaringClass()->getName()); $idProperties = $this->reflectionService->getPropertyNamesByTag($className, 'id'); $joinColumnName = $this->buildJoinTableColumnName($className); } if (count($idProperties) === 0) { $joinColumn['name'] = $joinColumn['name'] === null ? $joinColumnName : $joinColumn['name']; $joinColumn['referencedColumnName'] = strtolower('Persistence_Object_Identifier'); } elseif (count($idProperties) === 1) { $joinColumn['name'] = $joinColumn['name'] === null ? $joinColumnName : $joinColumn['name']; $joinColumn['referencedColumnName'] = strtolower(current($idProperties)); } } } return $joinColumns; }
/** * Check if the referenced column name is set (and valid) and if not make sure * it is initialized properly. * * @param array $joinColumns * @param array $mapping * @param \ReflectionProperty $property * @param integer $direction regular or inverse mapping (use is to be coded) * @return array */ protected function buildJoinColumnsIfNeeded(array $joinColumns, array $mapping, \ReflectionProperty $property, $direction = self::MAPPING_REGULAR) { if ($joinColumns === array()) { $joinColumns[] = array('name' => strtolower($property->getName()), 'referencedColumnName' => NULL); } foreach ($joinColumns as &$joinColumn) { if ($joinColumn['referencedColumnName'] === NULL || $joinColumn['referencedColumnName'] === 'id') { if ($direction === self::MAPPING_REGULAR) { $idProperties = $this->reflectionService->getPropertyNamesByTag($mapping['targetEntity'], 'id'); $joinColumnName = $this->buildJoinTableColumnName($mapping['targetEntity']); } else { $className = preg_replace('/' . \TYPO3\Flow\Object\Proxy\Compiler::ORIGINAL_CLASSNAME_SUFFIX . '$/', '', $property->getDeclaringClass()->getName()); $idProperties = $this->reflectionService->getPropertyNamesByTag($className, 'id'); $joinColumnName = $this->buildJoinTableColumnName($className); } if (count($idProperties) === 0) { $joinColumn['name'] = $joinColumn['name'] === NULL ? $joinColumnName : $joinColumn['name']; $joinColumn['referencedColumnName'] = strtolower('Persistence_Object_Identifier'); } elseif (count($idProperties) === 1) { $joinColumn['name'] = $joinColumn['name'] === NULL ? $joinColumnName : $joinColumn['name']; $joinColumn['referencedColumnName'] = strtolower(current($idProperties)); } } } return $joinColumns; }
/** * Returns the identifier for the given object either from * the session, if the object was registered, or from the object * itself using a special uuid property or the internal * properties set by AOP. * * Note: this returns an UUID even if the object has not been persisted * in case of AOP-managed entities. Use isNewObject() if you need * to distinguish those cases. * * @param object $object * @return string * @api */ public function getIdentifierByObject($object) { if ($this->hasObject($object)) { return $this->objectMap[$object]; } $idPropertyNames = $this->reflectionService->getPropertyNamesByTag(get_class($object), 'id'); if (count($idPropertyNames) === 1) { $idPropertyName = $idPropertyNames[0]; return \TYPO3\Flow\Reflection\ObjectAccess::getProperty($object, $idPropertyName, true); } elseif (property_exists($object, 'Persistence_Object_Identifier')) { return \TYPO3\Flow\Reflection\ObjectAccess::getProperty($object, 'Persistence_Object_Identifier', true); } return null; }
/** * Renders code to create identifier/type information from related entities in an object. * Used in sleep methods. * * @param Configuration $objectConfiguration * @return string */ protected function buildSerializeRelatedEntitiesCode(Configuration $objectConfiguration) { $className = $objectConfiguration->getClassName(); $code = ''; if ($this->reflectionService->hasMethod($className, '__sleep') === false) { $transientProperties = $this->reflectionService->getPropertyNamesByAnnotation($className, 'TYPO3\\Flow\\Annotations\\Transient'); $propertyVarTags = []; foreach ($this->reflectionService->getPropertyNamesByTag($className, 'var') as $propertyName) { $varTagValues = $this->reflectionService->getPropertyTagValues($className, $propertyName, 'var'); $propertyVarTags[$propertyName] = isset($varTagValues[0]) ? $varTagValues[0] : null; } $code = "\t\t\$this->Flow_Object_PropertiesToSerialize = array();\n\n\t\$transientProperties = " . var_export($transientProperties, true) . ";\n\t\$propertyVarTags = " . var_export($propertyVarTags, true) . ";\n\t\$reflectedClass = new \\ReflectionClass('" . $className . "');\n\t\$allReflectedProperties = \$reflectedClass->getProperties();\n\tforeach (\$allReflectedProperties as \$reflectionProperty) {\n\t\t\$propertyName = \$reflectionProperty->name;\n\t\tif (in_array(\$propertyName, array('Flow_Aop_Proxy_targetMethodsAndGroupedAdvices', 'Flow_Aop_Proxy_groupedAdviceChains', 'Flow_Aop_Proxy_methodIsInAdviceMode'))) continue;\n\t\tif (isset(\$this->Flow_Injected_Properties) && is_array(\$this->Flow_Injected_Properties) && in_array(\$propertyName, \$this->Flow_Injected_Properties)) continue;\n\t\tif (\$reflectionProperty->isStatic() || in_array(\$propertyName, \$transientProperties)) continue;\n\t\tif (is_array(\$this->\$propertyName) || (is_object(\$this->\$propertyName) && (\$this->\$propertyName instanceof \\ArrayObject || \$this->\$propertyName instanceof \\SplObjectStorage ||\$this->\$propertyName instanceof \\Doctrine\\Common\\Collections\\Collection))) {\n\t\t\tif (count(\$this->\$propertyName) > 0) {\n\t\t\t\tforeach (\$this->\$propertyName as \$key => \$value) {\n\t\t\t\t\t\$this->searchForEntitiesAndStoreIdentifierArray((string)\$key, \$value, \$propertyName);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (is_object(\$this->\$propertyName) && !\$this->\$propertyName instanceof \\Doctrine\\Common\\Collections\\Collection) {\n\t\t\tif (\$this->\$propertyName instanceof \\Doctrine\\ORM\\Proxy\\Proxy) {\n\t\t\t\t\$className = get_parent_class(\$this->\$propertyName);\n\t\t\t} else {\n\t\t\t\tif (isset(\$propertyVarTags[\$propertyName])) {\n\t\t\t\t\t\$className = trim(\$propertyVarTags[\$propertyName], '\\\\');\n\t\t\t\t}\n\t\t\t\tif (\\TYPO3\\Flow\\Core\\Bootstrap::\$staticObjectManager->isRegistered(\$className) === FALSE) {\n\t\t\t\t\t\$className = \\TYPO3\\Flow\\Core\\Bootstrap::\$staticObjectManager->getObjectNameByClassName(get_class(\$this->\$propertyName));\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\$this->\$propertyName instanceof \\TYPO3\\Flow\\Persistence\\Aspect\\PersistenceMagicInterface && !\\TYPO3\\Flow\\Core\\Bootstrap::\$staticObjectManager->get(\\TYPO3\\Flow\\Persistence\\PersistenceManagerInterface::class)->isNewObject(\$this->\$propertyName) || \$this->\$propertyName instanceof \\Doctrine\\ORM\\Proxy\\Proxy) {\n\t\t\t\tif (!property_exists(\$this, 'Flow_Persistence_RelatedEntities') || !is_array(\$this->Flow_Persistence_RelatedEntities)) {\n\t\t\t\t\t\$this->Flow_Persistence_RelatedEntities = array();\n\t\t\t\t\t\$this->Flow_Object_PropertiesToSerialize[] = 'Flow_Persistence_RelatedEntities';\n\t\t\t\t}\n\t\t\t\t\$identifier = \\TYPO3\\Flow\\Core\\Bootstrap::\$staticObjectManager->get(\\TYPO3\\Flow\\Persistence\\PersistenceManagerInterface::class)->getIdentifierByObject(\$this->\$propertyName);\n\t\t\t\tif (!\$identifier && \$this->\$propertyName instanceof \\Doctrine\\ORM\\Proxy\\Proxy) {\n\t\t\t\t\t\$identifier = current(\\TYPO3\\Flow\\Reflection\\ObjectAccess::getProperty(\$this->\$propertyName, '_identifier', TRUE));\n\t\t\t\t}\n\t\t\t\t\$this->Flow_Persistence_RelatedEntities[\$propertyName] = array(\n\t\t\t\t\t'propertyName' => \$propertyName,\n\t\t\t\t\t'entityType' => \$className,\n\t\t\t\t\t'identifier' => \$identifier\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (\$className !== FALSE && (\\TYPO3\\Flow\\Core\\Bootstrap::\$staticObjectManager->getScope(\$className) === \\TYPO3\\Flow\\Object\\Configuration\\Configuration::SCOPE_SINGLETON || \$className === \\TYPO3\\Flow\\Object\\DependencyInjection\\DependencyProxy::class)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\t\$this->Flow_Object_PropertiesToSerialize[] = \$propertyName;\n\t}\n\t\$result = \$this->Flow_Object_PropertiesToSerialize;\n"; } return $code; }
/** * Renders code to create identifier/type information from related entities in an object. * Used in sleep methods. * * @param Configuration $objectConfiguration * @return string */ protected function buildSerializeRelatedEntitiesCode(Configuration $objectConfiguration) { $className = $objectConfiguration->getClassName(); $code = ''; if ($this->reflectionService->hasMethod($className, '__sleep') === false) { $transientProperties = $this->reflectionService->getPropertyNamesByAnnotation($className, 'TYPO3\\Flow\\Annotations\\Transient'); $propertyVarTags = []; foreach ($this->reflectionService->getPropertyNamesByTag($className, 'var') as $propertyName) { $varTagValues = $this->reflectionService->getPropertyTagValues($className, $propertyName, 'var'); $propertyVarTags[$propertyName] = isset($varTagValues[0]) ? $varTagValues[0] : null; } $code = " \$this->Flow_Object_PropertiesToSerialize = array();\n\n \$transientProperties = " . var_export($transientProperties, true) . ";\n \$propertyVarTags = " . var_export($propertyVarTags, true) . ";\n \$result = \$this->Flow_serializeRelatedEntities(\$transientProperties, \$propertyVarTags);\n"; } return $code; }