Overview

Namespaces

  • PipelinerSales
    • ApiClient
      • Http
      • Query
      • Repository
        • Rest

Classes

  • RestCreatedResponse
  • RestInfoMethods
  • RestRepository
  • RestRepositoryFactory
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * This file is part of the Pipeliner API client library for PHP
 4:  *
 5:  * Copyright 2014 Pipelinersales, Inc. All Rights Reserved.
 6:  * For the full license information, see the attached LICENSE file.
 7:  */
 8: 
 9: namespace PipelinerSales\ApiClient\Repository\Rest;
10: 
11: use PipelinerSales\ApiClient\Http\Response;
12: use PipelinerSales\ApiClient\Http\CreatedResponse;
13: 
14: class RestCreatedResponse extends CreatedResponse
15: {
16:     public function __construct(Response $r)
17:     {
18:         parent::__construct(
19:             $r->getBody(),
20:             $r->getHeaders(),
21:             $r->getStatusCode(),
22:             $r->getRequestUrl(),
23:             $r->getRequestMethod()
24:         );
25:     }
26:     
27:     public function getCreatedId()
28:     {
29:         //Response to a POST request creating a new entity has a Location header
30:         //which contains the URL of that entity. Its ID is after the last slash
31:         //in that URL.
32:         $headers = $this->getHeaders();
33:         $locationPos = strpos($headers, "\r\nLocation:");
34:         $lineEndPos = strpos($headers, "\r\n", $locationPos + 1);
35:         $locationLine = substr($headers, $locationPos, $lineEndPos - $locationPos);
36:         $finalSlashPos = strrpos($locationLine, '/');
37:         return substr($locationLine, $finalSlashPos + 1);
38:     }
39: }
40: 
API documentation generated by ApiGen