/** * @dataProvider getValuesTo */ public function testCastTo($native, $value) { if ($native instanceof \Exception) { $this->setExpectedException(get_class($native)); $this->converter->output($value); } else { $this->assertEquals($native, $this->converter->output($value)); } }
protected function outputNotNull($value) { if (is_array($value)) { $value = call_user_func(array($this->resultClass, 'createFromArray'), $value); } elseif (!$value instanceof Range) { throw TypeConversionException::unexpectedValue($this, 'output', 'instance of Range or an array', $value); } /* @var $value Range */ if ($value->empty) { return 'empty'; } return ($value->lowerInclusive ? '[' : '(') . (null === $value->lower ? '' : '"' . addcslashes($this->_subtype->output($value->lower), "\"\\") . '"') . ',' . (null === $value->upper ? '' : '"' . addcslashes($this->_subtype->output($value->upper), "\"\\") . '"') . ($value->upperInclusive ? ']' : ')'); }
protected function parseInput($native, &$pos) { $result = array(); $this->expectChar($native, $pos, '{'); // Leading "{". while ('}' !== ($char = $this->nextChar($native, $pos))) { // require a comma delimiter between elements if (!empty($result)) { if (',' !== $char) { throw TypeConversionException::parsingFailed($this, "','", $native, $pos); } $pos++; $char = $this->nextChar($native, $pos); } if ('{' === $char) { // parse sub-array $result[] = $this->parseInput($native, $pos); } elseif ('"' === $char) { // quoted string if (!preg_match('/"((?>[^"\\\\]+|\\\\.)*)"/As', $native, $m, 0, $pos)) { throw TypeConversionException::parsingFailed($this, 'quoted string', $native, $pos); } $result[] = $this->_item->input(stripcslashes($m[1])); $pos += call_user_func(self::$strlen, $m[0]); } else { // zero-length string can appear only quoted if (0 === ($len = strcspn($native, ",} \t\r\n", $pos))) { throw TypeConversionException::parsingFailed($this, 'subarray, quoted or unquoted string', $native, $pos); } $v = call_user_func(self::$substr, $native, $pos, $len); $result[] = strcasecmp($v, "null") ? $this->_item->input(stripcslashes($v)) : null; $pos += $len; } } $pos++; // skip trailing "}" return $result; }
/** * Updates connection data for ConnectionAware converter * * @param TypeConverter $converter */ private function _updateConnection(TypeConverter $converter) { if ($this->_connection && $converter instanceof converters\ConnectionAware) { $converter->setConnectionResource($this->_connection->getResource()); } }