src/TableBuilder.php
public static function checkValue($name, $type, $value, array $arg = [])
    {
        $error = 'The default value (' . $value . ') for column ' . $name . ' does not correspond to type ' . $type . '.';

        switch (strtolower($type)) {
            case 'string':
            case 'char':
                if (!\is_string($value)) {
                    throw new ColumnsValueException($error);
                }
                if (!isset($arg[ 'length' ]) || strlen($value) > $arg[ 'length' ]) {
                    throw new ColumnsValueException('The default value is larger than the specified size.');
                }

                break;
            case 'text':
                if (!\is_string($value)) {
                    throw new ColumnsValueException($error);
                }

                break;
            case 'integer':
            case 'increments':
                if (!\is_numeric($value)) {
                    throw new ColumnsValueException($error);
                }

                return (int) $value;
            case 'float':
                if (!\is_numeric($value)) {
                    throw new ColumnsValueException($error);
                }

                return (float) $value;
            case 'boolean':
                if (!\is_bool($value)) {
                    throw new ColumnsValueException($error);
                }

                break;
            case 'date':
                if (strtolower($value) === 'current_date') {
                    return 'current_date';
                }
                if (($timestamp = strtotime($value))) {
                    return date('Y-m-d', $timestamp);
                }

                throw new ColumnsValueException($error);
            case 'datetime':
                if (strtolower($value) === 'current_datetime') {
                    return 'current_datetime';
                }
                if (($timestamp = strtotime($value))) {
                    return date('Y-m-d H:i:s', $timestamp);
                }

                throw new ColumnsValueException($error);
            default:
                throw new ColumnsValueException("Type $type not supported");
        }

        return $value;
    }
public static function checkValue($name, $type, $value, array $arg = [])
    {
        $error = 'The default value (' . $value . ') for column ' . $name . ' does not correspond to type ' . $type . '.';

        switch (strtolower($type)) {
            case 'string':
            case 'char':
                if (!\is_string($value)) {
                    throw new ColumnsValueException($error);
                }
                if (!isset($arg[ 'length' ]) || strlen($value) > $arg[ 'length' ]) {
                    throw new ColumnsValueException('The default value is larger than the specified size.');
                }

                break;
            case 'text':
                if (!\is_string($value)) {
                    throw new ColumnsValueException($error);
                }

                break;
            case 'integer':
            case 'increments':
                if (!\is_numeric($value)) {
                    throw new ColumnsValueException($error);
                }

                return (int) $value;
            case 'float':
                if (!\is_numeric($value)) {
                    throw new ColumnsValueException($error);
                }

                return (float) $value;
            case 'boolean':
                if (!\is_bool($value)) {
                    throw new ColumnsValueException($error);
                }

                break;
            case 'date':
                if (strtolower($value) === 'current_date') {
                    return 'current_date';
                }
                if (($timestamp = strtotime($value))) {
                    return date('Y-m-d', $timestamp);
                }

                throw new ColumnsValueException($error);
            case 'datetime':
                if (strtolower($value) === 'current_datetime') {
                    return 'current_datetime';
                }
                if (($timestamp = strtotime($value))) {
                    return date('Y-m-d H:i:s', $timestamp);
                }

                throw new ColumnsValueException($error);
            default:
                throw new ColumnsValueException("Type $type not supported");
        }

        return $value;
    }
public static function checkValue ( $ name , $ type , $ value , array $ arg = [ ] ) { $ error = 'The default value (' . $ value . ') for column ' . $ name . ' does not correspond to type ' . $ type . '.' ; switch ( strtolower ( $ type ) ) { case 'string' : case 'char' : if ( ! \ is_string ( $ value ) ) { throw new ColumnsValueException ( $ error ) ; } if ( ! isset ( $ arg [ 'length' ] ) || strlen ( $ value ) > $ arg [ 'length' ] ) { throw new ColumnsValueException ( 'The default value is larger than the specified size.' ) ; } break ; case 'text' : if ( ! \ is_string ( $ value ) ) { throw new ColumnsValueException ( $ error ) ; } break ; case 'integer' : case 'increments' : if ( ! \ is_numeric ( $ value ) ) { throw new ColumnsValueException ( $ error ) ; } return ( int ) $ value ; case 'float' : if ( ! \ is_numeric ( $ value ) ) { throw new ColumnsValueException ( $ error ) ; } return ( float ) $ value ; case 'boolean' : if ( ! \ is_bool ( $ value ) ) { throw new ColumnsValueException ( $ error ) ; } break ; case 'date' : if ( strtolower ( $ value ) === 'current_date' ) { return 'current_date' ; } if ( ( $ timestamp = strtotime ( $ value ) ) ) { return date ( 'Y-m-d' , $ timestamp ) ; } throw new ColumnsValueException ( $ error ) ; case 'datetime' : if ( strtolower ( $ value ) === 'current_datetime' ) { return 'current_datetime' ; } if ( ( $ timestamp = strtotime ( $ value ) ) ) { return date ( 'Y-m-d H:i:s' , $ timestamp ) ; } throw new ColumnsValueException ( $ error ) ; default : throw new ColumnsValueException ( "Type $type not supported" ) ; } return $ value ; }
Retourne la valeur s'il correspond au type déclaré.
Sinon déclenche une exception.

@param string $name  Nom du champ.
@param string $type  Type de donnée (string|text|int|float|bool|char|date|datetime).
@param mixed  $value Valeur à tester.
@param array  $arg   Arguments de tests optionnels (length).

@throws ColumnsValueException
@return mixed
Retourne la valeur s il correspond au type déclaré . Sinon déclenche une exception .