Exemplo n.º 1
0
 /** @codeCoverageIgnore */
 public static function create()
 {
     $injector = new Injector();
     $injector->bind(Injector::class, $injector);
     $request = HttpRequest::create();
     $response = new HttpResponse();
     $router = new Router();
     return new static($injector, $router, $request, $response);
 }
Exemplo n.º 2
0
 public function __invoke(HttpRequest $request, HttpResponse $response)
 {
     $path = $this->path . substr($request->getUrl(), 1);
     $fn = $this->filter;
     if ($fn($path)) {
         $response->setContentEncoding(HttpResponse::GZIP);
         if (is_dir($path) && $this->hasIndex) {
             // serve the index of the specified path
             $fn = $this->index;
             $response->setContentType('text/html');
             $response->setBody($fn($path));
         } else {
             if (is_file($path)) {
                 $response->setContentType($this->finfo->file($path, FILEINFO_MIME_TYPE));
                 $response->setBody(fopen($path, 'r'));
             }
         }
     }
 }
Exemplo n.º 3
0
 public function __invoke(HttpRequest $request, HttpResponse $response)
 {
     $origin = $request->getHeader('Origin');
     if (!empty($origin)) {
         if (in_array($origin, $this->domains)) {
             $response->setHeader('Access-Control-Allow-Origin', $origin);
             if (!!$this->credentials) {
                 $response->setHeader('Access-Control-Allow-Credentials', !!$this->credentials ? 'true' : 'false');
             }
             if (!empty($this->methods)) {
                 $response->setHeader('Access-Control-Allow-Methods', implode(', ', $this->methods));
             }
             if (!empty($this->allowHeaders)) {
                 $response->setHeader('Access-Control-Allow-Headers', implode(', ', $this->allowHeaders));
             }
             if (!empty($this->exposeHeaders)) {
                 $response->setHeader('Access-Control-Expose-Headers', implode(', ', $this->exposeHeaders));
             }
             if (!empty($this->ttl)) {
                 $response->setHeader('Access-Control-Max-Age', $this->ttl);
             }
         }
     }
 }