PHP Classes

File: src/Response.php

Recommend this page to a friend!
  Classes of Till Wehowski   PHP Proxy Server Script   src/Response.php   Download  
File: src/Response.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Proxy Server Script
Forward HTTP requests to other servers as a proxy
Author: By
Last change:
Date: 3 years ago
Size: 986 bytes
 

Contents

Class file image Download
<?php
namespace frdl\Proxy;


class
Response
{
    protected
$_response;
    public function
__construct(\Psr\Http\Message\ResponseInterface $response){
       
$this->_response = $response;
    }
    public function
__call($name, $params){
        if(!
is_callable([$this->_response, $name])){
           throw new \
Exception(get_class($this->_response ).'->'.$name.' is not callable in '.__METHOD__);
        }
       
       
$r = call_user_func_array([$this->_response, $name], $params);
        if(
$r instanceof $this){
           return
$r;
        }elseif(
is_object($r) && in_array(\Psr\Http\Message\ResponseInterface::class, class_implements($r))){
           return new
self($r);
        }else{
           return
$r;
        }
    }
   
    public function
send($verbose = true){
       

       
        if(
is_callable([$this->_response, 'send'])){
           return
$this->_response->send($verbose);
        }
       
         if(
true !== $verbose){
            return
$this->_response->getBody();
         }

         return (new \
Laminas\HttpHandlerRunner\Emitter\SapiEmitter)->emit($this->_response);
    }
}