initialize() public method

This method also re-initializes all properties.
public initialize ( array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], string | resource $content = null )
$query array The GET parameters
$request array The POST parameters
$attributes array The request attributes (parameters parsed from the PATH_INFO, ...)
$cookies array The COOKIE parameters
$files array The FILES parameters
$server array The SERVER parameters
$content string | resource The raw body data
コード例 #1
1
 public function testGetDataWithContentTypeJsonWithInvalidSha()
 {
     $this->mockRequest->initialize(['test' => 1], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json', 'HTTP_QUICKPAY_CHECKSUM_SHA256' => '83ce13dffa6523334daa14f33d1fc2adc98ff8b57c4df5be5d2f58b1c2c78fa1e'], '[]');
     try {
         $this->request->getData();
         $this->fail('Expected an exception');
     } catch (InvalidResponseException $e) {
         $this->assertEquals('Invalid response from payment gateway', $e->getMessage());
     }
 }
コード例 #2
0
 public function testNoDispatch()
 {
     $this->mapping->setParameter('key');
     $this->request->initialize(array('key' => 'nomethodhere'));
     $this->action->execute($this->mapping, null, $this->request, $this->response);
     $this->assertNotEmpty($this->response->getContent());
     $this->assertEquals(500, $this->response->getStatusCode());
 }
コード例 #3
0
ファイル: APITest.php プロジェクト: aaronpk/Telegraph
 private function superfeedr_tracker($content, $args)
 {
     $request = new Request();
     $request->initialize([], [], [], [], [], [], $content);
     $response = new Response();
     return $this->client->superfeedr_tracker($request, $response, $args);
 }
コード例 #4
0
 protected function setUp()
 {
     $this->requestStack = new RequestStack();
     $request = new Request();
     $request->initialize(array('foobar' => 'bar'));
     $this->requestStack->push($request);
 }
コード例 #5
0
ファイル: Request.php プロジェクト: Jaymon/Montage
 /**
  *  do custom initialization stuff
  *
  *  @since  7-25-11
  *  @see  parent::initialize for params      
  */
 public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
 {
     $cli_query = null;
     if (!empty($server['argv'])) {
         $cli = $server['argv'];
         // in a real cli request, the 0 will be the script, in a http request, 0 will be the query string
         // but we only care about argv if it has more than the first item...
         if (isset($cli[1])) {
             $cli_query = new \ParseOpt($cli);
             // treat all the key/vals as query vars...
             if ($cli_query->hasFields()) {
                 $query = array_merge($query, $cli_query->getFields());
             }
             //if
         }
         //if
     }
     //if
     ///\out::e($query, $request, $attributes, $cookies, $files, $server, $content);
     parent::initialize($query, $request, $attributes, $cookies, $files, $server, $content);
     // treat any cli vals as appendages to the path...
     if (!empty($cli_query) && $cli_query->hasList()) {
         // this overrides automagic path finding...
         $this->pathInfo = join('/', $cli_query->getList());
     }
     //if
 }
コード例 #6
0
 public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
 {
     parent::initialize($query, $request, $attributes, $cookies, $files, $server, $content);
     $this->soapMessage = null;
     $this->soapHeaders = new Collection('getName');
     $this->soapAttachments = new Collection('getId');
     $this->setRequestFormat('soap');
 }
コード例 #7
0
ファイル: SoapFacade.php プロジェクト: niutech/SOA
 /**
  * Magic, do not touch. F*****g ugly but provides incredibly huge speedup :]
  * 
  * @param string $service
  * @param string $query
  * @param string $language
  * @return \stdClass 
  */
 private function _queryService($service, $query, $language)
 {
     $request = new Request();
     $request->initialize(array('query_string' => 'query=' . $query . '&lang=' . $language));
     $controllerName = '\\Service\\' . $service . '\\Controller\\SearchController';
     $controller = new $controllerName();
     return json_decode($controller->indexAction($request)->getContent());
 }
コード例 #8
0
 /**
  * @test
  */
 public function it_does_not_match_a_path_not_in_the_multi_path_configuration()
 {
     $nonMatchingRequest = new Request();
     $nonMatchingRequest->server->set('REQUEST_URI', '/incorrect/path');
     $nonMatchingRequest->initialize($nonMatchingRequest->query->all(), $nonMatchingRequest->request->all(), $nonMatchingRequest->attributes->all(), $nonMatchingRequest->cookies->all(), $nonMatchingRequest->files->all(), $nonMatchingRequest->server->all(), $nonMatchingRequest->getContent());
     $matches = $this->requestMatcher->matches($nonMatchingRequest);
     $this->assertFalse($matches);
 }
コード例 #9
0
ファイル: QueryDecoratorTest.php プロジェクト: niutech/SOA
 /**
  * @test 
  */
 public function decorateWithExtendedQuery()
 {
     $request = new Request();
     $request->initialize(array('query_string' => 'query=doesnt_matter'));
     $urlParamsMapper = new UrlParamsMapperInterfaceMock();
     $queryDecorator = new QueryDecorator(new QueryMock());
     $query = $queryDecorator->decorate($request, $urlParamsMapper);
     $this->assertEquals('q=label%3Aphp+sf', $query->encode());
 }
コード例 #10
0
 public function testShouldDetectAndroid()
 {
     $server = array('HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 2.1-update1; ja-jp; HTCX06HT Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17');
     $request = new Request();
     $request->initialize(array(), array(), array(), array(), array(), $server);
     $mobile = new Detector();
     $result = $mobile->detect($request);
     $this->assertEquals($result, 'iphone', '->detect() returns iphone');
 }
コード例 #11
0
ファイル: ManagerTest.php プロジェクト: niutech/SOA
 /**
  * @test 
  */
 public function getSearchResultsEmptyQuery()
 {
     $urlParamsMapper = new UrlParamsMapper();
     $request = new Request();
     $request->initialize(array($urlParamsMapper->getQueryParamName() => '', $urlParamsMapper->getLanguageParamName() => ''));
     $manager = new GithubManager($request);
     $resultSet = $manager->getSearchResults();
     $this->assertFalse($resultSet->success);
     $this->assertCount(0, $resultSet->results);
     $this->assertNull($resultSet->message);
 }
コード例 #12
0
ファイル: Request.php プロジェクト: phpffcms/ffcms-core
 /**
  * Sets the parameters for this request.
  *
  * This method also re-initializes all properties.
  *
  * @param array $query The GET parameters
  * @param array $request The POST parameters
  * @param array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
  * @param array $cookies The COOKIE parameters
  * @param array $files The FILES parameters
  * @param array $server The SERVER parameters
  * @param string $content The raw body data
  *
  * @api
  */
 public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
 {
     parent::initialize($query, $request, $attributes, $cookies, $files, $server, $content);
     $basePath = trim(App::$Properties->get('basePath'), '/');
     if ($basePath !== null && Str::length($basePath) > 0) {
         $basePath = '/' . $basePath;
     }
     if (!defined('env_no_uri') || env_no_uri === false) {
         $basePath .= '/' . strtolower(env_name);
     }
     // we never try to use path's without friendly url's
     $this->basePath = $this->baseUrl = $basePath;
 }
コード例 #13
0
ファイル: JsonRequest.php プロジェクト: erpframework/restapi
 /**
  * {@inheritdoc}
  *
  */
 public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null)
 {
     parent::initialize($query, $request, $attributes, $cookies, $files, $server, $content);
     $vars_in_body = in_array($this->getMethod(), ['PUT', 'POST', 'PATCH', 'DELETE']);
     if (!$this->isJson() || !$vars_in_body) {
         return;
     }
     if (!($data = json_decode($this->getContent(), TRUE))) {
         return;
     }
     foreach ($data as $key => $value) {
         $this->request->set($key, $value);
     }
 }
コード例 #14
0
ファイル: ManagerTest.php プロジェクト: niutech/SOA
 /**
  * @test 
  */
 public function cacheWorksCorrectly()
 {
     $sha1 = sha1(mktime());
     $hash = md5('https://github.com/search?repo=&langOverride=&start_value=1&type=Code&q=' . $sha1 . '&language=php');
     $cacheFile = __DIR__ . '/../../../../../app/cache/servicecache/' . $hash;
     if (file_exists($cacheFile)) {
         unlink($cacheFile);
     }
     $request = new Request();
     $request->initialize(array('query_string' => 'query=' . $sha1 . '&lang=php'));
     $manager = new ManagerAbstractMock($request);
     $manager->getSearchResults();
     $cacheFileTime = filectime($cacheFile);
     sleep(1);
     $manager->getSearchResults();
     $this->assertEquals($cacheFileTime, filectime($cacheFile), 'File overwritten, problem with cache.');
 }
コード例 #15
0
ファイル: Request.php プロジェクト: vigourouxjulien/thelia
 /**
  * @
  * {@inheritdoc} Including Thelia request properties
  */
 public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null)
 {
     parent::initialize($query, $request, $attributes, $cookies, $files, $server, $content);
     $this->resolvedPathInfo = null;
 }
コード例 #16
0
 private function getRequestInstanceForClientIpTests($remoteAddr, $httpForwardedFor, $trustedProxies)
 {
     $request = new Request();
     $server = array('REMOTE_ADDR' => $remoteAddr);
     if (null !== $httpForwardedFor) {
         $server['HTTP_X_FORWARDED_FOR'] = $httpForwardedFor;
     }
     if ($trustedProxies) {
         Request::setTrustedProxies($trustedProxies);
     }
     $request->initialize(array(), array(), array(), array(), array(), $server);
     return $request;
 }
コード例 #17
0
ファイル: RequestTest.php プロジェクト: spf13/symfony
 /**
  * @covers Symfony\Component\HttpFoundation\Request::getHost
  */
 public function testGetHost()
 {
     $request = new Request();
     $request->initialize(array('foo' => 'bar'));
     $this->assertEquals('', $request->getHost(), '->getHost() return empty string if not initialized');
     $request->initialize(null, null, null, null, null, array('HTTP_HOST' => 'www.exemple.com'));
     $this->assertEquals('www.exemple.com', $request->getHost(), '->getHost() from Host Header');
     // Host header with port number.
     $request->initialize(null, null, null, null, null, array('HTTP_HOST' => 'www.exemple.com:8080'));
     $this->assertEquals('www.exemple.com', $request->getHost(), '->getHost() from Host Header with port number');
     // Server values.
     $request->initialize(null, null, null, null, null, array('SERVER_NAME' => 'www.exemple.com'));
     $this->assertEquals('www.exemple.com', $request->getHost(), '->getHost() from server name');
     // X_FORWARDED_HOST.
     $request->initialize(null, null, null, null, null, array('HTTP_X_FORWARDED_HOST' => 'www.exemple.com'));
     $this->assertEquals('www.exemple.com', $request->getHost(), '->getHost() from X_FORWARDED_HOST');
     // X_FORWARDED_HOST
     $request->initialize(null, null, null, null, null, array('HTTP_X_FORWARDED_HOST' => 'www.exemple.com, www.second.com'));
     $this->assertEquals('www.second.com', $request->getHost(), '->getHost() value from X_FORWARDED_HOST use last value');
     // X_FORWARDED_HOST with port number
     $request->initialize(null, null, null, null, null, array('HTTP_X_FORWARDED_HOST' => 'www.exemple.com, www.second.com:8080'));
     $this->assertEquals('www.second.com', $request->getHost(), '->getHost() value from X_FORWARDED_HOST with port number');
     $request->initialize(null, null, null, null, null, array('HTTP_HOST' => 'www.exemple.com', 'HTTP_X_FORWARDED_HOST' => 'www.forward.com'));
     $this->assertEquals('www.forward.com', $request->getHost(), '->getHost() value from X_FORWARDED_HOST has priority over Host');
     $request->initialize(null, null, null, null, null, array('SERVER_NAME' => 'www.exemple.com', 'HTTP_X_FORWARDED_HOST' => 'www.forward.com'));
     $this->assertEquals('www.forward.com', $request->getHost(), '->getHost() value from X_FORWARDED_HOST has priority over SERVER_NAME ');
     $request->initialize(null, null, null, null, null, array('SERVER_NAME' => 'www.exemple.com', 'HTTP_HOST' => 'www.host.com'));
     $this->assertEquals('www.host.com', $request->getHost(), '->getHost() value from Host header has priority over SERVER_NAME ');
 }
コード例 #18
0
 public function testGetPathInfo()
 {
     $request = new Request();
     $this->assertEquals('/', $request->getPathInfo());
     $server = array();
     $server['REQUEST_URI'] = '/path/info';
     $request->initialize(array(), array(), array(), array(), array(), $server);
     $this->assertEquals('/path/info', $request->getPathInfo());
     $server = array();
     $server['REQUEST_URI'] = '/path%20test/info';
     $request->initialize(array(), array(), array(), array(), array(), $server);
     $this->assertEquals('/path%20test/info', $request->getPathInfo());
 }
コード例 #19
0
ファイル: Silex.php プロジェクト: RETFU/RREST
 /**
  * {@inheritdoc}
  */
 public function setPayloadBodyValue($payloadBodyJSON)
 {
     //no better way to setContent of the Request
     $this->request->initialize($this->request->query->all(), $this->request->request->all(), $this->request->attributes->all(), $this->request->cookies->all(), $this->request->files->all(), $this->request->server->all(), $payloadBodyJSON);
 }
コード例 #20
0
ファイル: RequestTest.php プロジェクト: nacef/symfony
    public function testGetBasePath()
    {
        $request = new Request();
        $this->assertEquals('', $request->getBasePath());

        $server = array();
        $server['SCRIPT_FILENAME'] = '/some/where/index.php';
        $request->initialize(array(), array(), array(), array(), array(), $server);
        $this->assertEquals('', $request->getBasePath());

        $server = array();
        $server['SCRIPT_FILENAME'] = '/some/where/index.php';
        $server['SCRIPT_NAME'] = '/index.php';
        $request->initialize(array(), array(), array(), array(), array(), $server);

        $this->assertEquals('', $request->getBasePath());

        $server = array();
        $server['SCRIPT_FILENAME'] = '/some/where/index.php';
        $server['PHP_SELF'] = '/index.php';
        $request->initialize(array(), array(), array(), array(), array(), $server);

        $this->assertEquals('', $request->getBasePath());

        $server = array();
        $server['SCRIPT_FILENAME'] = '/some/where/index.php';
        $server['ORIG_SCRIPT_NAME'] = '/index.php';
        $request->initialize(array(), array(), array(), array(), array(), $server);

        $this->assertEquals('', $request->getBasePath());
    }
コード例 #21
0
 /**
  * Since the Request object is absent of APIs for modifying parts of the
  * request, we will need to run its iniitalize method to make it do it
  * itself. This will be done after a method plugin alters the server
  * attributes i.e. $request->server->set('REQUEST_URI', '/new/uri')
  *
  * I don't have a better solution that doesn't feel hacky.
  */
 private function reinitializeRequest(Request $request)
 {
     $request->initialize($request->query->all(), $request->request->all(), $request->attributes->all(), $request->cookies->all(), $request->files->all(), $request->server->all(), $request->getContent());
 }
コード例 #22
0
ファイル: Request.php プロジェクト: stopsopa/utils
 public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
 {
     parent::initialize($query, $request, $attributes, $cookies, $files, $server, $content);
     $this->json = new ParameterBag(Json::decode($this->getContent()) ?: array());
 }
コード例 #23
-1
ファイル: RequestTest.php プロジェクト: netixpro/symfony
 /**
  * @covers Symfony\Component\HttpFoundation\Request::initialize
  */
 public function testInitialize()
 {
     $request = new Request();
     $request->initialize(array('foo' => 'bar'));
     $this->assertEquals('bar', $request->query->get('foo'), '->initialize() takes an array of query parameters as its first argument');
     $request->initialize(null, array('foo' => 'bar'));
     $this->assertEquals('bar', $request->request->get('foo'), '->initialize() takes an array of request parameters as its second argument');
     $request->initialize(null, null, array('foo' => 'bar'));
     $this->assertEquals('bar', $request->attributes->get('foo'), '->initialize() takes an array of attributes as its thrid argument');
     $request->initialize(null, null, null, null, null, array('HTTP_FOO' => 'bar'));
     $this->assertEquals('bar', $request->headers->get('FOO'), '->initialize() takes an array of HTTP headers as its fourth argument');
 }