本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::initialize方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::initialize方法的具体用法?PHP Request::initialize怎么用?PHP Request::initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNoDispatch
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());
}
示例2: testGetDataWithContentTypeJsonWithInvalidSha
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());
}
}
示例3: testInitialize
/**
* @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');
}
示例4: initialize
/**
* 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
}
示例5: setUp
protected function setUp()
{
$this->requestStack = new RequestStack();
$request = new Request();
$request->initialize(array('foobar' => 'bar'));
$this->requestStack->push($request);
}
示例6: superfeedr_tracker
private function superfeedr_tracker($content, $args)
{
$request = new Request();
$request->initialize([], [], [], [], [], [], $content);
$response = new Response();
return $this->client->superfeedr_tracker($request, $response, $args);
}
示例7: initialize
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');
}
示例8: _queryService
/**
* Magic, do not touch. Fucking 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());
}
示例9: it_does_not_match_a_path_not_in_the_multi_path_configuration
/**
* @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);
}
示例10: decorateWithExtendedQuery
/**
* @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());
}
示例11: testShouldDetectAndroid
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');
}
示例12: getSearchResultsEmptyQuery
/**
* @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);
}
示例13: initialize
/**
* 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;
}
示例14: initialize
/**
* {@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);
}
}
示例15: cacheWorksCorrectly
/**
* @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.');
}