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


PHP Request::hasSession方法代码示例

本文整理汇总了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());
 }
开发者ID:krisldz,项目名称:Gekosale2,代码行数:33,代码来源:RequestDataCollector.php

示例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);
 }
开发者ID:KasaiDot,项目名称:FoolFrame,代码行数:14,代码来源:Notices.php

示例3: getSessionName

 /**
  * {@inheritdoc}
  */
 public function getSessionName()
 {
     if (null !== $this->request && $this->request->hasSession()) {
         return $this->request->getSession()->getName();
     }
     return '';
 }
开发者ID:pguso,项目名称:WellCommerce,代码行数:10,代码来源:RequestHelper.php

示例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(),
        );
    }
开发者ID:Gregwar,项目名称:symfony,代码行数:33,代码来源:RequestDataCollector.php

示例5: getSessionName

 /**
  * {@inheritdoc}
  */
 public function getSessionName() : string
 {
     if (null !== $this->getCurrentRequest() && $this->request->hasSession()) {
         return $this->request->getSession()->getName();
     }
     return '';
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:10,代码来源:RequestHelper.php

示例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);
     }
 }
开发者ID:renyunhuang,项目名称:nodephp,代码行数:8,代码来源:SessionManger.php

示例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]);
     }
 }
开发者ID:ronnylt,项目名称:symfony,代码行数:61,代码来源:RequestDataCollector.php

示例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());
     }
 }
开发者ID:khelle,项目名称:EngiShop,代码行数:9,代码来源:ExceptionListener.php

示例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());
 }
开发者ID:nicodmf,项目名称:symfony,代码行数:9,代码来源:ContextListenerTest.php

示例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')));
 }
开发者ID:terretta,项目名称:gitki.php,代码行数:20,代码来源:DefaultController.php

示例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();
     }
 }
开发者ID:notbrain,项目名称:symfony,代码行数:14,代码来源:RequestListener.php

示例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;
 }
开发者ID:kejwmen,项目名称:WhoopsBundle,代码行数:20,代码来源:WhoopsHandler.php

示例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);
 }
开发者ID:foreverglory,项目名称:oauth-bundle,代码行数:21,代码来源:OAuthController.php

示例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());
     }
 }
开发者ID:nicodmf,项目名称:symfony,代码行数:7,代码来源:ExceptionListener.php

示例15: testHasSession

 public function testHasSession()
 {
     $request = new Request();
     $this->assertFalse($request->hasSession());
     $request->setSession(new Session(new MockArraySessionStorage()));
     $this->assertTrue($request->hasSession());
 }
开发者ID:vieiragabriel,项目名称:moodle-block_gchat,代码行数:7,代码来源:RequestTest.php


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