public function testRemoveDataType() { $this->dataTypeMapper->removeDataType('tinyint'); $this->assertFalse($this->dataTypeMapper->hasDataType('tinyint')); }
/** * parses type definition * * @param string $type * @throws \Dive\Schema\SchemaException * @return array */ protected function parseDbType($type) { $definition = array(); $dataType = ''; $length = null; $values = null; $match = array(); // parsing type like varchar(32) OR char(2) if (preg_match('/^(\\w+)\\((\\d+)\\)/', $type, $match)) { $dataType = $match[1]; $length = $match[2]; } else { if (preg_match('/^(\\w+)\\((\\d+),(\\d+)\\)/', $type, $match)) { $dataType = $match[1]; $length = $match[2] + 1; $definition['scale'] = $match[3]; } else { if (preg_match('/^\\w+/', $type, $match)) { $dataType = $match[0]; } } } // parsing attributes like UNSIGNED, ZEROFILL, AND BINARY if (isset($match[0])) { $attributesString = strtolower(substr($type, strlen($match[0]))); $attributesString = trim($attributesString); if (!empty($attributesString)) { $attributes = explode(' ', trim($attributesString)); foreach ($attributes as $attr) { $definition[$attr] = true; } } } $dataType = strtolower($dataType); switch ($dataType) { case 'time': $length = 5; break; case 'year': $length = 4; break; case 'enum': if (preg_match('/^enum\\((.+)\\)/i', $type, $match)) { $values = self::parseInlineValues($match[1]); } break; case 'set': if (preg_match('/^set\\((.+)\\)/i', $type, $match)) { $values = self::parseInlineValues($match[1]); } break; } if (!$this->dataTypeMapper->hasDataType($dataType)) { throw new SchemaException("Data type {$dataType} is not defined! (Found in string {$type})"); } $definition['type'] = $this->dataTypeMapper->getMappedOrmType($dataType); // get length by longest value entry if (!empty($values)) { foreach ($values as $value) { $valueStringLength = strlen($value); if ($length < $valueStringLength) { $length = $valueStringLength; } } $definition['values'] = $values; } if ($length !== null) { $definition['length'] = (int) $length; } ksort($definition); return $definition; }