Overview

Namespaces

  • Inlm
    • SchemaGenerator
      • Adapters
      • Bridges
        • PhpCli
      • Diffs
      • Dumpers
      • Extractors
      • Integrations
      • Loggers
      • Utils

Classes

  • Inlm\SchemaGenerator\Adapters\DibiAdapter
  • Inlm\SchemaGenerator\Adapters\MemoryAdapter
  • Inlm\SchemaGenerator\Adapters\NeonAdapter
  • Inlm\SchemaGenerator\Bridges\Dibi
  • Inlm\SchemaGenerator\Bridges\DibiMysql
  • Inlm\SchemaGenerator\Bridges\PhpCli\CreateMigrationCommand
  • Inlm\SchemaGenerator\Bridges\PhpCli\DiffCommand
  • Inlm\SchemaGenerator\Bridges\PhpCli\InitFromDatabaseCommand
  • Inlm\SchemaGenerator\Bridges\PhpCli\UpdateDatabaseCommand
  • Inlm\SchemaGenerator\Configuration
  • Inlm\SchemaGenerator\ConfigurationFactory
  • Inlm\SchemaGenerator\ConfigurationSerializer
  • Inlm\SchemaGenerator\Database
  • Inlm\SchemaGenerator\DataType
  • Inlm\SchemaGenerator\DiffGenerator
  • Inlm\SchemaGenerator\Diffs\AddedTableOption
  • Inlm\SchemaGenerator\Diffs\CreatedForeignKey
  • Inlm\SchemaGenerator\Diffs\CreatedTable
  • Inlm\SchemaGenerator\Diffs\CreatedTableColumn
  • Inlm\SchemaGenerator\Diffs\CreatedTableIndex
  • Inlm\SchemaGenerator\Diffs\RemovedForeignKey
  • Inlm\SchemaGenerator\Diffs\RemovedTable
  • Inlm\SchemaGenerator\Diffs\RemovedTableColumn
  • Inlm\SchemaGenerator\Diffs\RemovedTableIndex
  • Inlm\SchemaGenerator\Diffs\RemovedTableOption
  • Inlm\SchemaGenerator\Diffs\UpdatedForeignKey
  • Inlm\SchemaGenerator\Diffs\UpdatedTable
  • Inlm\SchemaGenerator\Diffs\UpdatedTableColumn
  • Inlm\SchemaGenerator\Diffs\UpdatedTableComment
  • Inlm\SchemaGenerator\Diffs\UpdatedTableIndex
  • Inlm\SchemaGenerator\Diffs\UpdatedTableOption
  • Inlm\SchemaGenerator\Dumpers\AbstractSqlDumper
  • Inlm\SchemaGenerator\Dumpers\DibiDumper
  • Inlm\SchemaGenerator\Dumpers\NullDumper
  • Inlm\SchemaGenerator\Dumpers\SqlDumper
  • Inlm\SchemaGenerator\Dumpers\SqlMemoryDumper
  • Inlm\SchemaGenerator\Extractors\DibiExtractor
  • Inlm\SchemaGenerator\Extractors\LeanMapperExtractor
  • Inlm\SchemaGenerator\Extractors\NeonExtractor
  • Inlm\SchemaGenerator\Integrations\AbstractIntegration
  • Inlm\SchemaGenerator\Integrations\LeanMapperIntegration
  • Inlm\SchemaGenerator\Loggers\MemoryLogger
  • Inlm\SchemaGenerator\Loggers\OutputLogger
  • Inlm\SchemaGenerator\SchemaGenerator
  • Inlm\SchemaGenerator\Utils\DataTypeParser
  • Inlm\SchemaGenerator\Utils\DataTypeProcessor
  • Inlm\SchemaGenerator\Utils\Generator
  • Inlm\SchemaGenerator\Utils\GeneratorColumn
  • Inlm\SchemaGenerator\Utils\GeneratorHasManyTable
  • Inlm\SchemaGenerator\Utils\GeneratorIndex
  • Inlm\SchemaGenerator\Utils\GeneratorTable

Interfaces

  • Inlm\SchemaGenerator\IAdapter
  • Inlm\SchemaGenerator\IDumper
  • Inlm\SchemaGenerator\IExtractor
  • Inlm\SchemaGenerator\IIntegration
  • Inlm\SchemaGenerator\ILogger

Exceptions

  • Inlm\SchemaGenerator\DuplicatedException
  • Inlm\SchemaGenerator\EmptyException
  • Inlm\SchemaGenerator\Exception
  • Inlm\SchemaGenerator\FileSystemException
  • Inlm\SchemaGenerator\IncompatibleException
  • Inlm\SchemaGenerator\InvalidArgumentException
  • Inlm\SchemaGenerator\InvalidStateException
  • Inlm\SchemaGenerator\MissingArgumentException
  • Inlm\SchemaGenerator\MissingException
  • Inlm\SchemaGenerator\StaticClassException
  • Inlm\SchemaGenerator\UnsupportedException
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 
<?php

    namespace Inlm\SchemaGenerator\Utils;

    use CzProject\SqlSchema;
    use Inlm\SchemaGenerator\DataType;
    use Inlm\SchemaGenerator\DuplicatedException;
    use Inlm\SchemaGenerator\InvalidArgumentException;
    use Inlm\SchemaGenerator\MissingException;
    use Inlm\SchemaGenerator\StaticClassException;


    class DataTypeProcessor
    {
        public function __construct()
        {
            throw new StaticClassException('This is static class.');
        }


        /**
         * @param  string|NULL
         * @param  DataType|NULL
         * @param  bool
         * @param  array  [type => DataType]
         * @param  string|NULL
         * @return DataType
         */
        public static function process($inputType, DataType $dbType = NULL, $isPrimaryColumn = FALSE, array $customTypes = array(), $databaseType = NULL)
        {
            $type = NULL;
            $parameters = array();
            $options = array();

            if ($inputType !== NULL) {
                // predefined & custom types
                $inputType = strtolower($inputType);

                if (isset($customTypes[$inputType])) {
                    $columnType = $customTypes[$inputType];
                    $type = $columnType->getType();
                    $parameters = $columnType->getParameters();
                    $options = $columnType->getOptions();

                } elseif ($inputType === 'integer' || $inputType === 'int') {
                    $type = 'INT';

                    if ($isPrimaryColumn) {
                        $options[] = SqlSchema\Column::OPTION_UNSIGNED;
                    }

                } elseif ($inputType === 'boolean' || $inputType === 'bool') {
                    $type = 'TINYINT';
                    $parameters = array(1);
                    $options[] = SqlSchema\Column::OPTION_UNSIGNED;

                } elseif ($inputType === 'float' || $inputType === 'double') {
                    $type = 'DOUBLE';

                } elseif ($inputType === 'string') {
                    $type = 'TEXT';

                } elseif ($inputType === 'datetime' || $inputType === 'datetimeinterface') {
                    $type = 'DATETIME';
                }
            }

            if ($dbType !== NULL) {
                if ($dbType->getType() !== NULL) {
                    $type = $dbType->getType();
                    $lowerType = strtolower($type);

                    if (isset($customTypes[$lowerType])) {
                        $columnType = $customTypes[$lowerType];
                        $type = $columnType->getType();
                        $parameters = $columnType->getParameters();
                        $options = $columnType->getOptions();
                    }
                }

                if ($dbType->getParameters() !== NULL) {
                    $parameters = $dbType->getParameters();
                }

                foreach ($dbType->getOptions() as $k => $v) {
                    if (is_int($k)) {
                        $options[$v] = NULL;

                    } else {
                        $options[$k] = $v;
                    }
                }
            }

            if ($type === NULL) {
                throw new MissingException('Missing type.');
            }

            return new DataType($type, $parameters, $options);
        }
    }
inlm/schema-generator master API documentation API documentation generated by ApiGen