public function testInstanceUpdateDeleteURIs() { $x = new User(); $x->__set('id', 1234); $this->assertEquals('/users/:id', UrlGenerator::getInstanceUri($x)); $this->assertEquals('/users/1234', UrlGenerator::getInstanceUri($x, [':id' => 1234])); $this->assertEquals('/users/1234', UrlGenerator::getUpdateUri($x, [':id' => 1234])); $this->assertEquals('/users/1234', UrlGenerator::getDeleteUri($x, [':id' => 1234])); }
/** * Function to delete an existing entity * * @return Boolean Success of the delete operation */ public function destroy() { //get a request object $request = RequestFactory::build(); //init the request $request->createRequest(Config::get('request.base_uri'), UrlGenerator::getDeleteUri($this, [':' . $this->getIdentityProperty() => $this->getId()]), 'DELETE', [], Config::get('request.http_method_param')); //add auth if it is needed if ($auth = AuthFactory::build()) { $request->authenticate($auth); } //actually send the request $response = $request->sendRequest(); //clean up anything no longer needed $this->doPostRequestCleanUp(); $interpreter = ResponseInterpreterFactory::build(); //handle clean response with errors if ($interpreter->success($response)) { return true; } else { if ($interpreter->invalid($response)) { //get the errors and set them to our local collection $this->errors = ErrorHandlerFactory::build()->parseErrors($response); } } //end if-else return false; }