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


PHP Session::set方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Session\Session::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::set方法的具体用法?PHP Session::set怎么用?PHP Session::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Session\Session的用法示例。


在下文中一共展示了Session::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateFromTokenResponse

 /**
  * @param \EasyBib\OAuth2\Client\TokenResponse\TokenResponse $tokenResponse
  */
 public function updateFromTokenResponse(TokenResponse $tokenResponse)
 {
     // don't use replace(), as that resets first and then sets
     $this->session->set(self::KEY_ACCESS_TOKEN, $tokenResponse->getToken());
     $this->session->set(self::KEY_REFRESH_TOKEN, $tokenResponse->getRefreshToken());
     $this->session->set(self::KEY_EXPIRES_AT, $this->expirationTimeFor($tokenResponse));
 }
开发者ID:easybiblabs,项目名称:oauth2-client-php,代码行数:10,代码来源:TokenStore.php

示例2: loginAction

 public function loginAction(Request $request)
 {
     // Récupération du login et mot de passe
     $login = $request->request->get("username");
     $pass = $request->request->get("password");
     if (!empty($login) && $login !== "" && !empty($pass) && $pass !== "") {
         //        $isConnected = AuthentificationLDAP::open($login, $pass);
         if (AuthentificationLDAP::open($login, $pass)) {
             AuthentificationLDAP::close();
             $session = new Session();
             // Rentre le nom d'utilisateur en session
             $session->set('username', $login);
             $session->set('password', $pass);
             // On recupère la promotion de l'étudiant qu'on met en session également
             $promotion = AuthentificationLDAP::getPromotion($login, $pass);
             $session->set('promotion', $promotion);
             // Ainsi qu'un boolean pour savoir si l'utilisateur est admin
             $isAdmin = AuthentificationLDAP::isAdmin($login, $pass);
             var_dump($isAdmin);
             if ($isAdmin) {
                 $session->set("admin", true);
             } else {
                 $session->set("admin", false);
             }
             $url = $this->generateUrl("glpmr_peripherique_gestion");
         } else {
             CustomError::showMessage("Identifiants incorrects");
             $url = $this->generateUrl("glpmr_authentification_homepage");
         }
     } else {
         CustomError::showMessage("Il faut renseigner tous les champs");
         $url = $this->generateUrl("glpmr_authentification_homepage");
     }
     return $this->redirect($url);
 }
开发者ID:JDemonchaux,项目名称:glpmr-portail,代码行数:35,代码来源:AuthentificationController.php

示例3: onInteractiveLogin

 /**
  * @param InteractiveLoginEvent $event
  */
 public function onInteractiveLogin(InteractiveLoginEvent $event)
 {
     $user = $event->getAuthenticationToken()->getUser();
     if (null !== $user->getLocale()) {
         $this->session->set('_locale', $user->getLocale());
     }
 }
开发者ID:blackbirdone,项目名称:training-schedulePHP,代码行数:10,代码来源:UserLocaleListener.php

示例4: setCart

 /**
  * @inheritdoc
  */
 public function setCart(Cart $cart)
 {
     $lineItems = $cart->getLineItems()->map(function (LineItem $lineItem) {
         return $lineItem->getQuantity()->getValue();
     });
     $this->session->set(self::NAME, $lineItems->toArray());
 }
开发者ID:igaponov,项目名称:shop,代码行数:10,代码来源:CartRepository.php

示例5: getCurrentSite

 public function getCurrentSite(Request $request)
 {
     $currentSite = null;
     $siteId = $request->get('site');
     if (!$siteId && $this->session->has(self::SESSION_NAME)) {
         $currentSiteId = $this->session->get(self::SESSION_NAME);
         $currentSite = $this->siteManager->find($currentSiteId);
         if (!$currentSite) {
             $sites = $this->getSites();
             if (count($sites) > 0) {
                 $currentSite = $this->getSites()[0];
             }
         }
     } else {
         foreach ($this->getSites() as $site) {
             if ($siteId && $site->getId() == $siteId) {
                 $currentSite = $site;
             } elseif (!$siteId && $site->getIsDefault()) {
                 $currentSite = $site;
             }
         }
         if (!$currentSite && count($this->sites) > 0) {
             $currentSite = $this->sites[0];
         }
     }
     if ($currentSite) {
         $this->session->set(self::SESSION_NAME, $currentSite->getId());
     }
     return $currentSite;
 }
开发者ID:symbio,项目名称:orangegate4-page-bundle,代码行数:30,代码来源:SitePool.php

示例6: getSessionToken

 /**
  * {@inheritdoc}
  */
 protected function getSessionToken()
 {
     if (!$this->session->has($this->name)) {
         $this->session->set($this->name, sha1(uniqid(rand(), true)));
     }
     return $this->session->get($this->name);
 }
开发者ID:jacobjjc,项目名称:PageKit-framework,代码行数:10,代码来源:SessionCsrfProvider.php

示例7: placeOrder

 /**
  * Place order and clear cart
  * @throws \Simplon\Mysql\MysqlException
  */
 public function placeOrder($billingStreet, $billingCity, $billingState, $billingZip, $shippingStreet, $shippingCity, $shippingState, $shippingZip, $email)
 {
     $query = '
         SELECT
           *
         FROM
           aca_cart_product
         WHERE
           cart_id= :cartId';
     // Get all user orders that are in the cart
     $data = $this->cart->getCart();
     // If there are products in the order
     if (!empty($data)) {
         // Add order to order table
         $orderId = $this->db->insert('aca_order', array('user_id' => $this->session->get('user_id'), 'billing_street' => $billingStreet, 'billing_city' => $billingCity, 'billing_state' => $billingState, 'billing_zip' => $billingZip, 'shipping_street' => $shippingStreet, 'shipping_city' => $shippingCity, 'shipping_state' => $shippingState, 'shipping_zip' => $shippingZip, 'email' => $email));
         // Iterate through products and add to order product table
         foreach ($data as $product) {
             $this->db->insert('aca_order_product', array('order_id' => $orderId, 'product_id' => $product['cp_product_id'], 'quantity' => $product['cp_quantity'], 'price' => $product['cp_price']));
         }
         // Delete order from cart
         $this->cart->removeCart();
         // Add orderId to session
         $this->session->set('order_id', $orderId);
     }
 }
开发者ID:jorions,项目名称:acashop,代码行数:29,代码来源:OrderService.php

示例8: handleSessionValidation

 /**
  * @param \Symfony\Component\HttpFoundation\Session\Session $session
  */
 public function handleSessionValidation(SymfonySession $session)
 {
     $ip_address = new IPAddress($this->request->getClientIp());
     $request_ip = $ip_address->getIp(IPAddress::FORMAT_IP_STRING);
     $invalidate = false;
     $ip = $session->get('CLIENT_REMOTE_ADDR');
     $agent = $session->get('CLIENT_HTTP_USER_AGENT');
     $request_agent = $this->request->server->get('HTTP_USER_AGENT');
     // Validate the request IP
     if ($this->shouldCompareIP() && $ip && $ip != $request_ip) {
         if ($this->logger) {
             $this->logger->debug('Session Invalidated. Session IP "{session}" did not match provided IP "{client}".', array('session' => $ip, 'client' => $request_ip));
         }
         $invalidate = true;
     }
     // Validate the request user agent
     if ($this->shouldCompareAgent() && $agent && $agent != $request_agent) {
         if ($this->logger) {
             $this->logger->debug('Session Invalidated. Session user agent "{session}" did not match provided agent "{client}"', array('session' => $agent, 'client' => $request_agent));
         }
         $invalidate = true;
     }
     if ($invalidate) {
         $session->invalidate();
     } else {
         if (!$ip && $request_ip) {
             $session->set('CLIENT_REMOTE_ADDR', $request_ip);
         }
         if (!$agent && $request_agent) {
             $session->set('CLIENT_HTTP_USER_AGENT', $request_agent);
         }
     }
 }
开发者ID:digideskio,项目名称:concrete5,代码行数:36,代码来源:SessionValidator.php

示例9: write

 /**
  * Writes contents into storage/session
  *
  * @param mixed $contents
  *
  * @return void
  */
 public function write($contents)
 {
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     $this->session->set(self::SESSION_STO_KEY . '-' . $this->namespace, $contents);
 }
开发者ID:fwk,项目名称:security,代码行数:14,代码来源:SessionStorage.php

示例10: indexAction

 /**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     //start session
     $session = new Session(new PhpBridgeSessionStorage());
     $session->start();
     $session->set('date', time());
     //get products from DB
     $products = $this->getDoctrine()->getRepository('AppBundle:Cart')->findAll();
     //get session products
     $sessionProducts = $session->get('products');
     $productArray = null;
     //if post save to db && session
     if ($request->isMethod('post')) {
         $postProduct = [$request->request->get('product')];
         if (!empty($sessionProducts)) {
             $productArray = array_merge($sessionProducts, $postProduct);
         } else {
             $productArray = $postProduct;
         }
         $productArray = array_unique($productArray);
     }
     $session->set('products', $productArray);
     // this helps create cookie for session
     $session->save();
     return $this->render('default/index.html.twig', array('sessionProducts' => $productArray, 'products' => $products));
 }
开发者ID:grzegab,项目名称:cart,代码行数:29,代码来源:DefaultController.php

示例11: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $content = $response->getResponse();
     $resourceOwner = $response->getResourceOwner();
     try {
         $user = $this->loadUserByServiceAndId($resourceOwner->getName(), $content['id']);
         return $user;
     } catch (\Exception $e) {
         $name = $response->getRealName();
         $nameArray = explode(' ', $name, 2);
         $firstName = $response->getFirstName();
         $lastName = $response->getLastName();
         if (empty($firstName) || empty($lastName)) {
             if (array_key_exists(0, $nameArray)) {
                 $firstName = ucfirst(strtolower($nameArray[0]));
             }
             if (array_key_exists(1, $nameArray)) {
                 $lastName = ucfirst(strtolower($nameArray[1]));
             }
         }
         $user = array();
         $user['firstName'] = $firstName;
         $user['lastName'] = $lastName;
         $user['username'] = $this->createUsername($response->getNickname());
         $user['mail'] = $response->getEmail();
         $this->session->set('icap.oauth.user', $user);
         $resourceOwnerArray = array('name' => $resourceOwner->getName(), 'id' => $content['id']);
         $this->session->set('icap.oauth.resource_owner', $resourceOwnerArray);
         throw $e;
     }
 }
开发者ID:claroline,项目名称:distribution,代码行数:34,代码来源:OauthUserProvider.php

示例12: checkInAction

 /**
  * @Route("/checkIn", name="loginCheck")
  * @Template()
  */
 public function checkInAction()
 {
     if (isset($_GET['connectData'])) {
         //Jeżeli są dane, to loguje
         $wykop = $this->get('WykopApi');
         $connect_data = $wykop->handleConnectData();
         $session = new Session();
         $session->set('token', $connect_data['token']);
         $session->set('sign', $connect_data['sign']);
         $profile = $wykop->doRequest('profile/index/' . $connect_data['login']);
         if (!$wykop->isValid()) {
             throw new Exception($this->api->getError());
         } else {
             $answer = $wykop->doRequest('user/login', array('login' => $profile['login'], 'accountkey' => $session->get('token')));
             if (!$wykop->isValid()) {
                 throw new Exception($this->api->getError());
             }
             $roles = ['ROLE_USER_WYKOP'];
             if ($profile['login'] === 'anonim1133') {
                 $roles[] = 'ROLE_ADMIN';
             }
             $token = new UsernamePasswordToken($profile['login'], $answer['userkey'], 'wykop', $roles);
             $token->setAttribute('wykop_login', $profile['login']);
             $token->setAttribute('wykop_sex', $profile['sex']);
             $token->setAttribute('wykop_group', $profile['author_group']);
             $token->setAttribute('wykop_avatar', $profile['avatar_med']);
             $token->setAttribute('wykop_login_date', new \DateTime('now'));
             $this->get('security.token_storage')->setToken($token);
             $session->set('_security_main', serialize($token));
         }
     }
     return $this->redirect('/');
 }
开发者ID:anonim1133,项目名称:ruszdupe-web,代码行数:37,代码来源:AuthController.php

示例13: getUrl

 /**
  * @inheritdoc
  */
 public function getUrl(ResourceObjectInterface $resource)
 {
     $url = $this->getLocationConfig('url', $resource->getLocation(), $this->config);
     preg_match_all('/\\{(\\w+)\\}/', $url, $matches);
     $accessor = new PropertyAccessor();
     if (isset($matches[1])) {
         foreach ($matches[1] as $token) {
             if ($token === 'id') {
                 //when mapping information contains {id}
                 //for security reasons instead of set the real resource id
                 //set a random value and save in session with the real id
                 //the param converter resolve the real resource related for given hash
                 //and keep the resource private for non public access
                 $value = md5(mt_rand());
                 $this->session->set('_resource/' . $value, $resource->getId());
             } else {
                 if ($accessor->isReadable($resource, $token)) {
                     $value = $accessor->getValue($resource, $token);
                 } else {
                     $msg = sprintf('Invalid parameter "{%s}" in %s resource mapping.', $token, $resource->getLocation());
                     throw new \InvalidArgumentException($msg);
                 }
             }
             $url = str_replace("{{$token}}", $value, $url);
         }
     }
     return str_replace('//', '/', $url);
 }
开发者ID:rafrsr,项目名称:resource-bundle,代码行数:31,代码来源:LocalResourceResolver.php

示例14: setAuthenticated

 /**
  * Sets the authentication flag.
  *
  * @param bool $authenticated The authentication status
  */
 public function setAuthenticated($authenticated)
 {
     if (true === $authenticated) {
         $this->session->set('_auth_until', time() + $this->timeout);
     } else {
         $this->session->remove('_auth_until');
     }
 }
开发者ID:burguin,项目名称:test02,代码行数:13,代码来源:InstallToolUser.php

示例15: it_do_not_authenticate_channel_when_cookie_name_is_missing

 public function it_do_not_authenticate_channel_when_cookie_name_is_missing(Session $session, ParameterBag $cookies)
 {
     $session->getName()->shouldBeCalled()->willReturn('session');
     $cookies->get('session')->shouldBeCalled()->willReturn('invalid_channel');
     $session->set('socketId', 1)->shouldNotBeCalled();
     $session->set('channelName', 'new_channel')->shouldNotBeCalled();
     $this->authenticate(1, 'new_channel')->shouldReturn(false);
 }
开发者ID:pazjacket,项目名称:pborreli-_-composer-service,代码行数:8,代码来源:ChannelAuthenticatorSpec.php


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