Overview

Namespaces

  • Racoon
    • Api
      • Auth
      • Exception
      • Response
        • Format
        • Generate
      • Schema

Classes

  • Racoon\Api\App
  • Racoon\Api\Auth\ApiKeyAuthenticator
  • Racoon\Api\Auth\NoAuthenticator
  • Racoon\Api\Controller
  • Racoon\Api\Request
  • Racoon\Api\Response\Format\JsonFormatter
  • Racoon\Api\Response\Generate\DetailedResponse
  • Racoon\Api\Schema\Item
  • Racoon\Api\Schema\Schema
  • Racoon\Api\Schema\Translator

Interfaces

  • Racoon\Api\Auth\AuthInterface
  • Racoon\Api\Response\Format\FormatterInterface
  • Racoon\Api\Response\Generate\GeneratorInterface

Exceptions

  • Racoon\Api\Exception\AuthenticationException
  • Racoon\Api\Exception\Exception
  • Racoon\Api\Exception\InvalidArgumentException
  • Racoon\Api\Exception\InvalidJsonException
  • Racoon\Api\Exception\InvalidRouteException
  • Racoon\Api\Exception\NotFoundException
  • Racoon\Api\Exception\ResponseFormattingException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: 
  4: namespace Racoon\Api\Response\Generate;
  5: 
  6: 
  7: use Racoon\Api\Request;
  8: 
  9: class DetailedResponse implements GeneratorInterface
 10: {
 11: 
 12:     /**
 13:      * @var Request
 14:      */
 15:     protected $request;
 16: 
 17:     /**
 18:      * @var int
 19:      */
 20:     protected $httpResponseCode;
 21: 
 22:     /**
 23:      * @var bool
 24:      */
 25:     protected $showSchema;
 26: 
 27:     /**
 28:      * @var bool
 29:      */
 30:     protected $showTimeElapsed;
 31: 
 32:     /**
 33:      * @var bool
 34:      */
 35:     protected $showReceived;
 36: 
 37:     public function __construct()
 38:     {
 39:         $this->setShowSchema(true);
 40:         $this->setShowTimeElapsed(true);
 41:         $this->setShowReceived(true);
 42:     }
 43: 
 44: 
 45:     /**
 46:      * @param Request $request
 47:      * @return mixed
 48:      */
 49:     public function setRequest(Request $request)
 50:     {
 51:         $this->request = $request;
 52:     }
 53: 
 54: 
 55:     /**
 56:      * @return Request
 57:      */
 58:     public function getRequest()
 59:     {
 60:         return $this->request;
 61:     }
 62: 
 63:     /**
 64:      * @return mixed
 65:      */
 66:     public function generate()
 67:     {
 68:         $this->httpResponseCode = 200;
 69:         
 70:         $displayException = $this->getRequest()->getDisplayException();
 71:         
 72:         $response = new \stdClass();
 73:         $response->success = (! is_object($displayException));
 74:         $response->message = $this->getRequest()->getResponseMessage();
 75:         if (is_object($displayException)) {
 76:             $response->message = $displayException->getMessage();
 77:             $this->httpResponseCode = $displayException->getCode();
 78:             if ($this->httpResponseCode == 0) {
 79:                 $this->httpResponseCode = 500;
 80:             }
 81:         }
 82:         if ($this->shouldShowSchema()) {
 83:             if (is_object($this->getRequest()->getSchema())) {
 84:                 $response->schema = $this->getRequest()->getSchema()->getDefinition();
 85:             } else {
 86:                 $response->schema = null;
 87:             }
 88:         }
 89:         if ($this->shouldShowReceived()) {
 90:             $response->received = $this->request->getFullRequestData();
 91:         }
 92:         if ($this->shouldShowTimeElapsed()) {
 93:             $response->time_elapsed = number_format($this->request->getElapsedTime(true), 3);
 94:         }
 95:         $response->response = $this->getRequest()->getControllerResponse();
 96: 
 97:         return $response;
 98:     }
 99: 
100: 
101:     /**
102:      * @return int
103:      */
104:     public function getHttpResponseCode()
105:     {
106:         return $this->httpResponseCode;
107:     }
108: 
109: 
110:     /**
111:      * @return boolean
112:      */
113:     public function shouldShowSchema()
114:     {
115:         return $this->showSchema;
116:     }
117: 
118: 
119:     /**
120:      * @param boolean $showSchema
121:      */
122:     public function setShowSchema($showSchema)
123:     {
124:         $this->showSchema = $showSchema;
125:     }
126: 
127: 
128:     /**
129:      * @return boolean
130:      */
131:     public function shouldShowTimeElapsed()
132:     {
133:         return $this->showTimeElapsed;
134:     }
135: 
136: 
137:     /**
138:      * @param boolean $showTimeElapsed
139:      */
140:     public function setShowTimeElapsed($showTimeElapsed)
141:     {
142:         $this->showTimeElapsed = $showTimeElapsed;
143:     }
144: 
145: 
146:     /**
147:      * @return boolean
148:      */
149:     public function shouldShowReceived()
150:     {
151:         return $this->showReceived;
152:     }
153: 
154: 
155:     /**
156:      * @param boolean $showReceived
157:      */
158:     public function setShowReceived($showReceived)
159:     {
160:         $this->showReceived = $showReceived;
161:     }
162: }
API documentation generated by ApiGen