Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function typeCast(Token $token)
 {
     if ($token->test(Token::T_NULL)) {
         return 0;
     } elseif ($token->test(Token::T_TRUE)) {
         return 1;
     } elseif ($token->test(Token::T_FALSE)) {
         return 0;
     } elseif ($token->test(Token::T_EMPTY)) {
         return 0;
     } elseif ($token->test(Token::T_DATE)) {
         return (int) (new \DateTime($token->getValue()))->format('YmdHis');
     } else {
         return (int) $token->getValue();
     }
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function typeCast(Token $token)
 {
     if ($token->test(Token::T_NULL)) {
         return false;
     } elseif ($token->test(Token::T_TRUE)) {
         return true;
     } elseif ($token->test(Token::T_FALSE)) {
         return false;
     } elseif ($token->test(Token::T_EMPTY)) {
         return false;
     } elseif ($token->test(Token::T_DATE)) {
         return $token->getValue() === '0000-00-00T00:00:00Z';
     } else {
         return (bool) $token->getValue();
     }
 }
Ejemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function typeCast(Token $token)
 {
     if (!$token->test(Token::T_INTEGER)) {
         throw new SyntaxErrorException('Timestamp type caster expects an integer token');
     }
     return new \DateTime('@' . $token->getValue());
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function typeCast(Token $token)
 {
     if ($token->test(Token::T_NULL)) {
         return 0.0;
     } elseif ($token->test(Token::T_TRUE)) {
         return 1.0;
     } elseif ($token->test(Token::T_FALSE)) {
         return 0.0;
     } elseif ($token->test(Token::T_EMPTY)) {
         return 0.0;
     } elseif ($token->test(Token::T_DATE)) {
         return (double) DateTime::createFromRqlFormat($token->getValue())->format('YmdHis');
     } else {
         return (double) $token->getValue();
     }
 }
Ejemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function typeCast(Token $token)
 {
     if ($token->test(Token::T_NULL)) {
         return 'null';
     } elseif ($token->test(Token::T_TRUE)) {
         return 'true';
     } elseif ($token->test(Token::T_FALSE)) {
         return 'false';
     } elseif ($token->test(Token::T_EMPTY)) {
         return '';
     } elseif ($token->test(Token::T_GLOB)) {
         return rawurldecode($token->getValue());
     } else {
         return $token->getValue();
     }
 }
 protected function getScalarValue(Token $token)
 {
     if ($token->test(Token::T_INTEGER)) {
         return $token->getValue();
     } else {
         return parent::getScalarValue($token);
     }
 }
Ejemplo n.º 7
0
 /**
  * @param Token $token
  * @return mixed
  * @throws SyntaxErrorException
  */
 protected function getScalarValue(Token $token)
 {
     if ($token->test(Token::T_FALSE)) {
         return false;
     } elseif ($token->test(Token::T_TRUE)) {
         return true;
     } elseif ($token->test(Token::T_NULL)) {
         return null;
     } elseif ($token->test(Token::T_EMPTY)) {
         return '';
     } elseif ($token->test(Token::T_DATE)) {
         return new \DateTime($token->getValue());
     } elseif ($token->test(Token::T_STRING)) {
         return $token->getValue();
     } elseif ($token->test(Token::T_INTEGER)) {
         return (int) $token->getValue();
     } elseif ($token->test(Token::T_FLOAT)) {
         return (double) $token->getValue();
     }
     throw new SyntaxErrorException(sprintf('Invalid scalar token "%s" (%s)', $token->getValue(), $token->getName()));
 }