示例#1
0
 protected function outputNotNull($value)
 {
     if (is_array($value)) {
         $value = Point::createFromArray($value);
     } elseif (!$value instanceof Point) {
         throw TypeConversionException::unexpectedValue($this, 'output', 'instance of Point or an array', $value);
     }
     return '(' . $this->_float->output($value->x) . ',' . $this->_float->output($value->y) . ')';
 }
示例#2
0
 public static function createFromArray(array $input)
 {
     $points = array();
     foreach ($input as $point) {
         if (is_array($point)) {
             $point = Point::createFromArray($point);
         }
         $points[] = $point;
     }
     return new static($points);
 }
示例#3
0
 /**
  * Creates a Circle from a given array
  *
  * @param array $input
  * @return self
  * @throws InvalidArgumentException
  */
 public static function createFromArray(array $input)
 {
     if (2 != count($input)) {
         throw new InvalidArgumentException(sprintf("%s() expects an array with exactly two elements", __METHOD__));
     }
     if (array_key_exists('center', $input) && array_key_exists('radius', $input)) {
         $center = $input['center'];
         $radius = $input['radius'];
     } else {
         $center = array_shift($input);
         $radius = array_shift($input);
     }
     if (is_array($center)) {
         $center = Point::createFromArray($center);
     }
     return new self($center, $radius);
 }
示例#4
0
 /**
  * Creates an instance of PointPair from a given array
  *
  * @param array $input
  * @return self
  * @throws InvalidArgumentException
  */
 public static function createFromArray(array $input)
 {
     if (2 != count($input)) {
         throw new InvalidArgumentException(sprintf("%s() expects an array with exactly two elements", __METHOD__));
     }
     if (array_key_exists('start', $input) && array_key_exists('end', $input)) {
         $start = $input['start'];
         $end = $input['end'];
     } else {
         $start = array_shift($input);
         $end = array_shift($input);
     }
     if (is_array($start)) {
         $start = Point::createFromArray($start);
     }
     if (is_array($end)) {
         $end = Point::createFromArray($end);
     }
     return new static($start, $end);
 }