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


PHP Response::withProtocolVersion方法代码示例

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


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

示例1: register

 /**
  * {@inheritdoc}
  */
 public function register()
 {
     $this->getContainer()->share('settings', function () {
         return new Collection($this->defaultSettings);
     });
     $this->getContainer()->share('environment', function () {
         return new Environment($_SERVER);
     });
     $this->getContainer()->share('request', function () {
         return Request::createFromEnvironment($this->getContainer()->get('environment'));
     });
     $this->getContainer()->share('response', function () {
         $headers = new Headers(['Content-Type' => 'text/html']);
         $response = new Response(200, $headers);
         return $response->withProtocolVersion($this->getContainer()->get('settings')['httpVersion']);
     });
     $this->getContainer()->share('router', function () {
         return new Router();
     });
     $this->getContainer()->share('foundHandler', function () {
         return new RequestResponse();
     });
     $this->getContainer()->share('errorHandler', function () {
         return new Error($this->getContainer()->get('settings')['displayErrorDetails']);
     });
     $this->getContainer()->share('notFoundHandler', function () {
         return new NotFound();
     });
     $this->getContainer()->share('notAllowedHandler', function () {
         return new NotAllowed();
     });
     $this->getContainer()->share('callableResolver', function () {
         return new CallableResolver($this->getContainer());
     });
 }
开发者ID:jenssegers,项目名称:lean,代码行数:38,代码来源:SlimServiceProvider.php

示例2: __invoke

 /**
  * @param \swoole_http_request $request
  * @param \swoole_http_response $response
  * @throws \Exception
  */
 public function __invoke($request, $response)
 {
     $this->app->getContainer()['environment'] = $this->app->getContainer()->factory(function () {
         return new Environment($_SERVER);
     });
     $this->app->getContainer()['request'] = $this->app->getContainer()->factory(function ($container) {
         return Request::createFromEnvironment($container['environment']);
     });
     $this->app->getContainer()['response'] = $this->app->getContainer()->factory(function ($container) {
         $headers = new Headers(['Content-Type' => 'text/html']);
         $response = new Response(200, $headers);
         return $response->withProtocolVersion($container->get('settings')['httpVersion']);
     });
     /**
      * @var ResponseInterface $appResponse
      */
     $appResponse = $this->app->run(true);
     // set http header
     foreach ($appResponse->getHeaders() as $key => $value) {
         $filter_header = function ($header) {
             $filtered = str_replace('-', ' ', $header);
             $filtered = ucwords($filtered);
             return str_replace(' ', '-', $filtered);
         };
         $name = $filter_header($key);
         foreach ($value as $v) {
             $response->header($name, $v);
         }
     }
     // set http status
     $response->status($appResponse->getStatusCode());
     // send response to browser
     if (!$this->isEmptyResponse($appResponse)) {
         $body = $appResponse->getBody();
         if ($body->isSeekable()) {
             $body->rewind();
         }
         $settings = $this->app->getContainer()->get('settings');
         $chunkSize = $settings['responseChunkSize'];
         $contentLength = $appResponse->getHeaderLine('Content-Length');
         if (!$contentLength) {
             $contentLength = $body->getSize();
         }
         $totalChunks = ceil($contentLength / $chunkSize);
         $lastChunkSize = $contentLength % $chunkSize;
         $currentChunk = 0;
         while (!$body->eof() && $currentChunk < $totalChunks) {
             if (++$currentChunk == $totalChunks && $lastChunkSize > 0) {
                 $chunkSize = $lastChunkSize;
             }
             $response->write($body->read($chunkSize));
             if (connection_status() != CONNECTION_NORMAL) {
                 break;
             }
         }
         $response->end();
     }
 }
开发者ID:praswicaksono,项目名称:veloce,代码行数:63,代码来源:RequestHandler.php

示例3: __construct

 /**
  * Create new container
  *
  * @param array $settings Associative array of settings. User settings are in a 'settings' sub-array
  */
 public function __construct($settings = [])
 {
     $userSettings = [];
     if (isset($settings['settings'])) {
         $userSettings = $settings['settings'];
         unset($settings['settings']);
     }
     // Add settings factory that also collects the default settings
     $defaultSettings = $this->defaultSettings;
     $settings['factories']['settings'] = function ($c) use($userSettings, $defaultSettings) {
         return array_merge($defaultSettings, $userSettings);
     };
     // Add default services if they aren't added already
     if (!isset($settings['environment'])) {
         $settings['factories']['environment'] = function ($c) {
             return new Environment($_SERVER);
         };
     }
     if (!isset($settings['request'])) {
         $settings['factories']['request'] = function ($c) {
             return Request::createFromEnvironment($c['environment']);
         };
     }
     if (!isset($settings['response'])) {
         $settings['factories']['response'] = function ($c) {
             $headers = new Headers(['Content-Type' => 'text/html']);
             $response = new Response(200, $headers);
             return $response->withProtocolVersion($c['settings']['httpVersion']);
         };
     }
     if (!isset($settings['router'])) {
         $settings['factories']['router'] = function ($c) {
             return new Router();
         };
     }
     if (!isset($settings['callableResolver'])) {
         $settings['factories']['callableResolver'] = function ($c) {
             return new CallableResolver($c);
         };
     }
     if (!isset($settings['foundHandler'])) {
         $settings['invokables']['foundHandler'] = RequestResponse::class;
     }
     if (!isset($settings['errorHandler'])) {
         $settings['factories']['errorHandler'] = function ($c) {
             return new Error($c->get('settings')['displayErrorDetails']);
         };
     }
     if (!isset($settings['notFoundHandler'])) {
         $settings['invokables']['notFoundHandler'] = NotFound::class;
     }
     if (!isset($settings['notAllowedHandler'])) {
         $settings['invokables']['notAllowedHandler'] = NotAllowed::class;
     }
     parent::__construct($settings);
 }
开发者ID:akrabat,项目名称:rka-slim-zfsm-container,代码行数:61,代码来源:Container.php

示例4: __construct

 public function __construct(array $userSettings = [])
 {
     parent::__construct();
     $this["settings"] = function ($c) use($userSettings) {
         return array_merge($c->defaultSettings, $userSettings);
     };
     $this["environment"] = function () {
         return new Environment($_SERVER);
     };
     $this["request"] = $this->factory(function ($c) {
         return Request::createFromEnvironment($c["environment"]);
     });
     $this["response"] = $this->factory(function ($c) {
         $headers = new Headers(["Content-Type" => "text/html"]);
         $response = new Response(200, $headers);
         return $response->withProtocolVersion($c["settings"]["httpVersion"]);
     });
     $this["router"] = function ($c) {
         return (new Router())->setContainer($c);
     };
 }
开发者ID:zither,项目名称:memo,代码行数:21,代码来源:App.php

示例5: registerDefaultServices

 /**
  * This function registers the default services that Slim needs to work.
  *
  * All services are shared - that is, they are registered such that the
  * same instance is returned on subsequent calls.
  *
  * @param array $userSettings Associative array of application settings
  *
  * @return void
  */
 private function registerDefaultServices($userSettings)
 {
     $defaultSettings = $this->defaultSettings;
     /**
      * This service MUST return an array or an
      * instance of \ArrayAccess.
      *
      * @return array|\ArrayAccess
      */
     $this['settings'] = function () use($userSettings, $defaultSettings) {
         return new Collection(array_merge($defaultSettings, $userSettings));
     };
     if (!isset($this['environment'])) {
         /**
          * This service MUST return a shared instance
          * of \Slim\Interfaces\Http\EnvironmentInterface.
          *
          * @return EnvironmentInterface
          */
         $this['environment'] = function () {
             return new Environment($_SERVER);
         };
     }
     if (!isset($this['request'])) {
         /**
          * PSR-7 Request object
          *
          * @param Container $c
          *
          * @return ServerRequestInterface
          */
         $this['request'] = function ($c) {
             return Request::createFromEnvironment($c->get('environment'));
         };
     }
     if (!isset($this['response'])) {
         /**
          * PSR-7 Response object
          *
          * @param Container $c
          *
          * @return ResponseInterface
          */
         $this['response'] = function ($c) {
             $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
             $response = new Response(200, $headers);
             return $response->withProtocolVersion($c->get('settings')['httpVersion']);
         };
     }
     if (!isset($this['router'])) {
         /**
          * This service MUST return a SHARED instance
          * of \Slim\Interfaces\RouterInterface.
          *
          * @return RouterInterface
          */
         $this['router'] = function () {
             return new Router();
         };
     }
     if (!isset($this['foundHandler'])) {
         /**
          * This service MUST return a SHARED instance
          * of \Slim\Interfaces\InvocationStrategyInterface.
          *
          * @return InvocationStrategyInterface
          */
         $this['foundHandler'] = function () {
             return new RequestResponse();
         };
     }
     if (!isset($this['errorHandler'])) {
         /**
          * This service MUST return a callable
          * that accepts three arguments:
          *
          * 1. Instance of \Psr\Http\Message\ServerRequestInterface
          * 2. Instance of \Psr\Http\Message\ResponseInterface
          * 3. Instance of \Exception
          *
          * The callable MUST return an instance of
          * \Psr\Http\Message\ResponseInterface.
          *
          * @param Container $c
          *
          * @return callable
          */
         $this['errorHandler'] = function ($c) {
             return new Error($c->get('settings')['displayErrorDetails']);
         };
//.........这里部分代码省略.........
开发者ID:kschaefers,项目名称:RaumsucheRestBackend,代码行数:101,代码来源:Container.php

示例6: get

<?php

use DI\Bridge\Slim\CallableResolver;
use DI\Bridge\Slim\ControllerInvoker;
use DI\Container;
use DI\Scope;
use Interop\Container\ContainerInterface;
use Invoker\Invoker;
use Invoker\ParameterResolver\AssociativeArrayResolver;
use Invoker\ParameterResolver\Container\TypeHintContainerResolver;
use Invoker\ParameterResolver\ResolverChain;
use Slim\Http\Headers;
use Slim\Http\Request;
use Slim\Http\Response;
use function DI\factory;
use function DI\get;
use function DI\object;
return ['settings.httpVersion' => '1.1', 'settings.responseChunkSize' => 4096, 'settings.outputBuffering' => 'append', 'settings.determineRouteBeforeAppMiddleware' => false, 'settings.displayErrorDetails' => false, 'settings' => ['httpVersion' => get('settings.httpVersion'), 'responseChunkSize' => get('settings.responseChunkSize'), 'outputBuffering' => get('settings.outputBuffering'), 'determineRouteBeforeAppMiddleware' => get('settings.determineRouteBeforeAppMiddleware'), 'displayErrorDetails' => get('settings.displayErrorDetails')], 'router' => object(Slim\Router::class), 'errorHandler' => object(Slim\Handlers\Error::class)->constructor(get('settings.displayErrorDetails')), 'notFoundHandler' => object(Slim\Handlers\NotFound::class), 'notAllowedHandler' => object(Slim\Handlers\NotAllowed::class), 'environment' => function () {
    return new Slim\Http\Environment($_SERVER);
}, 'request' => factory(function (ContainerInterface $c) {
    return Request::createFromEnvironment($c->get('environment'));
})->scope(Scope::SINGLETON), 'response' => factory(function (ContainerInterface $c) {
    $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
    $response = new Response(200, $headers);
    return $response->withProtocolVersion($c->get('settings')['httpVersion']);
})->scope(Scope::SINGLETON), 'foundHandler' => object(ControllerInvoker::class)->constructor(get('foundHandler.invoker')), 'foundHandler.invoker' => function (ContainerInterface $c) {
    $resolvers = [new AssociativeArrayResolver(), new TypeHintContainerResolver($c)];
    return new Invoker(new ResolverChain($resolvers), $c);
}, 'callableResolver' => object(CallableResolver::class), ContainerInterface::class => get(Container::class)];
开发者ID:vonalbert,项目名称:Slim-Bridge,代码行数:29,代码来源:config.php

示例7: register

 /**
  * Register Slim's default services.
  *
  * @param Container $container A DI container implementing ArrayAccess and container-interop.
  */
 public function register($container)
 {
     if (!isset($container['environment'])) {
         /**
          * This service MUST return a shared instance
          * of \Slim\Interfaces\Http\EnvironmentInterface.
          *
          * @return EnvironmentInterface
          */
         $container['environment'] = function () {
             return new Environment($_SERVER);
         };
     }
     if (!isset($container['request'])) {
         /**
          * PSR-7 Request object
          *
          * @param Container $container
          *
          * @return ServerRequestInterface
          */
         $container['request'] = function ($container) {
             return Request::createFromEnvironment($container->get('environment'));
         };
     }
     if (!isset($container['response'])) {
         /**
          * PSR-7 Response object
          *
          * @param Container $container
          *
          * @return ResponseInterface
          */
         $container['response'] = function ($container) {
             $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
             $response = new Response(200, $headers);
             return $response->withProtocolVersion($container->get('settings')['httpVersion']);
         };
     }
     if (!isset($container['router'])) {
         /**
          * This service MUST return a SHARED instance
          * of \Slim\Interfaces\RouterInterface.
          *
          * @param Container $container
          *
          * @return RouterInterface
          */
         $container['router'] = function ($container) {
             $routerCacheFile = false;
             if (isset($container->get('settings')['routerCacheFile'])) {
                 $routerCacheFile = $container->get('settings')['routerCacheFile'];
             }
             return (new Router())->setCacheFile($routerCacheFile);
         };
     }
     if (!isset($container['foundHandler'])) {
         /**
          * This service MUST return a SHARED instance
          * of \Slim\Interfaces\InvocationStrategyInterface.
          *
          * @return InvocationStrategyInterface
          */
         $container['foundHandler'] = function () {
             return new RequestResponse();
         };
     }
     if (!isset($container['phpErrorHandler'])) {
         /**
          * This service MUST return a callable
          * that accepts three arguments:
          *
          * 1. Instance of \Psr\Http\Message\ServerRequestInterface
          * 2. Instance of \Psr\Http\Message\ResponseInterface
          * 3. Instance of \Error
          *
          * The callable MUST return an instance of
          * \Psr\Http\Message\ResponseInterface.
          *
          * @param Container $container
          *
          * @return callable
          */
         $container['phpErrorHandler'] = function ($container) {
             return new PhpError($container->get('settings')['displayErrorDetails']);
         };
     }
     if (!isset($container['errorHandler'])) {
         /**
          * This service MUST return a callable
          * that accepts three arguments:
          *
          * 1. Instance of \Psr\Http\Message\ServerRequestInterface
          * 2. Instance of \Psr\Http\Message\ResponseInterface
          * 3. Instance of \Exception
//.........这里部分代码省略.........
开发者ID:ModelSolv,项目名称:swagger-codegen,代码行数:101,代码来源:DefaultServicesProvider.php

示例8: __construct

 /**
  * Create new container
  *
  * @param array $userSettings Associative array of application settings
  */
 public function __construct(array $userSettings = [])
 {
     parent::__construct();
     $defaultSettings = $this->defaultSettings;
     /**
      * This service MUST return an array or an
      * instance of \ArrayAccess.
      *
      * @param Container $c
      *
      * @return array|\ArrayAccess
      */
     $this->setFactory('settings', function ($c) use($userSettings, $defaultSettings) {
         return array_merge($defaultSettings, $userSettings);
     });
     /**
      * This service MUST return a shared instance
      * of \Slim\Interfaces\Http\EnvironmentInterface.
      *
      * @param Container $c
      *
      * @return EnvironmentInterface
      */
     $this->setFactory('environment', function ($c) {
         return new Environment($_SERVER);
     });
     /**
      * \Psr\Http\Message\ServerRequestInterface.
      */
     $this->setFactory('request', function ($c) {
         return Request::createFromEnvironment($c['environment']);
     });
     /**
      * \Psr\Http\Message\ResponseInterface.
      */
     $this->setFactory('response', function ($c) {
         $headers = new Headers(['Content-Type' => 'text/html']);
         $response = new Response(200, $headers);
         return $response->withProtocolVersion($c['settings']['httpVersion']);
     });
     /**
      * This service MUST return a SHARED instance
      * of \Slim\Interfaces\RouterInterface.
      *
      * @param Container $c
      *
      * @return RouterInterface
      */
     $this->setFactory('router', function ($c) {
         return new Router();
     });
     /**
      * This service MUST return a SHARED instance
      * of \Slim\Interfaces\InvocationStrategyInterface.
      *
      * @param Container $c
      *
      * @return InvocationStrategyInterface
      */
     $this->setFactory('foundHandler', function ($c) {
         return new RequestResponse();
     });
     /**
      * This service MUST return a callable
      * that accepts three arguments:
      *
      * 1. Instance of \Psr\Http\Message\ServerRequestInterface
      * 2. Instance of \Psr\Http\Message\ResponseInterface
      * 3. Instance of \Exception
      *
      * The callable MUST return an instance of
      * \Psr\Http\Message\ResponseInterface.
      *
      * @param Container $c
      *
      * @return callable
      */
     $this->setFactory('errorHandler', function ($c) {
         return new Error();
     });
     /**
      * This service MUST return a callable
      * that accepts two arguments:
      *
      * 1. Instance of \Psr\Http\Message\ServerRequestInterface
      * 2. Instance of \Psr\Http\Message\ResponseInterface
      *
      * The callable MUST return an instance of
      * \Psr\Http\Message\ResponseInterface.
      *
      * @param Container $c
      *
      * @return callable
      */
     $this->setFactory('notFoundHandler', function ($c) {
//.........这里部分代码省略.........
开发者ID:boosis,项目名称:rka-slim-zfsm-container,代码行数:101,代码来源:Container.php

示例9: getDefaultServicesDefinitions

 /**
  * Get definitions for Slim's default services
  *
  * @param array $userSettings
  *
  * @throws \InvalidArgumentException
  *
  * @return callable[]
  */
 private static function getDefaultServicesDefinitions(array $userSettings)
 {
     $defaultSettings = self::$defaultSettings;
     return ['settings' => function () use($defaultSettings, $userSettings) {
         return new Collection(array_merge($defaultSettings, $userSettings));
     }, 'environment' => function () {
         return new Environment($_SERVER);
     }, 'request' => function (ContainerInterface $container) {
         return Request::createFromEnvironment($container->get('environment'));
     }, 'response' => function (ContainerInterface $container) {
         $headers = new Headers(['Content-Type' => 'text/html; charset=utf-8']);
         $response = new Response(200, $headers);
         return $response->withProtocolVersion($container->get('settings')['httpVersion']);
     }, 'router' => function (ContainerInterface $container) {
         $routerCacheFile = false;
         if (isset($container->get('settings')['routerCacheFile'])) {
             $routerCacheFile = $container->get('settings')['routerCacheFile'];
         }
         return (new Router())->setCacheFile($routerCacheFile);
     }, 'foundHandler' => function () {
         return new RequestResponse();
     }, 'phpErrorHandler' => function (ContainerInterface $container) {
         return new PhpError($container->get('settings')['displayErrorDetails']);
     }, 'errorHandler' => function (ContainerInterface $container) {
         return new Error($container->get('settings')['displayErrorDetails']);
     }, 'notFoundHandler' => function () {
         return new NotFound();
     }, 'notAllowedHandler' => function () {
         return new NotAllowed();
     }, 'callableResolver' => function (ContainerInterface $container) {
         return new CallableResolver($container);
     }];
 }
开发者ID:juliangut,项目名称:slim-php-di,代码行数:42,代码来源:ContainerBuilder.php

示例10: function

use Slim\Router;
use Slim\Handlers\Error;
return ['settings' => function (ContainerInterface $container) {
    $config = $container->get(ConfigRepository::class);
    return $config->get('slim');
}, 'environment' => function () {
    return new Environment($_SERVER);
}, 'request' => function (ContainerInterface $container) {
    $environment = $container->get('environment');
    return Request::createFromEnvironment($environment);
}, 'response' => function (ContainerInterface $container) {
    $config = $container->get(ConfigRepository::class);
    $slimConfig = $config->get('slim');
    $headers = new Headers(['Content-Type' => 'text/html']);
    $response = new Response(200, $headers);
    return $response->withProtocolVersion($slimConfig['httpVersion']);
}, 'router' => function () {
    return new Router();
}, 'foundHandler' => function () {
    return new RequestResponse();
}, 'errorHandler' => function (ContainerInterface $container) {
    $config = $container->get(ConfigRepository::class);
    $slimConfig = $config->get('slim');
    return new Error($slimConfig['displayErrorDetails']);
}, 'notFoundHandler' => function () {
    return new NotFound();
}, 'notAllowedHandler' => function () {
    return new NotAllowed();
}, 'callableResolver' => function (ContainerInterface $container) {
    return new CallableResolver($container);
}];
开发者ID:ozag,项目名称:slim-skeleton,代码行数:31,代码来源:slim-definitions.php


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