Beispiel #1
0
 if (($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) {
     throw new InvalidArgumentException("id cannot be empty or negative", 405);
 }
 //sanitize and trim the rest of the inputs
 $elevationX = filter_input(INPUT_GET, "segmentStartElevation", FILTER_VALIDATE_INT);
 $elevationY = filter_input(INPUT_GET, "segmentStopElevation", FILTER_VALIDATE_INT);
 //handle all restful calls
 // get some or all segments
 if ($method === "GET") {
     // not sure if i need to set XSRF COOKIE
     // TL; DR: yes
     setXsrfCookie("/");
     if (empty($id) === false) {
         $reply->data = Segment::getSegmentBySegmentId($pdo, $id);
     } elseif (empty($segmentStart) === false) {
         $reply->data = Segment::getSegmentBySegmentStart($pdo, $segmentStart)->toArray();
     } elseif (empty($segmentStop) === false) {
         $reply->data = Segment::getSegmentBySegmentStop($pdo, $segmentStop)->toArray();
     } elseif (empty($elevationX) === false) {
         $reply->data = Segment::getSegmentBySegmentStartElevation($pdo, $elevationX)->toArray();
     } elseif (empty($elevationY) === false) {
         $reply->data = Segment::getSegmentBySegmentStopElevation($pdo, $elevationY)->toArray();
     }
 }
 //if the section belongs to a new an active user allow post, put and delete m
 if (empty($_SESSION["user"]) === false && $_SESSION["user"]->getUserAccountType() !== "X") {
     if ($method === "PUT" || $method === "POST") {
         verifyXsrf();
         $requestContent = file_get_contents("php://input");
         $requestObject = json_decode($requestContent);
         //formatted segments so that the api and class can communicate together
Beispiel #2
0
 /**
  * test grabbing a segment by segmentStart that does not exist
  *
  * @expectedException RangeException
  **/
 public function testGetInvalidSegmentBySegmentStart()
 {
     //grab a segmentStart that does not exist
     $pdoSegments = Segment::getSegmentBySegmentStart($this->getPDO(), new Point(190.222, -190.222));
     foreach ($pdoSegments as $pdoSegment) {
         $this->assertNull($pdoSegment);
     }
 }