Exemple #1
0
 /**
  * The constructor 
  * @param string $filename The filename to output
  * @throws \InvalidArgumentException
  */
 public function __construct($filename)
 {
     if (!is_string($filename)) {
         throw new \InvalidArgumentException('The filename argument must be of type string');
     }
     $this->filename = $filename;
     parent::__construct('');
 }
Exemple #2
0
 /**
  * The constructor
  * 
  * @param string $content The content of the response
  * @throws \InvalidArgumentException
  */
 public function __construct($content = '')
 {
     if (!is_string($content)) {
         throw new \InvalidArgumentException('The content argument must be of type string');
     }
     parent::__construct($content);
     $this->setContentType('text/html');
 }
Exemple #3
0
 /**
  * The constructor
  * 
  * @param string $content The content of the response
  * @throws \InvalidArgumentException
  */
 public function __construct($content = '')
 {
     if (!is_string($content)) {
         throw new \InvalidArgumentException('The content argument must be of type string');
     }
     parent::__construct($content);
     $this->charset = 'UTF-8';
     $this->headers->set('Content-Type', 'text/html');
 }
 /**
  * The constructor
  * 
  * @param string $content The content of the response
  * @throws \InvalidArgumentException
  */
 public function __construct($content = 'Temporary Unavailable')
 {
     if (!is_string($content)) {
         throw new \InvalidArgumentException('The content argument must be of type string');
     }
     parent::__construct($content);
     $this->setContentType('text/plain');
     $this->setStatusCode(503);
 }
 /**
  * The constructor
  * 
  * @param string $content The content of the response
  * @throws \InvalidArgumentException
  */
 public function __construct($content = 'Not Found')
 {
     if (!is_string($content)) {
         throw new \InvalidArgumentException('The content argument must be of type string');
     }
     parent::__construct($content);
     $this->setContentType('text/plain');
     $this->setStatusCode(404);
 }
 /**
  * The constructor
  * @param string $url The redirect url
  * @throws \InvalidArgumentException
  */
 public function __construct($url)
 {
     if (!is_string($url)) {
         throw new \InvalidArgumentException('The url argument must be of type string');
     }
     parent::__construct('');
     $this->setContentType('text/plain');
     $this->setStatusCode(301);
     $this->headers['location'] = 'Location: ' . $url;
 }
 /**
  * The constructor
  * 
  * @param string $content The content of the response
  * @throws \InvalidArgumentException
  */
 public function __construct($content = 'Temporary Unavailable')
 {
     if (!is_string($content)) {
         throw new \InvalidArgumentException('The content argument must be of type string');
     }
     parent::__construct($content);
     $this->statusCode = 503;
     $this->charset = 'UTF-8';
     $this->headers->set('Content-Type', 'text/plain');
 }
 /**
  * The constructor
  * 
  * @param string $url The redirect url
  * @throws \InvalidArgumentException
  */
 public function __construct($url)
 {
     if (!is_string($url)) {
         throw new \InvalidArgumentException('The url argument must be of type string');
     }
     parent::__construct('');
     $this->statusCode = 307;
     $this->headers->set('Content-Type', 'text/plain');
     $this->headers->set('Location', $url);
 }
 /**
  * The constructor 
  * 
  * @param string $filename The filename to output
  * @throws \InvalidArgumentException
  */
 public function __construct($filename)
 {
     if (!is_string($filename)) {
         throw new \InvalidArgumentException('The filename argument must be of type string');
     }
     $filename = realpath($filename);
     if ($filename === false) {
         throw new \InvalidArgumentException('The filename specified does not exist');
     }
     $this->filename = $filename;
     parent::__construct('');
 }
 /**
  * The constructor 
  * 
  * @param string $filename The filename to output
  * @throws \InvalidArgumentException
  */
 public function __construct($filename)
 {
     parent::__construct('');
     $this->defineProperty('filename', ['init' => function () {
         return '';
     }, 'set' => function ($value) {
         if (!is_string($value)) {
             throw new \InvalidArgumentException('The filename argument must be of type string');
         }
         $value = realpath($value);
         if ($value === false || !is_readable($value)) {
             throw new \InvalidArgumentException('The filename specified does not exist or is not readable');
         }
         return $value;
     }, 'unset' => function () {
         return '';
     }]);
     $this->filename = $filename;
 }
Exemple #11
0
 /**
  * Sends the response to the client
  * 
  * @param \BearFramework\App\Response $response The response object to be sent
  * @return void No value is returned
  */
 private function sendResponse($response)
 {
     if (!headers_sent()) {
         $statusCodes = [];
         $statusCodes[200] = 'OK';
         $statusCodes[201] = 'Created';
         $statusCodes[202] = 'Accepted';
         $statusCodes[203] = 'Non-Authoritative Information';
         $statusCodes[204] = 'No Content';
         $statusCodes[205] = 'Reset Content';
         $statusCodes[206] = 'Partial Content';
         $statusCodes[300] = 'Multiple Choices';
         $statusCodes[301] = 'Moved Permanently';
         $statusCodes[302] = 'Found';
         $statusCodes[303] = 'See Other';
         $statusCodes[304] = 'Not Modified';
         $statusCodes[305] = 'Use Proxy';
         $statusCodes[307] = 'Temporary Redirect';
         $statusCodes[400] = 'Bad Request';
         $statusCodes[401] = 'Unauthorized';
         $statusCodes[402] = 'Payment Required';
         $statusCodes[403] = 'Forbidden';
         $statusCodes[404] = 'Not Found';
         $statusCodes[405] = 'Method Not Allowed';
         $statusCodes[406] = 'Not Acceptable';
         $statusCodes[407] = 'Proxy Authentication Required';
         $statusCodes[408] = 'Request Timeout';
         $statusCodes[409] = 'Conflict';
         $statusCodes[410] = 'Gone';
         $statusCodes[411] = 'Length Required';
         $statusCodes[412] = 'Precondition Failed';
         $statusCodes[413] = 'Request Entity Too Large';
         $statusCodes[414] = 'Request-URI Too Long';
         $statusCodes[415] = 'Unsupported Media Type';
         $statusCodes[416] = 'Requested Range Not Satisfiable';
         $statusCodes[417] = 'Expectation Failed';
         $statusCodes[500] = 'Internal Server Error';
         $statusCodes[501] = 'Not Implemented';
         $statusCodes[502] = 'Bad Gateway';
         $statusCodes[503] = 'Service Unavailable';
         $statusCodes[504] = 'Gateway Timeout';
         $statusCodes[505] = 'HTTP Version Not Supported';
         if (isset($statusCodes[$response->statusCode])) {
             header((isset($_SERVER, $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1') . ' ' . $response->statusCode . ' ' . $statusCodes[$response->statusCode]);
         }
         if ($response->isPropertyUsed('headers')) {
             // performance optimization
             if (count($response->headers) > 0) {
                 $headers = $response->headers->getList();
                 foreach ($headers as $header) {
                     if ($header['name'] === 'Content-Type') {
                         $header['value'] .= '; charset=' . $response->charset;
                     }
                     header($header['name'] . ': ' . $header['value']);
                 }
             }
         }
         if ($response->isPropertyUsed('cookies')) {
             // performance optimization
             if (count($response->cookies) > 0) {
                 $baseUrlParts = parse_url($this->request->base);
                 $cookies = $response->cookies->getList();
                 foreach ($cookies as $cookie) {
                     setcookie($cookie['name'], $cookie['value'], $cookie['expire'], $cookie['path'] === null ? isset($baseUrlParts['path']) ? $baseUrlParts['path'] . '/' : '' : $cookie['path'], $cookie['domain'] === null ? isset($baseUrlParts['host']) ? $baseUrlParts['host'] : '' : $cookie['domain'], $cookie['secure'] === null ? $this->request->scheme === 'https' : $cookie['secure'], $cookie['httpOnly']);
                 }
             }
         }
     }
     if ($response instanceof App\Response\FileReader) {
         readfile($response->filename);
     } else {
         echo $response->content;
     }
     if ($this->isPropertyUsed('hooks')) {
         // performance optimization
         $this->hooks->execute('responseSent', $response);
     }
 }
    static function handleRobots()
    {
        $response = new App\Response('User-agent: *
Disallow:');
        $response->setContentType('text/plain');
        return $response;
    }