/** * @inheritdoc */ public function httpAction($action) { $configuration = $this->getConfiguration(); $request = json_decode($this->container->get('request')->getContent(), true); $schemas = $configuration["schemes"]; $debugMode = $configuration['debug'] || $this->container->get('kernel')->getEnvironment() == "dev"; if (!isset($request["schema"])) { throw new Exception('For initialization there is no name of the declared scheme'); } $schema = $schemas[$request["schema"]]; if (is_array($schema['featureType'])) { $featureType = new FeatureType($this->container, $schema['featureType']); } else { throw new Exception("FeatureType settings not correct"); } $results = array(); switch ($action) { case 'select': $defaultCriteria = array('returnType' => 'FeatureCollection', 'maxResults' => 2); $results = $featureType->search(array_merge($defaultCriteria, $request)); break; case 'save': // save once if (isset($request['feature'])) { $request['features'] = array($request['feature']); } try { // save collection if (isset($request['features']) && is_array($request['features'])) { foreach ($request['features'] as $feature) { $feature = $this->prepareQueredFeatureData($feature, $schema['formItems']); $results[] = $featureType->save($feature); } } $results = $featureType->toFeatureCollection($results); } catch (DBALException $e) { $message = $debugMode ? $e->getMessage() : "Feature can't be saved. Maybe something is wrong configured or your database isn't available?\n" . "For more information have a look at the webserver log file. \n Error code: " . $e->getCode(); $results = array('errors' => array(array('message' => $message, 'code' => $e->getCode()))); } break; case 'delete': // remove once $results = $featureType->remove($request['feature'])->getId(); break; } return new JsonResponse($results); }
public function testUpdate() { $originFeature = $this->getRandomFeature(); self::$featureType->save($originFeature); }