Skip to content
Permalink
Browse files

Implement the TypeInterface into all type subclasses and remove from …

…the Type class.
  • Loading branch information...
davidyell committed Jul 28, 2016
1 parent bdc24cc commit d63423eebdaeb41c538de732e37430a4e7dcfbe5
@@ -21,7 +21,7 @@
* Encapsulates all conversion functions for values coming from database into PHP and
* going from PHP into database.
*/
class Type implements TypeInterface
class Type
{
/**
@@ -17,17 +17,47 @@
use Cake\Core\Exception\Exception;
use Cake\Database\Driver;
use Cake\Database\Driver\Sqlserver;
use Cake\Database\Type;
use Cake\Database\TypeInterface;
use PDO;
/**
* Binary type converter.
*
* Use to convert binary data between PHP and the database types.
*/
class BinaryType extends Type
class BinaryType implements TypeInterface
{
/**
* Identifier name for this type
*
* @var string
*/
protected $_name = null;
/**
* Constructor
*
* @param string|null $name The name identifying this type
*/
public function __construct($name = null)
{
$this->_name = $name;
}
/**
* Returns the base type name that this class is inheriting.
* This is useful when extending base type for adding extra functionality
* but still want the rest of the framework to use the same assumptions it would
* do about the base type it inherits from.
*
* @return string
*/
public function getBaseType()
{
return $this->_name;
}
/**
* Convert binary data into the database format.
*
@@ -79,4 +109,19 @@ public function toStatement($value, Driver $driver)
{
return PDO::PARAM_LOB;
}
/**
* Marshalls flat data into PHP objects.
*
* Most useful for converting request data into PHP objects
* that make sense for the rest of the ORM/Database layers.
*
* @param mixed $value The value to convert.
*
* @return mixed Converted value.
*/
public function marshal($value)
{
return $value;
}
}
@@ -15,7 +15,7 @@
namespace Cake\Database\Type;
use Cake\Database\Driver;
use Cake\Database\Type;
use Cake\Database\TypeInterface;
use InvalidArgumentException;
use PDO;
@@ -24,9 +24,39 @@
*
* Use to convert bool data between PHP and the database types.
*/
class BoolType extends Type
class BoolType implements TypeInterface
{
/**
* Identifier name for this type
*
* @var string
*/
protected $_name = null;
/**
* Constructor
*
* @param string|null $name The name identifying this type
*/
public function __construct($name = null)
{
$this->_name = $name;
}
/**
* Returns the base type name that this class is inheriting.
* This is useful when extending base type for adding extra functionality
* but still want the rest of the framework to use the same assumptions it would
* do about the base type it inherits from.
*
* @return string
*/
public function getBaseType()
{
return $this->_name;
}
/**
* Convert bool data into the database format.
*
@@ -15,17 +15,18 @@
namespace Cake\Database\Type;
use Cake\Database\Driver;
use Cake\Database\Type;
use Cake\Database\TypeInterface;
use DateTimeInterface;
use Exception;
use PDO;
use RuntimeException;
/**
* Datetime type converter.
*
* Use to convert datetime instances to strings & back.
*/
class DateTimeType extends Type
class DateTimeType implements TypeInterface
{
/**
@@ -76,12 +77,19 @@ class DateTimeType extends Type
*/
protected $_className;
/**
* Identifier name for this type
*
* @var string
*/
protected $_name = null;
/**
* {@inheritDoc}
*/
public function __construct($name = null)
{
parent::__construct($name);
$this->_name = $name;
$this->_setClassName(static::$dateTimeClass, 'DateTime');
}
@@ -273,7 +281,7 @@ public function useMutable()
}
/**
* Converts a string into a DateTime object after parseing it using the locale
* Converts a string into a DateTime object after parsing it using the locale
* aware parser with the specified format.
*
* @param string $value The value to parse and convert to an object.
@@ -285,4 +293,17 @@ protected function _parseValue($value)
return $class::parseDateTime($value, $this->_localeFormat);
}
/**
* Casts given value to Statement equivalent
*
* @param mixed $value value to be converted to PDO statement
* @param \Cake\Database\Driver $driver object from which database preferences and configuration will be extracted
*
* @return mixed
*/
public function toStatement($value, Driver $driver)
{
return PDO::PARAM_STR;
}
}
@@ -15,9 +15,10 @@
namespace Cake\Database\Type;
use Cake\Database\Driver;
use Cake\Database\TypeInterface;
use DateTime;
class DateType extends DateTimeType
class DateType extends DateTimeType implements TypeInterface
{
/**
@@ -15,7 +15,7 @@
namespace Cake\Database\Type;
use Cake\Database\Driver;
use Cake\Database\Type;
use Cake\Database\TypeInterface;
use PDO;
use RuntimeException;
@@ -24,9 +24,39 @@
*
* Use to convert float/decimal data between PHP and the database types.
*/
class FloatType extends Type
class FloatType implements TypeInterface
{
/**
* Identifier name for this type
*
* @var string
*/
protected $_name = null;
/**
* Constructor
*
* @param string|null $name The name identifying this type
*/
public function __construct($name = null)
{
$this->_name = $name;
}
/**
* Returns the base type name that this class is inheriting.
* This is useful when extending base type for adding extra functionality
* but still want the rest of the framework to use the same assumptions it would
* do about the base type it inherits from.
*
* @return string
*/
public function getBaseType()
{
return $this->_name;
}
/**
* The class to use for representing number objects
*
@@ -15,7 +15,7 @@
namespace Cake\Database\Type;
use Cake\Database\Driver;
use Cake\Database\Type;
use Cake\Database\TypeInterface;
use InvalidArgumentException;
use PDO;
@@ -24,9 +24,53 @@
*
* Use to convert integer data between PHP and the database types.
*/
class IntegerType extends Type
class IntegerType implements TypeInterface
{
/**
* Identifier name for this type
*
* @var string
*/
protected $_name = null;
/**
* Constructor
*
* @param string|null $name The name identifying this type
*/
public function __construct($name = null)
{
$this->_name = $name;
}
/**
* Returns the base type name that this class is inheriting.
* This is useful when extending base type for adding extra functionality
* but still want the rest of the framework to use the same assumptions it would
* do about the base type it inherits from.
*
* @return string
*/
public function getBaseType()
{
return $this->_name;
}
/**
* Generate a new primary key value for a given type.
*
* This method can be used by types to create new primary key values
* when entities are inserted.
*
* @return mixed A new primary key value.
* @see \Cake\Database\Type\UuidType
*/
public function newId()
{
return null;
}
/**
* Convert integer data into the database format.
*
@@ -16,6 +16,7 @@
use Cake\Database\Driver;
use Cake\Database\Type;
use Cake\Database\TypeInterface;
use InvalidArgumentException;
use PDO;
@@ -24,7 +25,7 @@
*
* Use to convert string data between PHP and the database types.
*/
class StringType extends Type implements OptionalConvertInterface
class StringType extends Type implements OptionalConvertInterface, TypeInterface
{
/**
@@ -14,12 +14,14 @@
*/
namespace Cake\Database\Type;
use Cake\Database\TypeInterface;
/**
* Time type converter.
*
* Use to convert time instances to strings & back.
*/
class TimeType extends DateTimeType
class TimeType extends DateTimeType implements TypeInterface
{
/**
@@ -16,12 +16,13 @@
use Cake\Database\Driver;
use Cake\Database\Type;
use Cake\Database\TypeInterface;
use Cake\Utility\Text;
/**
* Provides behavior for the UUID type
*/
class UuidType extends StringType
class UuidType extends StringType implements TypeInterface
{
/**
@@ -33,7 +33,7 @@ public function cast($value, $type)
if (is_string($type)) {
$type = Type::build($type);
}
if ($type instanceof Type) {
if ($type instanceof TypeInterface) {
$value = $type->toDatabase($value, $this->_driver);
$type = $type->toStatement($value, $this->_driver);
}

0 comments on commit d63423e

Please sign in to comment.
You can’t perform that action at this time.