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


PHP Http\Environment类代码示例

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


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

示例1: createFromEnvironment

 /**
  * Create a normalized tree of UploadedFile instances from the Environment.
  *
  * @param Environment $env The environment
  *
  * @return array|null A normalized tree of UploadedFile instances or null if none are provided.
  */
 public static function createFromEnvironment(Environment $env)
 {
     if (is_array($env['slim.files']) && $env->has('slim.files')) {
         return $env['slim.files'];
     } elseif (isset($_FILES)) {
         return static::parseUploadedFiles($_FILES);
     }
     return [];
 }
开发者ID:tgfbikes,项目名称:php,代码行数:16,代码来源:UploadedFile.php

示例2: determineAuthorization

 /**
  * If HTTP_AUTHORIZATION does not exist tries to get it from
  * getallheaders() when available.
  *
  * @param Environment $environment The Slim application Environment
  *
  * @return Environment
  */
 public static function determineAuthorization(Environment $environment)
 {
     $authorization = $environment->get('HTTP_AUTHORIZATION');
     if (null === $authorization && is_callable('getallheaders')) {
         $headers = getallheaders();
         $headers = array_change_key_case($headers, CASE_LOWER);
         if (isset($headers['authorization'])) {
             $environment->set('HTTP_AUTHORIZATION', $headers['authorization']);
         }
     }
     return $environment;
 }
开发者ID:mateuszmackowiak,项目名称:swagger-codegen,代码行数:20,代码来源:Headers.php

示例3: setUp

 public function setUp()
 {
     $this->encryption = Mockery::mock(CookieEncryptionInterface::class);
     $this->request = Request::createFromEnvironment(Environment::mock());
     $this->response = new Response();
     $this->capturedRequest = null;
 }
开发者ID:quickenloans-mcp,项目名称:mcp-panthor,代码行数:7,代码来源:EncryptedCookiesMiddlewareTest.php

示例4: requestFactory

 /**
  * @param $method
  * @param $path
  * @param $body
  * @param $options
  * @return Request
  */
 protected function requestFactory($method, $path, $body = [], $options = [])
 {
     $uri = Uri::createFromString($path);
     $headers = new Headers();
     $cookies = [];
     $_POST['_METHOD'] = $method;
     if (strtolower($method) != 'get' && is_array($body)) {
         foreach ($body as $key => $value) {
             $_POST[$key] = $value;
         }
     }
     $envMethod = 'POST';
     if (strtolower($method) == 'get') {
         $envMethod = 'GET';
     }
     $env = Environment::mock(['REQUEST_URI' => $path, 'REQUEST_METHOD' => $envMethod, 'HTTP_CONTENT_TYPE' => 'multipart/form-data; boundary=---foo']);
     $serverParams = $env->all();
     $body = $this->buildBody($body);
     //echo $body->getContents();
     // @todo
     // $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body, []);
     $request = Request::createFromEnvironment($env);
     unset($_POST);
     return $request;
 }
开发者ID:SharkIng,项目名称:ss-panel,代码行数:32,代码来源:TestCase.php

示例5: setUp

 public function setUp()
 {
     $this->request = Request::createFromEnvironment(Environment::mock());
     $this->response = new Response();
     $this->logger = new MemoryLogger();
     $this->config = ['error' => 'critical', 'not-allowed' => 'info', 'not-found' => 'info'];
 }
开发者ID:quickenloans-mcp,项目名称:mcp-panthor,代码行数:7,代码来源:LoggingContentHandlerTest.php

示例6: dispatch

 protected function dispatch($path, $method = 'GET', $data = array(), $cookies = array())
 {
     $container = $this->app->getContainer();
     // seperate the path from the query string so we can set in the environment
     @(list($path, $queryString) = explode('?', $path));
     // Prepare a mock environment
     $env = Environment::mock(array('REQUEST_URI' => $path, 'REQUEST_METHOD' => $method, 'QUERY_STRING' => is_null($queryString) ? '' : $queryString));
     // Prepare request and response objects
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = $cookies;
     $serverParams = $env->all();
     $body = new RequestBody();
     // create request, and set params
     $req = new $container['request']($method, $uri, $headers, $cookies, $serverParams, $body);
     if (!empty($data)) {
         $req = $req->withParsedBody($data);
     }
     $res = new $container['response']();
     // // Fix for body, but breaks POST params in tests - http://stackoverflow.com/questions/34823328/response-getbody-is-empty-when-testing-slim-3-routes-with-phpunit
     // $body = new RequestBody();
     // if (!empty($data))
     //    $body->write(json_encode($data));
     //
     // // create request, and set params
     // $req = new $container['request']($method, $uri, $headers, $cookies, $serverParams, $body);
     // $res = new $container['response']();
     $this->headers = $headers;
     $this->request = $req;
     $this->response = call_user_func_array($this->app, array($req, $res));
 }
开发者ID:martynbiz,项目名称:slim3-controller,代码行数:31,代码来源:TestCase.php

示例7: runApp

 /**
  * Process the application given a request method and URI
  *
  * @param string $requestMethod the request method (e.g. GET, POST, etc.)
  * @param string $requestUri the request URI
  * @param array|object|null $requestData the request data
  * @return \Slim\Http\Response
  */
 public function runApp($requestMethod, $requestUri, $requestData = null)
 {
     // Create a mock environment for testing with
     $environment = Environment::mock(['REQUEST_METHOD' => $requestMethod, 'REQUEST_URI' => $requestUri]);
     // Set up a request object based on the environment
     $request = Request::createFromEnvironment($environment);
     // Add request data, if it exists
     if (isset($requestData)) {
         $request = $request->withParsedBody($requestData);
     }
     // Set up a response object
     $response = new Response();
     // Use the application settings
     $settings = (require __DIR__ . '/../../src/settings.php');
     // Instantiate the application
     $app = new App($settings);
     // Set up dependencies
     require __DIR__ . '/../../src/dependencies.php';
     // Register middleware
     if ($this->withMiddleware) {
         require __DIR__ . '/../../src/middleware.php';
     }
     // Register routes
     require __DIR__ . '/../../src/routes.php';
     // Process the application
     $response = $app->process($request, $response);
     // Return the response
     return $response;
 }
开发者ID:COCAFoundation,项目名称:coca_help,代码行数:37,代码来源:BaseTestCase.php

示例8: request

 private function request($method, $path, $data = array(), $optionalHeaders = array())
 {
     //Make method uppercase
     $method = strtoupper($method);
     $options = array('REQUEST_METHOD' => $method, 'REQUEST_URI' => $path);
     if ($method === 'GET') {
         $options['QUERY_STRING'] = http_build_query($data);
     } else {
         $params = json_encode($data);
     }
     // Prepare a mock environment
     $env = Environment::mock(array_merge($options, $optionalHeaders));
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = $this->cookies;
     $serverParams = $env->all();
     $body = new RequestBody();
     // Attach JSON request
     if (isset($params)) {
         $headers->set('Content-Type', 'application/json;charset=utf8');
         $body->write($params);
     }
     $this->request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
     $response = new Response();
     // Invoke request
     $app = $this->app;
     $this->response = $app($this->request, $response);
     // Return the application output.
     return (string) $this->response->getBody();
 }
开发者ID:there4,项目名称:slim-test-helpers,代码行数:30,代码来源:WebTestClient.php

示例9: requestFactory

 public function requestFactory($method, $path)
 {
     $environment = Environment::mock(['REQUEST_METHOD' => $method, 'REQUEST_URI' => $path, 'QUERY_STRING' => 'foo=bar']);
     $request = Request::createFromEnvironment($environment);
     $request->withMethod('GET');
     return $request;
 }
开发者ID:NothingToDoCN,项目名称:ss-panel,代码行数:7,代码来源:TestCase.php

示例10: request

 /**
  * Perform request
  *
  * @param string $method
  * @param string $uri
  * @param array $params
  * @param array $server
  * @param string $content
  *
  * @throws \Slim\Exception\MethodNotAllowedException
  * @throws \Slim\Exception\NotFoundException
  */
 public function request($method, $uri, array $params = [], array $server = [], $content = null)
 {
     $method = strtoupper($method);
     switch ($method) {
         case 'POST':
         case 'PUT':
         case 'PATCH':
         case 'DELETE':
             $this->server['slim.input'] = http_build_query($params);
             $query = '';
             break;
         case 'GET':
         default:
             $query = http_build_query($params);
             break;
     }
     $server = array_merge($this->server, $server, ['CONTENT_TYPE' => 'application/json', 'REQUEST_URI' => $uri, 'REQUEST_METHOD' => $method, 'QUERY_STRING' => $query]);
     $env = Http\Environment::mock($server);
     $request = Http\Request::createFromEnvironment($env);
     $response = new Http\Response();
     // dirty hack to set body of request :(
     if (!is_null($content)) {
         \Closure::bind(function ($request) use($content) {
             $request->bodyParsed = $content;
         }, null, $request)->__invoke($request);
     }
     $response = $this->app->__invoke($request, $response);
     $this->request = $request;
     $this->response = $response;
 }
开发者ID:EugeneKirillov,项目名称:organization-relationships,代码行数:42,代码来源:WebTestClient.php

示例11: testMock

 /**
  * Test environment from mock data
  */
 public function testMock()
 {
     $env = Environment::mock(['SCRIPT_NAME' => '/foo/bar/index.php', 'REQUEST_URI' => '/foo/bar?abc=123']);
     $this->assertTrue(is_array($env));
     $this->assertEquals('/foo/bar/index.php', $env['SCRIPT_NAME']);
     $this->assertEquals('/foo/bar?abc=123', $env['REQUEST_URI']);
     $this->assertEquals('localhost', $env['HTTP_HOST']);
 }
开发者ID:slimphp,项目名称:Slim-Http,代码行数:11,代码来源:EnvironmentTest.php

示例12: testMock

 /**
  * Test environment from mock data
  */
 public function testMock()
 {
     $env = Environment::mock(['SCRIPT_NAME' => '/foo/bar/index.php', 'REQUEST_URI' => '/foo/bar?abc=123']);
     $this->assertInstanceOf('\\Slim\\Interfaces\\CollectionInterface', $env);
     $this->assertEquals('/foo/bar/index.php', $env->get('SCRIPT_NAME'));
     $this->assertEquals('/foo/bar?abc=123', $env->get('REQUEST_URI'));
     $this->assertEquals('localhost', $env->get('HTTP_HOST'));
 }
开发者ID:hidayat365,项目名称:phpindonesia.or.id-membership2,代码行数:11,代码来源:EnvironmentTest.php

示例13: setUp

 public function setUp()
 {
     $container = new \Slim\Container(include "./Skeleton/Config/test.config.php");
     $this->controller = $container[DefaultController::class];
     $this->response = new Response();
     $this->request = Request::createFromEnvironment(Environment::mock());
     $this->args = [];
 }
开发者ID:geggleto,项目名称:skeleton,代码行数:8,代码来源:DefaultControllerTest.php

示例14: testCreateFromEnvironmentIgnoresHeaders

 public function testCreateFromEnvironmentIgnoresHeaders()
 {
     $e = Environment::mock(['CONTENT_TYPE' => 'text/csv', 'HTTP_CONTENT_LENGTH' => 1230]);
     $h = Headers::createFromEnvironment($e);
     $prop = new ReflectionProperty($h, 'data');
     $prop->setAccessible(true);
     $this->assertNotContains('content-length', $prop->getValue($h));
 }
开发者ID:hidayat365,项目名称:phpindonesia.or.id-membership2,代码行数:8,代码来源:HeadersTest.php

示例15: testRunWithoutObjTypeIs404

 /**
  *
  */
 public function testRunWithoutObjTypeIs404()
 {
     $request = Request::createFromEnvironment(Environment::mock());
     $response = new Response();
     $res = $this->obj->run($request, $response);
     $this->assertEquals(404, $res->getStatusCode());
     $res = $this->obj->results();
     $this->assertFalse($res['success']);
 }
开发者ID:locomotivemtl,项目名称:charcoal-admin,代码行数:12,代码来源:SaveActionTest.php


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