当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::withHeader方法代码示例

本文整理汇总了PHP中Slim\Http\Response::withHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::withHeader方法的具体用法?PHP Response::withHeader怎么用?PHP Response::withHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim\Http\Response的用法示例。


在下文中一共展示了Response::withHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school');
     $appForm = $this->appFormService->findSchoolApplicationForm($school->id);
     if (null === $appForm) {
         return $res->withStatus(404);
     }
     $html = $this->view->fetch('application_form/pdf.twig', ['school' => $school, 'appForm' => $appForm, 'logo' => base64_encode(file_get_contents(__DIR__ . '/../../public/img/application_form/minedu_logo.jpg')), 'style' => file_get_contents(__DIR__ . '/../../public/css/application_form/pdf.css')]);
     $pdf = new \Dompdf\Dompdf(['default_paper_size' => 'A4', 'default_font' => 'DejaVu Sans', 'isHtml5ParserEnabled' => true, 'is_remote_enabled' => false]);
     $pdf->loadHtml($html);
     $pdf->render();
     $filename = 'edulabs_app_form_' . $appForm['id'] . '.pdf';
     $str = $pdf->output();
     $length = mb_strlen($str, '8bit');
     return $res->withHeader('Cache-Control', 'private')->withHeader('Content-type', 'application/pdf')->withHeader('Content-Length', $length)->withHeader('Content-Disposition', 'attachment;  filename=' . $filename)->withHeader('Accept-Ranges', $length)->write($str);
 }
开发者ID:eellak,项目名称:gredu_labs,代码行数:16,代码来源:ApplicationFormPdf.php

示例2: buildResponse

 /**
  * Convert data to JSON and set as response, with caching header.
  *
  * @param $data mixed
  *
  * @return Response
  */
 public function buildResponse($data)
 {
     // Construct response based on provided data.
     $builtResponse = $this->response->withHeader('Content-Type', 'application/json')->write(json_encode($data, JSON_PRETTY_PRINT));
     // Return the response with an ETag added, for caching.
     return $this->c->cache->withEtag($builtResponse, sha1($builtResponse->getBody()));
 }
开发者ID:lchski,项目名称:api.lucascherkewski.com,代码行数:14,代码来源:BaseController.php

示例3: __invoke

 public function __invoke(Request $req, Response $res, callable $next)
 {
     // $path = $req->getUri()->getPath();
     // $path = "/".trim($path, "/");
     $user = self::getUser();
     if (empty($user)) {
         return $res->withHeader("Location", $_SERVER['HTTP_REFERER']);
     }
     if (!in_array($user["level"], $this->allow)) {
         return $res->withHeader("Location", $_SERVER['HTTP_REFERER']);
     }
     return $next($req, $res);
 }
开发者ID:nuiz,项目名称:gis,代码行数:13,代码来源:PermissionMiddleware.php

示例4: __invoke

 /**
  * __invoke is called by slim when a route matches
  * @param $request Request
  * @param $response Response
  * @param $args array
  * *
  * @return $response \Slim\Http\Response
  */
 public function __invoke(Request $request, Response $response, array $args)
 {
     $this->response = $response;
     //check for api key
     $queryParams = $request->getQueryParams();
     if (isset($queryParams['api_key'])) {
         $userData = UserModel::getUserWithApiKey($queryParams['api_key']);
         if ($userData !== false) {
             $this->currentUser = new User($userData);
         }
     }
     $this->response = $this->response->withHeader('Content-type', 'application/json');
 }
开发者ID:JohnUiterwyk,项目名称:journey-planner,代码行数:21,代码来源:ApiController.php

示例5: product_mediaRemove

 public function product_mediaRemove(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $media = $db->get("product_media", "*", ["id" => $attr["id"]]);
     if (!$media) {
         return $res->withHeader("Location", $req->getUri()->getBasePath() . "/product/" . $attr["product_id"] . "/media");
     }
     if ($media["type"] == "image") {
         @unlink("../product_media/" . $media["image_path"]);
     }
     $db->delete("product_media", ["id" => $attr["id"]]);
     return $res->withHeader("Location", $req->getUri()->getBasePath() . "/product/" . $attr["product_id"] . "/media");
 }
开发者ID:icezlizz1991,项目名称:tufftexgroup,代码行数:14,代码来源:ProductMediaController.php

示例6: learningcenterRemove

 public function learningcenterRemove(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $db->delete("learningcenter", ["id" => $attr["id"]]);
     return $res->withHeader("Location", $req->getUri()->getBasePath() . "/learningcenter");
 }
开发者ID:nuiz,项目名称:gis,代码行数:7,代码来源:LearningCenterController.php

示例7: productRemove

 public function productRemove(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $db->delete("product", ["id" => $attr["id"]]);
     $db->delete("person_cripple", ["cripple_id" => $attr["id"]]);
     return $res->withHeader("Location", $req->getUri()->getBasePath() . "/product");
 }
开发者ID:icezlizz1991,项目名称:tufftexgroup,代码行数:8,代码来源:ProductController.php

示例8: disavantaged_typeRemove

 public function disavantaged_typeRemove(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $db->delete("disavantaged_type", ["id" => $attr["id"]]);
     $db->delete("person_disavantaged", ["disavantaged_id" => $attr["id"]]);
     return $res->withHeader("Location", $req->getUri()->getBasePath() . "/disavantaged_type");
 }
开发者ID:nuiz,项目名称:gis,代码行数:8,代码来源:DisavantagedTypeController.php

示例9: anyLogout

 public function anyLogout(Request $req, Response $res)
 {
     $container = $this->slim->getContainer();
     /** @var Aura\Session\Session */
     $session = $container->session;
     $loginSegment = $session->getSegment("login");
     $loginSegment->clear();
     $session->commit();
     return $res->withHeader("Location", $req->getUri()->getBasePath() . "/login");
 }
开发者ID:nuiz,项目名称:gis,代码行数:10,代码来源:IndexController.php

示例10: logout

 /**
  * @param Response $response
  * @return Response
  */
 public function logout(Response $response)
 {
     if ($this->isAuthenticated()) {
         $this->_cookies->set("session_token", ["value" => "", "expires" => time() - 3600]);
         $this->getUser()->storeRememberToken(null);
         $this->_user = null;
         $this->_authenticated = false;
         return $response->withHeader('Set-Cookie', $this->_cookies->toHeaders());
     }
     return $response;
 }
开发者ID:dtkahl,项目名称:php-auth,代码行数:15,代码来源:Auth.php

示例11: __invoke

 public function __invoke(Request $req, Response $res, callable $next)
 {
     $path = $req->getUri()->getPath();
     $path = "/" . trim($path, "/");
     $allowNotAuth = ["/", "/login"];
     if (!in_array($path, $allowNotAuth)) {
         /** @var Aura\Session\Session */
         $session = $this->container["session"];
         $loginSegment = $session->getSegment("login");
         if (empty($loginSegment->get("user"))) {
             return $res->withHeader("Location", $req->getUri()->getBasePath() . "/login");
         }
     }
     return $next($req, $res);
 }
开发者ID:icezlizz1991,项目名称:tufftexgroup,代码行数:15,代码来源:AuthMiddleware.php

示例12: thumb

/**
 * @param string              $repo
 * @param string              $file
 * @param int                 $width
 * @param bool                $archived
 * @param \Slim\Http\Response $response
 * @return mixed
 */
function thumb($repo, $file, $width, $archived, $response, $format)
{
    $md5 = md5($file);
    $file = $md5[0] . '/' . $md5[0] . $md5[1] . '/' . $file;
    $path = $repo . ($archived ? 'archive/' : '') . $file;
    if (is_readable($path)) {
        $path = realpath($path);
        $pathParts = pathinfo($path);
        if (strpos($pathParts['dirname'], $repo) === 0) {
            $cacheDir = $repo . 'thumb/' . ($archived ? 'archive/' : '') . $file;
            if (!is_dir($cacheDir)) {
                if (!mkdir($cacheDir, 0777, true)) {
                    return $response->withStatus(403);
                }
            }
            if ($format != 'jpg') {
                $cacheFile = $cacheDir . '/' . $width . 'px-' . $pathParts['basename'];
            } else {
                $cacheFile = $cacheDir . '/' . $width . 'px-' . $pathParts['filename'] . '.jpg';
            }
            if (!is_readable($cacheFile)) {
                $image = new ImageResize($path);
                if ($width > $image->getSourceWidth()) {
                    return $response->withRedirect('/images/' . $file);
                } else {
                    $image->resizeToWidth($width);
                    if ($format != 'jpg') {
                        $image->save($cacheFile);
                    } else {
                        $image->save($cacheFile, IMAGETYPE_JPEG);
                    }
                }
            }
            $finfo = finfo_open(FILEINFO_MIME_TYPE);
            $type = finfo_file($finfo, $cacheFile);
            $stream = new \GuzzleHttp\Psr7\LazyOpenStream($cacheFile, 'r');
            return $response->withHeader('Content-type', $type)->withBody($stream);
        }
    }
    return $response->withStatus(404);
}
开发者ID:samogot,项目名称:rura-thumb,代码行数:49,代码来源:index.php

示例13: testETagWithCacheMiss

 public function testETagWithCacheMiss()
 {
     $etag = 'abc';
     $ifNoneMatch = 'xyz';
     $cache = new Cache('public', 86400);
     $req = $this->requestFactory()->withHeader('If-None-Match', $ifNoneMatch);
     $res = new Response();
     $next = function (Request $req, Response $res) use($etag) {
         return $res->withHeader('ETag', $etag);
     };
     $res = $cache($req, $res, $next);
     $this->assertEquals(200, $res->getStatusCode());
 }
开发者ID:aodkrisda,项目名称:slim-3-framework-app,代码行数:13,代码来源:CacheTest.php

示例14: redirect

 /**
  * Redirect to video file.
  *
  * @param Request  $request  PSR-7 request
  * @param Response $response PSR-7 response
  *
  * @return Response HTTP response
  */
 public function redirect(Request $request, Response $response)
 {
     $params = $request->getQueryParams();
     if (isset($params['url'])) {
         try {
             $url = $this->download->getURL($params['url'], $params['format']);
             return $response->withRedirect($url);
         } catch (\Exception $e) {
             $response->getBody()->write($e->getMessage());
             return $response->withHeader('Content-Type', 'text/plain');
         }
     }
 }
开发者ID:rudloff,项目名称:alltube,代码行数:21,代码来源:FrontController.php

示例15: stream

 /**
  * @param Request $request
  * @param Response $response
  * @param array $args
  * @return Response
  */
 public function stream(Request $request, Response $response, array $args)
 {
     $record = $this->getModel()->find($args['id']);
     return $response->withHeader('Last-Modified', $record->feed->lastModified)->withHeader('Content-Type', "application/xhtml+xml")->write($this->toXml($record, $args['format'])->saveXML());
 }
开发者ID:alexdebril,项目名称:feedio-demo,代码行数:11,代码来源:Feed.php


注:本文中的Slim\Http\Response::withHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。