public function actionCreate() { if (!Parameters::hasParam('type')) { throw new APIException('Invalid resource TYPE (parameter name: \'type\')', APIResponseCode::API_INVALID_METHOD_PARAMS); } $type = Parameters::get('type'); $storage = DataStorageFactory::createStorage($type); if (is_null($storage)) { throw new APIException('Could not create data storage', APIResponseCode::API_INVALID_METHOD_PARAMS); } try { $obj = DataModelFactory::createDataObjectWithType($type); $data = Parameters::getRaw('data', 'post'); $attr = $storage->decodeResponse($data); $obj->setAttributes($attr); $storage->save($obj); } catch (Exception $e) { throw new APIException('Can not save resource object', APIResponseCode::API_SHEMA_CREATE_ERROR); } }