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


PHP Response::create方法代码示例

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


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

示例1: __invoke

 public function __invoke(Request $request)
 {
     if ($this->service->delete($request->getRequestURI()) === false) {
         throw new ServiceUnavailableHttpException(null, "Failed to delete resource");
     }
     return Response::create("", Response::HTTP_NO_CONTENT);
 }
开发者ID:jdesrosiers,项目名称:resourceful,代码行数:7,代码来源:DeleteResourceController.php

示例2: checkIdExistsAction

 /**
  * Check Product existence for a given ID
  *
  * This API method will check if the given ID matches an existing product.
  *
  * @api_public
  * @param Request $request
  * @return Response
  */
 public function checkIdExistsAction(Request $request)
 {
     $id = $request->attributes->get('id');
     // TODO: check in DB if product ID exists
     return Response::create()->setStatusCode($id > 42 ? 404 : 200);
     // or 404 if not found.
 }
开发者ID:xGouley,项目名称:PSPublicReaderBundle,代码行数:16,代码来源:PropertiesV1Controller.php

示例3: __construct

 /** @inheritdoc */
 public function __construct(array $settings = [])
 {
     $this->_request = IfSet::get($settings, 'request', Request::createFromGlobals());
     $this->_response = IfSet::get($settings, 'response', Response::create());
     $this->_container = null;
     parent::__construct($settings);
 }
开发者ID:rajeshpillai,项目名称:php-utils,代码行数:8,代码来源:Environment.php

示例4: execute

 public function execute($request)
 {
     //generate cache key
     $key = $this->generateCacheKey($request);
     //check if exist in cache
     //if exist return
     if ($content = $this->cache->get($key)) {
         $response = Response::create($content, 200, ['Content-Type' => 'application/json']);
     } else {
         $token = $this->getToken();
         $request->headers->set('Authorization', "Bearer {$token}");
         //do request
         $forward_url = $this->api_base . $request->getPathInfo();
         $response = $this->proxy->forward($request)->to($forward_url);
         //token expired refresh and try again
         if ($response->getStatusCode() == 401) {
             $token = $this->generateToken();
             $request->headers->set('Authorization', "Bearer {$token}");
             $response = $this->proxy->forward($request)->to($forward_url);
         }
         //if status is 200 save in cache
         if ($response->getStatusCode() == 200) {
             $this->cache->set($key, $response->getContent());
             $this->cache->expire($key, 3600 * 12);
             //clear in 12 hours
         }
     }
     //output response
     return $response;
 }
开发者ID:sahanh,项目名称:api-proxy,代码行数:30,代码来源:RequestManager.php

示例5: setDefaultDependencies

 /**
  * Настраиваем зависимости фреймворка.
  */
 protected function setDefaultDependencies()
 {
     $this->container->set(Request::class, function (Container $c) {
         return Request::createFromGlobals();
     });
     $this->container->set(Response::class, function (Container $c) {
         return Response::create();
     });
     $this->container->set(RouteParser::class, function (Container $c) {
         return new RouteParser\Std();
     });
     $this->container->set(RouteCollector::class, function (Container $c) {
         /** @var RouteParser $routeParser */
         $routeParser = $c->get(RouteParser::class);
         return new RouteCollector($routeParser, new RouteDataGenerator());
     });
     $this->container->set(RouteDispatcher::class, function (Container $c) {
         /** @var RouteCollector $router */
         $router = $c->get(RouteCollector::class);
         return new RouteDispatcher($router->getData());
     });
     $this->container->set(UrlGenerator::class, function (Container $c) {
         /** @var RouteCollector $routeCollector */
         $routeCollector = $c->get(RouteCollector::class);
         /** @var RouteParser $routeParser */
         $routeParser = $c->get(RouteParser::class);
         return new UrlGenerator($routeCollector, $routeParser);
     });
 }
开发者ID:sheerockoff,项目名称:marabu,代码行数:32,代码来源:App.php

示例6: onQuickUploadResponse

    public function onQuickUploadResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        if ($request->get('responseType') === 'json') {
            return;
        }
        $response = $event->getResponse();
        $funcNum = $request->get('CKEditorFuncNum');
        $funcNum = preg_replace('/[^0-9]/', '', $funcNum);
        if ($response instanceof JsonResponse) {
            $responseData = $response->getData();
            $fileUrl = isset($responseData['url']) ? $responseData['url'] : '';
            $errorMessage = isset($responseData['error']['message']) ? $responseData['error']['message'] : '';
            ob_start();
            ?>
<script type="text/javascript">
    window.parent.CKEDITOR.tools.callFunction(<?php 
            echo json_encode($funcNum);
            ?>
, <?php 
            echo json_encode($fileUrl);
            ?>
, <?php 
            echo json_encode($errorMessage);
            ?>
);
</script>
            <?php 
            $event->setResponse(Response::create(ob_get_clean()));
        }
    }
开发者ID:SevenMonks,项目名称:100cities-dev,代码行数:31,代码来源:QuickUpload.php

示例7: testCreate

 public function testCreate()
 {
     $response = Response::create('foo', 301, array('Foo' => 'bar'));
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals(301, $response->getStatusCode());
     $this->assertEquals('bar', $response->headers->get('foo'));
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:7,代码来源:ResponseTest.php

示例8: getRedirectResponse

    public function getRedirectResponse()
    {
        if (!$this instanceof RedirectResponseInterface || !$this->isRedirect()) {
            throw new RuntimeException('This response does not support redirection.');
        }
        if ('GET' === $this->getRedirectMethod()) {
            return HttpRedirectResponse::create($this->getRedirectUrl());
        } elseif ('POST' === $this->getRedirectMethod()) {
            $hiddenFields = '';
            foreach ($this->getRedirectData() as $key => $value) {
                $hiddenFields .= sprintf('<input type="hidden" name="%1$s" value="%2$s" />', htmlentities($key, ENT_QUOTES, 'UTF-8', false), htmlentities($value, ENT_QUOTES, 'UTF-8', false)) . "\n";
            }
            $output = '<!DOCTYPE html>
<html>
    <head>
        <title>Redirecting...</title>
    </head>
    <body onload="document.forms[0].submit();">
        <form action="%1$s" method="post">
            <p>Redirecting to payment page...</p>
            <p>
                %2$s
                <input type="submit" value="Continue" />
            </p>
        </form>
    </body>
</html>';
            $output = sprintf($output, htmlentities($this->getRedirectUrl(), ENT_QUOTES, 'UTF-8', false), $hiddenFields);
            return HttpResponse::create($output);
        }
        throw new RuntimeException('Invalid redirect method "' . $this->getRedirectMethod() . '".');
    }
开发者ID:sanchojaf,项目名称:oldmytriptocuba,代码行数:32,代码来源:AbstractResponse.php

示例9: createResponse

 public function createResponse($exception, $onlyHtmlBodyContent = false)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     return Response::create($this->render($exception, $onlyHtmlBodyContent), $exception->getStatusCode(), $exception->getHeaders())->setCharset($this->charset);
 }
开发者ID:swayok,项目名称:laravel-extended-errors,代码行数:7,代码来源:ExceptionRenderer.php

示例10: onLogoutSuccess

 /**
  * {@inheritdoc}
  * @param Request $request
  * @return Response
  */
 public function onLogoutSuccess(Request $request)
 {
     if ($accessToken = $this->accessTokenManager->findTokenByToken($request->get('access_token'))) {
         $this->accessTokenManager->deleteToken($accessToken);
     }
     if ($accessToken = $this->accessTokenManager->findTokenByToken($request->cookies->get('access_token'))) {
         $this->accessTokenManager->deleteToken($accessToken);
     }
     if ($accessToken = $request->server->get('HTTP_AUTHORIZATION')) {
         if ($accessTokenObj = $this->accessTokenManager->findTokenByToken(substr($accessToken, 7))) {
             $this->accessTokenManager->deleteToken($accessTokenObj);
         }
     }
     if ($refreshToken = $this->refreshTokenManager->findTokenByToken($request->cookies->get('refresh_token'))) {
         $this->refreshTokenManager->deleteToken($refreshToken);
     }
     $request->headers->remove('Authorization');
     $request->server->remove('HTTP_AUTHORIZATION');
     $request->cookies->remove('access_token');
     $request->cookies->remove('refresh_token');
     $response = Response::create();
     $response->headers->clearCookie('access_token');
     $response->headers->clearCookie('refresh_token');
     return $response;
 }
开发者ID:renatomefidf,项目名称:sammui,代码行数:30,代码来源:LogoutSuccess.php

示例11: createAction

 /**
  * @param Request $request
  * @param int     $id
  *
  * @return Response
  * @throws \Exception
  */
 public function createAction(Request $request, $id = 0)
 {
     $repository = $this->getRepository();
     if (!$repository instanceof CrudRepositoryInterface) {
         throw new \Exception("Repository class must be implemented CrudRepositoryInterface");
     }
     $viewData = [];
     $entity = $repository->find($id);
     if (!$entity) {
         $entity = $repository->createEntity();
     }
     $form = $this->getCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $request->getMethod() === "POST") {
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $em->persist($entity);
             $em->flush();
             return RedirectResponse::create($this->getRouter());
         } else {
             return Response::create($form->getErrorsAsString(), 406);
         }
     }
     $viewData['form'] = $form->createView();
     $response = $this->render($this->createView, $viewData);
     return $response;
 }
开发者ID:AnkaraPHP,项目名称:pheetup,代码行数:34,代码来源:CrudController.php

示例12: testResponseObjectConstructionWithCustomResponse

 public function testResponseObjectConstructionWithCustomResponse()
 {
     $representation = new Json();
     $symResponse = \Symfony\Component\HttpFoundation\Response::create();
     $response = new Response($representation, $symResponse);
     $this->assertEquals($representation, $response->getRepresentation());
 }
开发者ID:leedavis81,项目名称:drest-client,代码行数:7,代码来源:ResponseTest.php

示例13: checkSemaphoreAction

 public function checkSemaphoreAction(Request $request)
 {
     // TODO !5: comportement de cette action à voir quand rabbitMQ arrivera
     //dump($request->attributes->get('footprint'));
     return Response::create('', 202, []);
     // '', 409, ['ps_status_text' => 'This request is already in working queue.']);
 }
开发者ID:xGouley,项目名称:PSPublicWriterBundle,代码行数:7,代码来源:PreprocessedRedirectController.php

示例14: test_NoRouteStrategyException_is_thrown

 /**
  * @covers \Colonel\HttpKernel::handle
  * @covers \Colonel\HttpKernel::run
  */
 public function test_NoRouteStrategyException_is_thrown()
 {
     $this->setExpectedException(NoRouteStrategyDefinedException::class);
     new HttpKernel(['debug' => false, 'services' => ['di' => []], 'routes' => ['test_group' => ['test_route' => ['pattern' => '/', 'controller' => function () {
         return Response::create('<h1>It works!</h1>', 200);
     }, 'method' => 'GET']]]]);
 }
开发者ID:nigelgreenway,项目名称:colonel,代码行数:11,代码来源:HttpKernelTest.php

示例15: terminate

 public function terminate()
 {
     if ($this->booted) {
         $response = Response::create('');
         $this->kernel->terminate($this->request, $response);
     }
 }
开发者ID:amira2r,项目名称:DrupalConsole,代码行数:7,代码来源:KernelHelper.php


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