Exemplo n.º 1
0
 protected function execute($value, EntityInterface $entity = null)
 {
     $null_value = $this->getOption(AttributeInterface::OPTION_NULL_VALUE, null);
     if ($value === $null_value || $value === '') {
         // accept NULL or empty string as valid NULL value when NULL value is NULL :D
         $this->setSanitizedValue($null_value);
         return true;
     }
     try {
         if (is_array($value)) {
             $geopoint = GeoPoint::createFromArray($value);
         } elseif ($value instanceof GeoPoint) {
             $geopoint = GeoPoint::createFromArray($value->toNative());
         } else {
             $this->throwError('invalid_type', ['value' => $value, 'type' => gettype($value)], IncidentInterface::CRITICAL);
             return false;
         }
         $treat_null_island_as_null = $this->getOption(self::OPTION_NULL_ISLAND_AS_NULL, true);
         if ($treat_null_island_as_null === true && $geopoint->isNullIsland()) {
             // use (0,0) as NULL as that's a geocoding failure or not wanted or wanted as NULL trigger
             $this->setSanitizedValue($null_value);
             return true;
         }
         // set the sanitized new geopoint data
         $this->setSanitizedValue($geopoint);
     } catch (BadValueException $e) {
         $this->throwError('invalid_data', ['error' => $e->getMessage()], IncidentInterface::CRITICAL);
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 public function testToArrayValuesEqualToNative()
 {
     $gp = new GeoPoint([GeoPoint::PROPERTY_LONGITUDE => 12.34, GeoPoint::PROPERTY_LATITUDE => 53.21]);
     $a = $gp->toArray();
     $b = $gp->toNative();
     $this->assertEquals($a, $b);
 }
Exemplo n.º 3
0
 public function testNullIslandIsAcceptedWhenConfiguredToDoSo()
 {
     $attribute = new GeoPointAttribute('gp', $this->getTypeMock(), [GeoPointAttribute::OPTION_NULL_ISLAND_AS_NULL => false]);
     $null_island = GeoPoint::createNullIsland();
     $valueholder = $attribute->createValueHolder();
     $valueholder->setValue($null_island);
     $this->assertNotSame($attribute->getNullValue(), $valueholder->getValue());
     $this->assertNotSame('', $valueholder->toNative());
     $this->assertTrue($valueholder->getValue()->isNullIsland());
 }