當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。