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


PHP Response::withStatus方法代码示例

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


在下文中一共展示了Response::withStatus方法的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: __invoke

 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $teacherId = $req->getParam('teacher_id');
     $teacher = $this->staffService->getTeacherById($teacherId);
     if ($teacher['school_id'] !== $school->id) {
         return $res->withStatus(403, 'No school');
     }
     if ($req->isPost()) {
         $inputFilter = $this->inputFilter;
         $result = $inputFilter($req->getParams());
         if (!$result['is_valid']) {
             $res = $res->withStatus(422);
             $res = $res->withJson($result);
             return $res;
         }
         $this->service->saveAnswers($teacherId, $result['values']);
     }
     $data = $this->service->getAnswers($teacherId);
     $res = $res->withJson($data);
     return $res;
 }
开发者ID:eellak,项目名称:gredu_labs,代码行数:25,代码来源:SurveyForm.php

示例3: writeUnauthorized

 public function writeUnauthorized()
 {
     $this->response = $this->response->withStatus(401);
     $apiResponse = new ApiResponse();
     $apiResponse->setStatusFail();
     $apiResponse->setData("Unauthorized");
     $this->body->write($apiResponse->toJSON());
 }
开发者ID:JohnUiterwyk,项目名称:journey-planner,代码行数:8,代码来源:ApiController.php

示例4: __invoke

 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $this->service->setTotalTeachers($school->id, (int) $req->getParam('total_teachers', 0));
     return $res->withStatus(204);
 }
开发者ID:eellak,项目名称:gredu_labs,代码行数:9,代码来源:SubmitTeachersCount.php

示例5: __invoke

 public function __invoke(Request $request, Response $response, $next)
 {
     $this->request = $request;
     $this->response = $response;
     $dsn = sprintf(self::PDO_DSN, $this->type, $this->name, $this->server);
     try {
         $this->connection = new PDO($dsn, $this->username, $this->password);
     } catch (PDOException $e) {
         $this->response->withStatus(500, $e->getMessage());
     }
     $next($request, $response);
     return $response;
 }
开发者ID:GreatOwl,项目名称:OAuth,代码行数:13,代码来源:Connect.php

示例6: dispatch

 public function dispatch(Request $request, Response $response, $args)
 {
     if ($request->isPost()) {
         $speaker = new Speaker(null, $request->getParam('first_name'), $request->getParam('last_name'), new Email($request->getParam('email')), new Twitter($request->getParam('twitter')));
         $msg = [];
         try {
             $this->speakersRepository->save($speaker);
             $msg['id'] = $speaker->id;
         } catch (\Exception $e) {
             return $response->withStatus(200)->withHeader('Content-Type', 'application/json')->write(json_encode(['error' => $e->getMessage()]));
         }
         return $response->withStatus(201)->withHeader('Content-Type', 'application/json')->write(json_encode($msg));
     }
 }
开发者ID:Allan-Mapletoft,项目名称:website,代码行数:14,代码来源:CreateSpeakerAction.php

示例7: __invoke

 /**
  * Execute the middleware.
  *
  * @param  \Slim\Http\Request  $req
  * @param  \Slim\Http\Response $res
  * @param  callable            $next
  * @return \Slim\Http\Response
  */
 public function __invoke(Request $req, Response $res, callable $next)
 {
     $uri = $req->getUri();
     $path = $this->filterTrailingSlash($uri);
     if ($uri->getPath() !== $path) {
         return $res->withStatus(301)->withHeader('Location', $path)->withBody($req->getBody());
     }
     //        if ($this->filterBaseurl($uri)) {
     //            return $res->withStatus(301)
     //                ->withHeader('Location', (string) $uri)
     //                ->withBody($req->getBody());
     //        }
     $server = $req->getServerParams();
     if (!isset($server['REQUEST_TIME_FLOAT'])) {
         $server['REQUEST_TIME_FLOAT'] = microtime(true);
     }
     $uri = $uri->withPath($path);
     $req = $this->filterRequestMethod($req->withUri($uri));
     $res = $next($req, $res);
     $res = $this->filterPrivateRoutes($uri, $res);
     // Only provide response calculation time in non-production env, tho.
     if ($this->settings['mode'] !== 'production') {
         $time = (microtime(true) - $server['REQUEST_TIME_FLOAT']) * 1000;
         $res = $res->withHeader('X-Response-Time', sprintf('%2.3fms', $time));
     }
     return $res;
 }
开发者ID:ninjanero,项目名称:slim-skeleton,代码行数:35,代码来源:CommonMiddleware.php

示例8: product_youtubePostAdd

 public function product_youtubePostAdd(Request $req, Response $res, $attr = [])
 {
     $container = $this->slim->getContainer();
     $db = $container->medoo;
     $postBody = $req->getParsedBody();
     // $insertParams = $this->adapterParams($postBody);
     $insertParams = [];
     $insertParams["product_id"] = $attr["product_id"];
     $insertParams["type"] = "youtube";
     $insertParams["youtube_id"] = $postBody["youtube_id"];
     $insertParams["sort_order"] = $db->max("product_media", "sort_order", ["AND" => ["product_id" => $attr["product_id"]]]) + 1;
     if (!$db->insert("product_media", $insertParams)) {
         return $res->withStatus(500)->withHeader('Content-Type', 'application/json')->write(json_encode(["error" => true]));
     }
     return $res->withStatus(200)->withHeader('Content-Type', 'application/json')->write(json_encode(["success" => true]));
 }
开发者ID:icezlizz1991,项目名称:tufftexgroup,代码行数:16,代码来源:ProductMediaController.php

示例9: __invoke

 public function __invoke(Request $req, Response $res, array $args = [])
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $params = $req->getParams();
     $id = $params['id'];
     $params['school_id'] = $school->id;
     if (isset($params['lessons']) && !is_array($params['lessons'])) {
         $params['lessons'] = explode(',', $params['lessons']);
     }
     unset($params['id']);
     try {
         if ($id) {
             $lab = $this->labservice->updateLab($params, $id);
             $res = $res->withStatus(200);
         } else {
             $lab = $this->labservice->createLab($params);
             $res = $res->withStatus(201);
         }
         $res = $res->withJson($lab);
     } catch (Exception $ex) {
         $res = $res->withStatus(500, $ex->getMessage());
     }
     return $res;
 }
开发者ID:eellak,项目名称:gredu_labs,代码行数:27,代码来源:PersistLab.php

示例10: __invoke

 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $lab_id = $req->getParam('lab_id', false);
     if (!$lab_id) {
         return $res->withStatus(404, 'No lab id');
     }
     $lab = $this->labService->getLabForSchool($school->id, $lab_id);
     try {
         $this->labService->removeLabAttachment($lab['id']);
         return $res->withStatus(204);
     } catch (Exception $ex) {
         return $res->withStatus(500, $ex->getMessage());
     }
 }
开发者ID:eellak,项目名称:gredu_labs,代码行数:18,代码来源:RemoveAttachment.php

示例11: dispatch

 public function dispatch(Request $request, Response $response, $args)
 {
     $meetupID = $request->getAttribute('meetup_id', null);
     $eventInfo = $this->eventService->getInfoByMeetupID($meetupID);
     if ($eventInfo->eventExists()) {
         $this->flash->addMessage('event', 'Event already exists. Check its status.');
         return $response->withStatus(302)->withHeader('Location', 'event-details/' . $meetupID);
     }
     if (!$eventInfo->isRegistered() && !is_null($meetupID)) {
         $this->flash->addMessage('event', 'No event found for meetupID provided. Please create a new event.');
         return $response->withStatus(302)->withHeader('Location', 'create-event');
     }
     $form = new CreateEventForm($this->eventManager, $this->eventService);
     if ($eventInfo->isRegistered()) {
         $form->setEventInfo($eventInfo);
     }
     $data = ['form' => $form, 'errors' => $this->flash->getMessage('event') ?? [], 'defaultTime' => $this->eventsConfig->defaultStartTime];
     if ($request->isPost()) {
         $form->populate($request->getParams());
         if (!$form->isValid()) {
             // return response
             $data['errors'] = $form->getErrors();
             $data = array_merge($data, $this->getCsrfValues($request));
             $response->withStatus(304);
             $this->view->render($response, 'admin/create-event.twig', $data);
             return $response;
         }
         try {
             $event = EventFactory::getEvent($form->getTalkTitle(), $form->getTalkDescription(), $form->getEventDate(), $form->getSpeaker(), $form->getVenue(), $form->getSupporter(), $this->eventsConfig->title, $this->eventsConfig->description);
             $createEventInfo = $this->eventService->createMainEvents($event, $this->auth->getUserId(), $meetupID);
             if (!is_null($createEventInfo['joindin_message'])) {
                 $this->flash->addMessage('event', $createEventInfo['joindin_message']);
             }
             return $response->withStatus(302)->withHeader('Location', 'event-details?meetup_id=' . $createEventInfo['meetup_id']);
         } catch (\Exception $e) {
             $this->logger->debug($e->getMessage());
             $this->logger->debug(print_r($data['errors'], true));
             $data['errors'] = array_merge($data['errors'], [$e->getMessage()]);
         }
     }
     $data = array_merge($data, $this->getCsrfValues($request));
     $this->view->render($response, 'admin/create-event.twig', $data);
     return $response;
 }
开发者ID:phpminds,项目名称:website,代码行数:44,代码来源:CreateEventAction.php

示例12: __invoke

 public function __invoke(Request $request, Response $response, $args)
 {
     $this->request =& $request;
     if ($this->execute($args)) {
         $responder = new $this->responder($response, $this->responseInfo);
         return $responder();
     } else {
         return $response->withStatus(self::STATUS_NOT_FOUND);
     }
 }
开发者ID:lacteosdelcesar,项目名称:s3-untitledApi-K,代码行数:10,代码来源:Action.php

示例13: declineFriendshipRequest

 /**
  * @param Request $req
  * @param Response $res
  * @param $args
  * @throws \BadMethodCallException
  * @return Response
  */
 public function declineFriendshipRequest(Request $req, Response $res, $args)
 {
     $toUserId = (int) $args['userId'];
     $fromUserId = (int) $req->getParam('fromUserId');
     if (empty($fromUserId)) {
         throw new \BadMethodCallException("POST param 'fromUserId' is required");
     }
     $this->friendship->declineFriendshipRequest($fromUserId, $toUserId);
     return $res->withStatus(200);
 }
开发者ID:AlexKR,项目名称:friendly,代码行数:17,代码来源:FriendshipController.php

示例14: __invoke

 public function __invoke(Request $req, Response $res, array $args = [])
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $staff = $this->staffService->getTeachersBySchoolId($school->id);
     return $this->view->render($res, 'schools/staff.twig', ['school' => $school, 'staff' => $staff, 'branches' => array_map(function ($branch) {
         return ['value' => $branch['id'], 'label' => $branch['name']];
     }, $this->staffService->getBranches())]);
 }
开发者ID:eellak,项目名称:gredu_labs,代码行数:11,代码来源:ListAll.php

示例15: __invoke

 /**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @param \Slim\Http\Response                      $response
  *
  * @return \Slim\Http\Response
  * @throws \livetyping\hermitage\app\exceptions\BadRequestException
  */
 public function __invoke(Request $request, Response $response) : Response
 {
     $mime = (string) current($request->getHeader('Content-Type'));
     $binary = (string) $request->getBody();
     if (empty($mime) || empty($binary) || !in_array($mime, Util::supportedMimeTypes())) {
         throw new BadRequestException('Invalid mime-type or body.');
     }
     $command = new StoreImageCommand($mime, $binary);
     $this->bus->handle($command);
     return $response->withStatus(201)->withJson(['filename' => $command->getPath()]);
 }
开发者ID:livetyping,项目名称:hermitage,代码行数:18,代码来源:StoreAction.php


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