本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::hasSession方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::hasSession方法的具体用法?PHP Request::hasSession怎么用?PHP Request::hasSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::hasSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$responseHeaders = $response->headers->all();
$cookies = array();
foreach ($response->headers->getCookies() as $cookie) {
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
if (count($cookies) > 0) {
$responseHeaders['Set-Cookie'] = $cookies;
}
$attributes = array();
foreach ($request->attributes->all() as $key => $value) {
if (is_object($value)) {
$attributes[$key] = sprintf('Object(%s)', get_class($value));
if (is_callable(array($value, '__toString'))) {
$attributes[$key] .= sprintf(' = %s', (string) $value);
}
} else {
$attributes[$key] = $value;
}
}
$content = null;
try {
$content = $request->getContent();
} catch (\LogicException $e) {
// the user already got the request content as a resource
$content = false;
}
$this->data = array('format' => $request->getRequestFormat(), 'content' => $content, 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), 'request_headers' => $request->headers->all(), 'request_server' => $request->server->all(), 'request_cookies' => $request->cookies->all(), 'request_attributes' => $attributes, 'response_headers' => $responseHeaders, 'session_attributes' => $request->hasSession() ? $request->getSession()->all() : array(), 'flashes' => $request->hasSession() ? $request->getSession()->getFlashBag()->peekAll() : array(), 'path_info' => $request->getPathInfo());
}
示例2: setFlash
/**
* Sets a flash notice
*
* @param string $level The level of the message: success, warning, danger
* @param string $message The message
*/
public function setFlash($level, $message)
{
if (!$this->request->hasSession()) {
$this->request->setSession(new Session());
}
$this->flash_notices[] = ['level' => $level, 'message' => $message];
$this->request->getSession()->getFlashBag()->set('notice', $this->flash_notices);
}
示例3: getSessionName
/**
* {@inheritdoc}
*/
public function getSessionName()
{
if (null !== $this->request && $this->request->hasSession()) {
return $this->request->getSession()->getName();
}
return '';
}
示例4: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$responseHeaders = $response->headers->all();
$cookies = array();
foreach ($response->headers->getCookies() as $cookie) {
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpire(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
if (count($cookies) > 0) {
$responseHeaders['Set-Cookie'] = $cookies;
}
$attributes = array();
foreach ($request->attributes->all() as $key => $value) {
$attributes[$key] = is_object($value) ? sprintf('Object(%s)', get_class($value)) : $value;
}
$this->data = array(
'format' => $request->getRequestFormat(),
'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html',
'status_code' => $response->getStatusCode(),
'request_query' => $request->query->all(),
'request_request' => $request->request->all(),
'request_headers' => $request->headers->all(),
'request_server' => $request->server->all(),
'request_cookies' => $request->cookies->all(),
'request_attributes' => $attributes,
'response_headers' => $responseHeaders,
'session_attributes' => $request->hasSession() ? $request->getSession()->getAttributes() : array(),
);
}
示例5: getSessionName
/**
* {@inheritdoc}
*/
public function getSessionName() : string
{
if (null !== $this->getCurrentRequest() && $this->request->hasSession()) {
return $this->request->getSession()->getName();
}
return '';
}
示例6: _initNativeSession
public function _initNativeSession(Request $request)
{
if (!$request->hasSession()) {
$sesOption = array('cache_limiter' => 'nocache', 'cookie_domain' => 'localhost.com', 'cookie_httponly' => '1', 'cookie_lifetime' => '1800', 'cookie_path' => '/', 'cookie_secure' => '0', 'entropy_file' => '/dev/urandom', 'entropy_length' => '1024', 'gc_divisor' => '100', 'gc_maxlifetime' => '1800', 'gc_probability' => '100', 'hash_bits_per_character' => '4', 'hash_function' => '1', 'name' => 'NODEPHP', 'referer_check' => '', 'serialize_handler' => 'php', 'use_cookies' => '1', 'use_only_cookies' => '1', 'use_trans_sid' => '0', 'upload_progress.enabled' => '1', 'upload_progress.cleanup' => '1', 'upload_progress.prefix' => 'upload_progress_', 'upload_progress.name' => 'PHP_SESSION_UPLOAD_PROGRESS', 'upload_progress.freq' => '1%', 'upload_progress.min-freq' => '1', 'url_rewriter.tags' => 'a=href,area=href,frame=src,form=,fieldset=');
$session = new Session(new NativeSessionStorage($sesOption, new NativeFileSessionHandler('/tmp;/tmp'), new MetadataBag('nodephp_meta')), new AttributeBag('nodephp_attributes'), new FlashBag('nodephp_flashes'));
$request->setSession($session);
}
}
示例7: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$responseHeaders = $response->headers->all();
$cookies = array();
foreach ($response->headers->getCookies() as $cookie) {
$cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
if (count($cookies) > 0) {
$responseHeaders['Set-Cookie'] = $cookies;
}
$attributes = array();
foreach ($request->attributes->all() as $key => $value) {
if ('_route' == $key && is_object($value)) {
$value = $value->getPattern();
}
$attributes[$key] = $this->varToString($value);
}
$content = null;
try {
$content = $request->getContent();
} catch (\LogicException $e) {
// the user already got the request content as a resource
$content = false;
}
$sessionMetadata = array();
$sessionAttributes = array();
$flashes = array();
if ($request->hasSession()) {
$session = $request->getSession();
if ($session->isStarted()) {
$sessionMetadata['Created'] = date(DATE_RFC822, $session->getMetadataBag()->getCreated());
$sessionMetadata['Last used'] = date(DATE_RFC822, $session->getMetadataBag()->getLastUsed());
$sessionMetadata['Lifetime'] = $session->getMetadataBag()->getLifetime();
$sessionAttributes = $session->all();
$flashes = $session->getFlashBag()->peekAll();
}
}
$this->data = array('format' => $request->getRequestFormat(), 'content' => $content, 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), 'request_headers' => $request->headers->all(), 'request_server' => $request->server->all(), 'request_cookies' => $request->cookies->all(), 'request_attributes' => $attributes, 'response_headers' => $responseHeaders, 'session_metadata' => $sessionMetadata, 'session_attributes' => $sessionAttributes, 'flashes' => $flashes, 'path_info' => $request->getPathInfo(), 'controller' => 'n/a', 'locale' => $request->getLocale());
if (isset($this->controllers[$request])) {
$controller = $this->controllers[$request];
if (is_array($controller)) {
try {
$r = new \ReflectionMethod($controller[0], $controller[1]);
$this->data['controller'] = array('class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], 'method' => $controller[1], 'file' => $r->getFilename(), 'line' => $r->getStartLine());
} catch (\ReflectionException $re) {
if (is_callable($controller)) {
// using __call or __callStatic
$this->data['controller'] = array('class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], 'method' => $controller[1], 'file' => 'n/a', 'line' => 'n/a');
}
}
} elseif ($controller instanceof \Closure) {
$this->data['controller'] = 'Closure';
} else {
$this->data['controller'] = (string) $controller ?: 'n/a';
}
unset($this->controllers[$request]);
}
}
示例8: setTargetPath
protected function setTargetPath(Request $request)
{
if ($request->isXmlHttpRequest()) {
return;
}
if ($request->hasSession() && ($request->isMethodSafe() || $request->get('_route') == 'engishop_front_cart_add')) {
$request->getSession()->set('_security.' . $this->providerKey . '.target_path', $request->getUri());
}
}
示例9: testOnKernelResponseWithoutSession
public function testOnKernelResponseWithoutSession()
{
$this->securityContext->setToken(new UsernamePasswordToken('test1', 'pass1', 'phpunit'));
$request = new Request();
$event = new FilterResponseEvent($this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST, new Response());
$listener = new ContextListener($this->securityContext, array(), 'session');
$listener->onKernelResponse($event);
$this->assertFalse($request->hasSession());
}
示例10: loginAction
public function loginAction(Request $request)
{
if (!$this->hasRole('ROLE_USER')) {
if ($request->hasSession() && $request->isMethodSafe()) {
$referer = $request->headers->get('referer');
if (null !== $referer) {
$request->getSession()->set('ddr.gitki.manuallogin.targetpath', $referer);
}
}
throw new AuthenticationException();
}
if ($request->hasSession() && $request->isMethodSafe()) {
$targetPath = $request->getSession()->get('ddr.gitki.manuallogin.targetpath');
$request->getSession()->remove('ddr.gitki.manuallogin.targetpath');
if (null !== $targetPath) {
return $this->redirect($targetPath);
}
}
return $this->redirect($this->generateUrl('ddr_gitki_wiki_file', array('path' => '/index.md')));
}
示例11: initializeSession
protected function initializeSession(Request $request, $master)
{
if (!$master) {
return;
}
// inject the session object if none is present
if (null === $request->getSession()) {
$request->setSession($this->container->get('session'));
}
// starts the session if a session cookie already exists in the request...
if ($request->hasSession()) {
$request->getSession()->start();
}
}
示例12: handle
public function handle(Request $request, $statusCode)
{
$runner = new Run();
$format = $request->getRequestFormat();
if ('html' == $format) {
$handler = new PrettyPageHandler();
$handler->addDataTable('App', ['Controller' => $request->get('_controller'), 'Route' => $request->get('_route'), 'Session' => $request->hasSession(), 'Status' => $this->getCodeWithDescription($statusCode)]);
} else {
if ('json' == $format) {
$handler = new JsonResponseHandler();
} else {
$handler = new PlainTextHandler();
}
}
$runner->pushHandler($handler);
$runner->writeToOutput(false);
$runner->allowQuit(false);
$runner->register();
return $runner;
}
示例13: connectAction
public function connectAction(Request $request, $service)
{
$redirectUrl = $this->generateUrl('glory_oauth_callback', ['service' => $service], true);
$ownerMap = $this->get('glory_oauth.ownermap');
$owner = $ownerMap->getOwner($service);
$authorizationUrl = $owner->getAuthorizationUrl($redirectUrl, []);
// Check for a return path and store it before redirect
if ($request->hasSession()) {
$targetUrl = $request->get('target');
$targetUrl = $targetUrl ?: $request->headers->get('Referer');
if ($targetUrl) {
//todo: 这里还有一个可能
/*if(useForward){
}*/
$sessionKey = 'glory_oauth.target_path';
$request->getSession()->set($sessionKey, $targetUrl);
}
}
return $this->redirect($authorizationUrl);
}
示例14: setTargetPath
protected function setTargetPath(Request $request)
{
// session isn't required when using http basic authentication mechanism for example
if ($request->hasSession()) {
$request->getSession()->set('_security.target_path', $request->getUri());
}
}
示例15: testHasSession
public function testHasSession()
{
$request = new Request();
$this->assertFalse($request->hasSession());
$request->setSession(new Session(new MockArraySessionStorage()));
$this->assertTrue($request->hasSession());
}