public function testDelete() { $pictureMapper = new PictureMapper(); $pictureMapper->setId(1); $pictureMapper->deletePicture(); $this->assertEquals(new Picture(), $pictureMapper->selectPicture()); }
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $picture_ = new Picture(); $pictureMapper = new \PictureMapper(); $pictureObject = $pictureMapper->selectPicture(); $pictureArray = extractData($pictureObject); if (!empty($pictureArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($pictureArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "picture", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($pictureArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $picture_ = new Picture(); $pictureMapper = new \PictureMapper(); if ($pictureMapper->deletePicture()) { Rest::sendResponse(200);
public function getPictures(PictureMapper $pictureMapper_) { $picturesObjects = $pictureMapper_->selectPicture(true); return $picturesObjects; }
<?php $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $pictureMapper = new \PictureMapper(); $picturesObject = $pictureMapper->selectPicture(true); $result = true; if (is_array($picturesObject) && !is_null($picturesObject)) { foreach ($picturesObject as $pictureObject) { $result = emptyObject($pictureObject); } } if (!$result) { foreach ($picturesObject as $pictureObject) { $picturesArray[] = extractData($pictureObject); } if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($picturesArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "picture"); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($picturesArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'post':