| 1 | <?php  | 
            ||
| 8 | trait ResponseAwareTrait  | 
            ||
| 9 | { | 
            ||
| 10 | /**  | 
            ||
| 11 | * @var \Psr\Http\Message\ResponseInterface  | 
            ||
| 12 | */  | 
            ||
| 13 | protected $response;  | 
            ||
| 14 | |||
| 15 | /**  | 
            ||
| 16 | * Set a PSR-7 response implementation.  | 
            ||
| 17 | *  | 
            ||
| 18 | * @param \Psr\Http\Message\ResponseInterface $response  | 
            ||
| 19 | *  | 
            ||
| 20 | * @return $this  | 
            ||
| 21 | */  | 
            ||
| 22 | 27 | public function setResponse(ResponseInterface $response)  | 
            |
| 23 |     { | 
            ||
| 24 | 27 | $this->response = $response;  | 
            |
| 25 | |||
| 26 | 27 | return $this;  | 
            |
| 27 | }  | 
            ||
| 28 | |||
| 29 | /**  | 
            ||
| 30 | * Return the request object.  | 
            ||
| 31 | *  | 
            ||
| 32 | * @throws \RuntimeException if a response object cannot be determined  | 
            ||
| 33 | *  | 
            ||
| 34 | * @return \Psr\Http\Message\ResponseInterface  | 
            ||
| 35 | */  | 
            ||
| 36 | 27 | public function getResponse()  | 
            |
| 37 |     { | 
            ||
| 38 | 27 |         if (! is_null($this->response)) { | 
            |
| 39 | 24 | return $this->response;  | 
            |
| 40 | }  | 
            ||
| 41 | |||
| 42 | 3 |         if ($this->getContainer()->has('Psr\Http\Message\ResponseInterface')) { | 
            |
| 43 | 3 |             $this->response = $this->getContainer()->get('Psr\Http\Message\ResponseInterface'); | 
            |
| 44 | 3 | return $this->response;  | 
            |
| 45 | }  | 
            ||
| 46 | |||
| 47 |         throw new RuntimeException('Unable to determine a response object'); | 
            ||
| 48 | }  | 
            ||
| 49 | |||
| 50 | /**  | 
            ||
| 51 | * @return \Interop\Container\ContainerInterface  | 
            ||
| 52 | */  | 
            ||
| 53 | abstract public function getContainer();  | 
            ||
| 54 | }  | 
            ||
| 55 |