コード例 #1
0
 /**
  * @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));
     }
 }
コード例 #2
0
 /**
  * Calculates the number of array dimensions and required sizes for sub-arrays
  *
  * @param array $value
  * @return array
  * @throws TypeConversionException
  */
 private function _calculateRequiredSizes(array $value)
 {
     $sizes = array();
     while (is_array($value)) {
         $sizes[] = count($value);
         if (!count($value) || array_keys($value) !== range(0, count($value) - 1)) {
             if (0 === $this->_item->dimensions()) {
                 // scalar base type? "weird" sub-array is not allowed
                 throw TypeConversionException::unexpectedValue($this, 'output', 'non-empty array with 0-based numeric indexes', $value);
             }
             // assume that we reached an array representing base type
             array_pop($sizes);
             return $sizes;
         }
         if (null === ($value = $value[0])) {
             // null sub-arrays are not allowed, so that should be a base-type null
             return $sizes;
         }
     }
     if ($this->_item->dimensions() > 0) {
         // check whether we have an object representing base type
         if (is_object($value)) {
             try {
                 $this->_item->output($value);
                 return $sizes;
             } catch (PackageException $e) {
             }
         }
         array_splice($sizes, -$this->_item->dimensions());
     }
     return $sizes;
 }
コード例 #3
0
 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 ? ']' : ')');
 }