A Type object is obtained by calling the static {@link getType()} method.
Since: 2.0
Author: Richard Fullmer (richard.fullmer@opensoftdev.com)
Example #1
0
 /**
  * @param WriterHelper $writer
  * @param ClassMetadata $classMetadata
  * @param string $fieldName
  * @param mixed $fieldValue
  */
 private function _writeText(WriterHelper $writer, ClassMetadata $classMetadata, $fieldName, $fieldValue)
 {
     $xmlName = $classMetadata->getFieldXmlName($fieldName);
     $type = $classMetadata->getTypeOfField($fieldName);
     $mapping = $classMetadata->getFieldMapping($fieldName);
     $prefix = isset($mapping['prefix']) ? $mapping['prefix'] : null;
     if ($classMetadata->isCollection($fieldName)) {
         if ($classMetadata->hasFieldWrapping($fieldName)) {
             $writer->startElement($mapping['wrapper'], $prefix);
         }
         foreach ($fieldValue as $value) {
             $writer->writeElement($xmlName, Type::getType($type)->convertToXmlValue($value), $prefix);
         }
         if ($classMetadata->hasFieldWrapping($fieldName)) {
             $writer->endElement();
         }
     } else {
         $writer->writeElement($xmlName, Type::getType($type)->convertToXmlValue($fieldValue), $prefix);
     }
 }
 /**
  * Complete and validate type mappings
  *
  * @param string $className
  * @param ClassMetadataInfo $class
  */
 private function completeMappingTypeValidation($className, ClassMetadataInfo $class)
 {
     foreach ($class->fieldMappings as $fieldName => $mapping) {
         if (Type::hasType($mapping['type'])) {
             continue;
         }
         // Support type as a mapped class?
         if (!$this->hasMetadataFor($mapping['type']) && !$this->getMetadataFor($mapping['type'])) {
             throw MappingException::fieldTypeNotFound($className, $fieldName, $mapping['type']);
         }
         // Mapped classes must have binding node type XML_ELEMENT
         if ($mapping['node'] !== ClassMetadataInfo::XML_ELEMENT) {
             throw MappingException::customTypeWithoutNodeElement($className, $fieldName);
         }
     }
 }
Example #3
0
 private function generateXmlEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null)
 {
     $methodName = $type . Inflector::classify($fieldName);
     if ($this->hasMethod($methodName, $metadata)) {
         return;
     }
     $var = sprintf('%sMethodTemplate', $type);
     $template = self::${$var};
     $variableType = $typeHint ? $typeHint . ' ' : null;
     $types = \Doctrine\OXM\Types\Type::getTypesMap();
     $methodTypeHint = $typeHint && !isset($types[$typeHint]) ? '\\' . $typeHint . ' ' : null;
     $replacements = array('<description>' => ucfirst($type) . ' ' . $fieldName, '<methodTypeHint>' => $methodTypeHint, '<variableType>' => $variableType, '<variableName>' => Inflector::camelize($fieldName), '<methodName>' => $methodName, '<fieldName>' => $fieldName);
     $method = str_replace(array_keys($replacements), array_values($replacements), $template);
     return $this->prefixCodeWithSpaces($method);
 }
Example #4
0
 protected function setUp()
 {
     $this->_type = Type::getType('datetime');
 }
Example #5
0
 protected function setUp()
 {
     $this->_type = Type::getType('string');
 }
Example #6
0
 /**
  * @backupStaticAttributes enabled
  */
 public function testOverrideTypeAlreadyInstantiated()
 {
     Type::getType('string');
     Type::overrideType('string', 'Doctrine\\Tests\\Mocks\\TypeMock');
     $this->assertInstanceOf('Doctrine\\Tests\\Mocks\\TypeMock', Type::getType('string'));
 }
Example #7
0
 protected function setUp()
 {
     $this->_type = Type::getType('float');
 }
Example #8
0
 protected function setUp()
 {
     $this->_type = Type::getType('array');
 }
Example #9
0
 /**
  * @param array
  * @return void
  */
 public function mapField(array $mapping)
 {
     // Check mandatory fields
     if (!isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) {
         throw MappingException::missingFieldName($this->name);
     }
     if (isset($this->fieldMappings[$mapping['fieldName']])) {
         $existingMapping = $this->fieldMappings[$mapping['fieldName']];
         // only complain if one exists for this class, and not any parents
         if (!isset($existingMapping['declared'])) {
             throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']);
         } elseif ($existingMapping['declared'] == $this->rootXmlEntityName) {
             throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']);
         }
     }
     if (!isset($mapping['type']) || strlen($mapping['type']) == 0) {
         throw MappingException::missingFieldType($this->name, $mapping['fieldName']);
     }
     if (!isset($mapping['name'])) {
         $mapping['name'] = Inflector::xmlize($mapping['fieldName']);
     } else {
         if ($mapping['name'][0] == '`') {
             $mapping['name'] = trim($mapping['name'], '`');
             $mapping['quoted'] = true;
         }
     }
     if (isset($this->xmlFieldMap[$mapping['name']])) {
         $existingMapping = $this->fieldMappings[$this->xmlFieldMap[$mapping['name']]];
         if (!isset($existingMapping['declared'])) {
             throw MappingException::duplicateXmlFieldName($this->name, $mapping['name']);
         } elseif ($existingMapping['declared'] == $this->rootXmlEntityName) {
             throw MappingException::duplicateXmlFieldName($this->name, $mapping['name']);
         }
     }
     if (!isset($mapping['node'])) {
         if (Type::hasType($mapping['type'])) {
             // Map object and array to "text", everything else to "attribute"
             if (in_array($mapping['type'], array(Type::OBJECT, Type::TARRAY))) {
                 $mapping['node'] = self::XML_TEXT;
             } else {
                 $mapping['node'] = self::XML_ATTRIBUTE;
             }
         } else {
             $mapping['node'] = self::XML_ELEMENT;
         }
     }
     if (!in_array($mapping['node'], self::getXmlNodeTypes())) {
         throw MappingException::xmlBindingTypeUnknown($mapping['fieldName'], $mapping['node']);
     }
     if (!isset($mapping['direct'])) {
         $mapping['direct'] = true;
     }
     if (!isset($mapping['nullable'])) {
         $mapping['nullable'] = false;
     }
     if (!isset($mapping['required'])) {
         $mapping['required'] = false;
     }
     if (!isset($mapping['container'])) {
         $mapping['container'] = false;
     }
     if (!isset($mapping['collection'])) {
         $mapping['collection'] = false;
     }
     if (!isset($mapping['getMethod'])) {
         $mapping['getMethod'] = $this->inferGetter($mapping['fieldName']);
     }
     if (!isset($mapping['setMethod'])) {
         $mapping['setMethod'] = $this->inferSetter($mapping['fieldName']);
     }
     if (!isset($mapping['id'])) {
         $mapping['id'] = false;
     } else {
         $this->identifier = $mapping['fieldName'];
     }
     $this->xmlFieldMap[$mapping['name']] = $mapping['fieldName'];
     $this->fieldMappings[$mapping['fieldName']] = $mapping;
     return $mapping;
 }
Example #10
0
 protected function setUp()
 {
     $this->_type = Type::getType('date');
     $this->_tz = date_default_timezone_get();
 }
Example #11
0
 protected function setUp()
 {
     $this->_type = Type::getType('integer');
 }