/** * {@inheritdoc} */ public function convertBinaryToPHPValue($sqlExpr) { if (!is_resource($sqlExpr)) { throw InvalidValueException::invalidType('resource', $sqlExpr); } $sqlExpr = stream_get_contents($sqlExpr); return parent::convertBinaryToPHPValue($sqlExpr); }
/** * Create spatial object from parsed value * * @param array $value * * @return GeometryInterface * @throws \CrEOF\Spatial\Exception\InvalidValueException */ private function newObjectFromValue($value) { $constName = 'CrEOF\\Spatial\\PHP\\Types\\Geometry\\GeometryInterface::' . strtoupper($value['type']); if (!defined($constName)) { throw InvalidValueException::unsupportedType($this->getTypeFamily(), strtoupper($value['type'])); } $class = sprintf('CrEOF\\Spatial\\PHP\\Types\\%s\\%s', $this->getTypeFamily(), constant($constName)); return new $class($value['value'], $value['srid']); }
/** * {@inheritdoc} */ public function setY($y) { $y = $this->toFloat($y); if ($y < -90 || $y > 90) { throw InvalidValueException::invalidLatitude($y); } $this->y = $y; return $this; }
/** * {@inheritdoc} */ public function convertToDatabaseValue(AbstractGeometry $value) { if (!$value instanceof GeographyInterface) { throw InvalidValueException::invalidValueNotGeography(); } if ($value->getSrid() === null) { $value->setSrid(self::DEFAULT_SRID); } return sprintf('SRID=%d;%s(%s)', $value->getSrid(), strtoupper($value->getType()), $value); }
/** * {@inheritdoc} */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { if ($value === null) { return $value; } if (!$value instanceof GeometryInterface) { throw InvalidValueException::invalidValueNoGeometryInterface(); } return $this->getSpatialPlatform($platform)->convertToDatabaseValue($value); }
/** * @param mixed $y * * @return self * @throws InvalidValueException */ public function setY($y) { $parser = new Parser($y); try { $y = (double) $parser->parse(); } catch (RangeException $e) { throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); } catch (UnexpectedValueException $e) { throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious()); } if ($y < -90 || $y > 90) { throw InvalidValueException::invalidLatitude($y); } $this->y = $y; return $this; }
/** * @param string $expected * @param array $token * * @throws InvalidValueException */ protected function syntaxError($expected = '', $token = null) { if ($token === null) { $token = $this->lexer->lookahead; } $tokenPos = isset($token['position']) ? $token['position'] : '-1'; $message = 'line 0, col ' . $tokenPos . ': Error: '; $message .= $expected !== '' ? 'Expected ' . $expected . ', got ' : 'Unexpected '; $message .= $this->lexer->lookahead === null ? 'end of string.' : '"' . $token['value'] . '"'; throw InvalidValueException::syntaxError($message, $this->input); }
/** * @param array $argv * * @return array * @throws InvalidValueException */ protected function validateArguments(array $argv = null) { $argc = count($argv); if (1 == $argc && is_array($argv[0])) { return $argv[0]; } if (2 == $argc) { if (is_array($argv[0]) && (is_numeric($argv[1]) || is_null($argv[1]) || is_string($argv[1]))) { $argv[0][] = $argv[1]; return $argv[0]; } if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1]))) { return $argv; } } if (3 == $argc) { if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1])) && (is_numeric($argv[2]) || is_null($argv[2]) || is_string($argv[2]))) { return $argv; } } throw InvalidValueException::invalidParameters(get_class($this), '__construct', $argv); }
/** * @param AbstractLineString|array[] $ring * * @return array[] * @throws InvalidValueException */ protected function validateRingValue($ring) { switch (true) { case $ring instanceof AbstractLineString: $ring = $ring->toArray(); break; case is_array($ring): break; default: throw InvalidValueException::invalidType($this, GeometryInterface::LINESTRING, $ring); } $ring = $this->validateLineStringValue($ring); if ($ring[0] !== end($ring)) { throw InvalidValueException::ringNotClosed($this->toStringLineString($ring)); } return $ring; }
/** * @throws InvalidValueException */ private function srid() { $srid = $this->reader->long(); if ($srid < 0) { throw InvalidValueException::invalidSrid($srid); } $this->srid = $srid; }
private function checkByteOrder() { if (!isset($this->byteOrder)) { throw InvalidValueException::invalidByteOrder('unset'); } }