Exemplo n.º 1
0
 /** {@inheritdoc} */
 public function convertToPHPValue($value)
 {
     if (is_object($value)) {
         throw ConversionException::conversionFailed(gettype($value), $this);
     }
     return null === $value ? null : (int) $value;
 }
Exemplo n.º 2
0
 /**
  * Factory method to create type instances. Type instances are implemented as flyweights
  *
  * @param   string $name Name of the type
  * @return  Type
  * @throws  \Chaos\Common\Exceptions\ConversionException
  */
 public static function getType($name)
 {
     if (!isset(self::$typeObjects[$name])) {
         if (!isset(self::$typesMap[$name])) {
             throw ConversionException::unknownColumnType($name);
         }
         self::$typeObjects[$name] = new self::$typesMap[$name]();
     }
     return self::$typeObjects[$name];
 }
Exemplo n.º 3
0
 /** {@inheritdoc} */
 public function convertToPHPValue($value)
 {
     if (null === $value || $value instanceof \DateTime) {
         return $value;
     }
     $val = date_create($value);
     if (!$val) {
         throw ConversionException::conversionFailed($value, $this);
     }
     return $val;
 }
Exemplo n.º 4
0
 /** {@inheritdoc} */
 public function convertToPHPValue($value)
 {
     if (null === $value || $value instanceof \DateTime) {
         return $value;
     }
     $format = @func_get_arg(1) ?: 'Y-m-d';
     $val = \DateTime::createFromFormat('!' . $format, $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this, $format);
     }
     return $val;
 }
Exemplo n.º 5
0
 /** {@inheritdoc} */
 public function convertToPHPValue($value)
 {
     if (null === $value || is_array($value)) {
         return $value;
     }
     if (is_resource($value)) {
         $value = stream_get_contents($value);
     }
     $val = @unserialize($value);
     if (false === $val && 'b:0;' !== $value) {
         throw ConversionException::conversionFailed($value, $this);
     }
     return $val;
 }
Exemplo n.º 6
0
 /** {@inheritdoc} */
 public function convertToPHPValue($value)
 {
     if (null === $value) {
         return null;
     }
     if (is_string($value)) {
         $stream = fopen('php://memory', 'r+b');
         fwrite($stream, $value);
         rewind($stream);
         $value = $stream;
     }
     if (!is_resource($value)) {
         throw ConversionException::conversionFailed($value, $this);
     }
     return $value;
 }
Exemplo n.º 7
0
 /** {@inheritdoc} */
 public function convertToPHPValue($value)
 {
     if (null === $value) {
         return null;
     } elseif (is_string($value) && class_exists($value, false)) {
         return (new \ReflectionClass($value))->newInstanceWithoutConstructor();
     }
     if (is_resource($value)) {
         $value = stream_get_contents($value);
     }
     $val = @unserialize($value);
     if (false === $val && 'b:0;' !== $value) {
         throw ConversionException::conversionFailed($value, $this);
     }
     return $val;
 }