/** * @backupStaticAttributes enabled */ public function testAddType() { Type::addType('mock', 'Doctrine\\Tests\\Mocks\\TypeMock'); $this->assertTrue(Type::hasType('mock')); $this->assertEquals('mock', Type::getType('mock')->getName()); }
/** * 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); } } }
/** * @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; }