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


PHP Session\Session类代码示例

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


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

示例1: createFromGlobals

 /**
  * Create new Xerxes Request
  */
 public static function createFromGlobals(ControllerMap $controller_map)
 {
     $registry = Registry::getInstance();
     // reverse proxy
     if ($registry->getConfig("REVERSE_PROXIES", false)) {
         self::$trustProxy = true;
         self::$trustedProxies = explode(',', $registry->getConfig("REVERSE_PROXIES"));
     }
     // request
     $request = parent::createFromGlobals();
     // set cookie path and name
     $basepath = $request->getBasePath();
     $id = strtolower($basepath);
     $id = preg_replace('/\\//', '_', $id);
     $id = 'xerxessession_' . $id;
     $session_options = array('name' => $id, 'cookie_path' => $basepath == '' ? '/' : $basepath);
     $storage = new NativeSessionStorage($session_options);
     // session
     $session = new Session($storage);
     $session->start();
     // register these mo-fo's
     $request->setRegistry($registry);
     $request->setSession($session);
     $request->setControllerMap($controller_map);
     // do our special mapping
     $request->extractQueryParams();
     return $request;
 }
开发者ID:fresnostate-library,项目名称:xerxes,代码行数:31,代码来源:Request.php

示例2: __construct

 /**
  * @param Registry $doctrine
  * @param Session $session
  * @param Logger $logger
  * @param Parameters $parameters
  */
 public function __construct(Registry $doctrine, Session $session, Logger $logger, Parameters $parameters)
 {
     $this->doctrine = $doctrine;
     $this->session = $session;
     $this->logger = $logger;
     $this->parameters = $parameters;
     $fromRetriever = new PgRetriever($doctrine, $this->logger, $this->parameters->getManagerFrom());
     $fromRetriever->setIndexType(PgRetriever::INDEX_TYPE_NAME);
     $fromMassRetriever = new PgMassRetriever($doctrine, $this->logger, $this->parameters->getManagerFrom());
     $toRetriever = new PgRetriever($doctrine, $this->logger, $this->parameters->getManagerTo());
     $toRetriever->setIndexType(PgRetriever::INDEX_TYPE_NAME);
     $toMassRetriever = new PgMassRetriever($doctrine, $this->logger, $this->parameters->getManagerTo());
     $this->fromAnalyzer = new PgAnalyzer($this->logger, $fromRetriever, $fromMassRetriever);
     $this->toAnalyzer = new PgAnalyzer($this->logger, $toRetriever, $toMassRetriever);
     if ($this->session->has(SyncHandler::SESSION_FROM_KEY)) {
         $this->fromAnalyzer->setSchemas($this->session->get(SyncHandler::SESSION_FROM_KEY));
         $this->fromAnalyzer->initTables();
     } else {
         $this->fromAnalyzer->initSchemas();
         $this->fromAnalyzer->initSchemasElements();
         $this->fromAnalyzer->initCompareTableInfo();
         //$this->session->set(SyncHandler::SESSION_FROM_KEY, $this->fromAnalyzer->getSchemas());
     }
     if ($this->session->has(SyncHandler::SESSION_TO_KEY)) {
         $this->toAnalyzer->setSchemas($this->session->get(SyncHandler::SESSION_TO_KEY));
         $this->toAnalyzer->initTables();
     } else {
         $this->toAnalyzer->initSchemas();
         $this->toAnalyzer->initSchemasElements();
         $this->toAnalyzer->initCompareTableInfo();
         $this->toAnalyzer->initTables();
         //$this->session->set(SyncHandler::SESSION_TO_KEY, $this->toAnalyzer->getSchemas());
     }
 }
开发者ID:rombar3,项目名称:PgExplorer,代码行数:40,代码来源:CompareStructure.php

示例3: showAction

 /**
  * @Route("/units/{id}", name="unit_show")
  * @Template()
  */
 public function showAction($id)
 {
     $session = new Session();
     $array = array();
     $user = $session->get('user');
     if ($user) {
         $array['user'] = $user;
     }
     $request = $this->get('request');
     $p_researchers = $request->query->get('p_researcher');
     $p_projects = $request->query->get('p_project');
     $service = $this->get("unit.service");
     $researchers = $service->getInv($id, $p_researchers, 20);
     $projects = $service->getProjectsByUnit($id, $p_projects, 20);
     $c_researchers = $service->getAllInv($id);
     $c_projects = $service->getAllProjectsByUnit($id);
     $states = array();
     for ($i = 0; $i < count($projects); $i++) {
         if (!in_array($projects[$i]["cestado"], $states)) {
             $states[$projects[$i]["cestado"]] = $projects[$i]["estado"];
         }
     }
     $unit = $service->getInfoByUnit($id);
     //  var_dump($unit);
     $array['states'] = $states;
     $array['projects'] = $projects;
     $array['p_researcher'] = $p_researchers;
     $array['p_project'] = $p_projects;
     $array['c_researcher'] = ceil(count($c_researchers) / 20);
     $array['c_project'] = ceil(count($c_projects) / 20);
     $array['researchers'] = $researchers;
     $array['unit'] = $unit;
     return $array;
 }
开发者ID:kmachoCr,项目名称:Sigpro,代码行数:38,代码来源:UnitController.php

示例4: alertifyFilter

 /**
  * Alertify filter
  * @param TwigEnvironment $environment
  * @param Session         $session
  *
  * @return string
  */
 public function alertifyFilter($environment, Session $session)
 {
     $flashes = $session->getFlashBag()->all();
     $renders = array();
     foreach ($flashes as $type => $flash) {
         if ($type == "callback") {
             foreach ($flash as $key => $currentFlash) {
                 $currentFlash['body'] .= $environment->render('AvAlertifyBundle:Modal:callback.html.twig', $currentFlash);
                 $session->getFlashBag()->add($currentFlash['engine'], $currentFlash);
                 $renders[$type . $key] = $this->alertifyFilter($session);
             }
         } else {
             foreach ($flash as $key => $content) {
                 if (is_array($content)) {
                     $context = isset($content['context']) ? $content['context'] : null;
                     $defaultParameters = self::getDefaultParametersFromContext($context);
                     $parameters = array_merge($defaultParameters, $content);
                 } else {
                     $defaultParameters = self::getDefaultParametersFromContext(null);
                     $parameters = array_merge($defaultParameters, array('body' => $content));
                 }
                 $parameters['type'] = $type;
                 $renders[$type . $key] = $environment->render('AvAlertifyBundle:Modal:' . $parameters['engine'] . '.html.twig', $parameters);
             }
         }
     }
     return implode(' ', $renders);
 }
开发者ID:bestmodules,项目名称:alertify-bundle,代码行数:35,代码来源:AlertifyExtension.php

示例5: testImplicitGrant

 public function testImplicitGrant()
 {
     // Start session manually.
     $session = new Session(new MockFileSessionStorage());
     $session->start();
     // Query authorization endpoint with response_type = token.
     $parameters = array('response_type' => 'token', 'client_id' => 'http://democlient1.com/', 'redirect_uri' => 'http://democlient1.com/redirect_uri', 'scope' => 'demoscope1', 'state' => $session->getId());
     $server = array('PHP_AUTH_USER' => 'demousername1', 'PHP_AUTH_PW' => 'demopassword1');
     $client = $this->createClient();
     $crawler = $client->request('GET', '/api/oauth2/authorize', $parameters, array(), $server);
     $this->assertTrue($client->getResponse()->isRedirect());
     // Check basic auth response that can simply compare.
     $authResponse = Request::create($client->getResponse()->headers->get('Location'), 'GET');
     $this->assertEquals('http://democlient1.com/redirect_uri', $authResponse->getSchemeAndHttpHost() . $authResponse->getBaseUrl() . $authResponse->getPathInfo());
     // Check basic token response that can simply compare.
     $tokenResponse = $authResponse->query->all();
     $this->assertEquals('bearer', $tokenResponse['token_type']);
     $this->assertEquals('demoscope1', $tokenResponse['scope']);
     $this->assertEquals($session->getId(), $tokenResponse['state']);
     // Query debug endpoint with access_token.
     $parameters = array();
     $server = array('HTTP_Authorization' => implode(' ', array('Bearer', $tokenResponse['access_token'])));
     $client = $this->createClient();
     $crawler = $client->request('GET', '/api/oauth2/debug', $parameters, array(), $server);
     $debugResponse = json_decode($client->getResponse()->getContent(), true);
     $this->assertEquals('demousername1', $debugResponse['username']);
 }
开发者ID:rakesh-mohanta,项目名称:oauth2-symfony-bundle,代码行数:27,代码来源:OAuth2Test.php

示例6: getUserDataHeader

 public function getUserDataHeader(Session $session)
 {
     if (!$session->has('userId')) {
         return null;
     }
     return ['name' => $session->get('userName'), 'secondName' => $session->get('userSName'), 'role' => $session->get('userRole')];
 }
开发者ID:swnsma,项目名称:coursework3.1,代码行数:7,代码来源:BaseController.php

示例7: setUp

 public function setUp()
 {
     $this->numberOfPayloads = 5;
     $this->realDirectory = sys_get_temp_dir() . '/storage';
     $this->chunkDirectory = $this->realDirectory . '/' . $this->chunksKey;
     $this->tempDirectory = $this->realDirectory . '/' . $this->orphanageKey;
     $this->payloads = array();
     if (!$this->checkIfTempnameMatchesAfterCreation()) {
         $this->markTestSkipped('Temporary directories do not match');
     }
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     $filesystem->mkdir($this->realDirectory);
     $filesystem->mkdir($this->chunkDirectory);
     $filesystem->mkdir($this->tempDirectory);
     $adapter = new Adapter($this->realDirectory, true);
     $filesystem = new GaufretteFilesystem($adapter);
     $this->storage = new GaufretteStorage($filesystem, 100000);
     $chunkStorage = new GaufretteChunkStorage($filesystem, 100000, null, 'chunks');
     // create orphanage
     $session = new Session(new MockArraySessionStorage());
     $session->start();
     $config = array('directory' => 'orphanage');
     $this->orphanage = new GaufretteOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat');
     for ($i = 0; $i < $this->numberOfPayloads; $i++) {
         // create temporary file as if it was reassembled by the chunk manager
         $file = tempnam($this->chunkDirectory, 'uploader');
         $pointer = fopen($file, 'w+');
         fwrite($pointer, str_repeat('A', 1024), 1024);
         fclose($pointer);
         //gaufrette needs the key relative to it's root
         $fileKey = str_replace($this->realDirectory, '', $file);
         $this->payloads[] = new GaufretteFile(new File($fileKey, $filesystem), $filesystem);
     }
 }
开发者ID:lsv,项目名称:OneupUploaderBundle,代码行数:34,代码来源:GaufretteOrphanageStorageTest.php

示例8: initSession

function initSession()
{
    $storage = new NativeSessionStorage(['cookie_lifetime' => 3600, 'gc_probability' => 1, 'gc_divisor' => 1, 'gc_maxlifetime' => 10000], new NativeFileSessionHandler());
    $session = new Session($storage, new NamespacedAttributeBag());
    $session->start();
    return $session;
}
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:7,代码来源:init.php

示例9: 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

示例10: environmentSessionController

 public function environmentSessionController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $session = new Session();
     $environment = $session->get('environment');
     // Validar si hay un environment cargado a la session de usuario
     if (isset($environment)) {
         // Validar si el controller es una instacia de InitController
         if ($controller[0] instanceof InitController) {
             // ****** if auth
             // ****** redirect home
             // ****** no
             // ****** redirect login
             return;
         }
         return;
     } else {
         // NO exite un environment cargado
         // Validar si el controller NO es instacia de InitController
         if (!$controller[0] instanceof InitController) {
             //redireccion a init controller
             $redirectUrl = '/init';
             $event->setController(function () use($redirectUrl) {
                 return new RedirectResponse($redirectUrl);
             });
         } else {
             return;
         }
     }
 }
开发者ID:stzef,项目名称:siacolweb-servicio,代码行数:30,代码来源:EnvironmentListener.php

示例11: TableauAction

 /**
  * @Route("/ajax/tableau",name="ajaxtab")
  * @Template("coffreappBundle:Default:tableau.html.twig")
  */
 public function TableauAction()
 {
     $session = new Session();
     $em = $this->getDoctrine()->getManager();
     $entities = $em->getRepository('coffreappBundle:Ticket')->findBy(array('operateur' => $session->get('Codecaisse'), 'session' => $session->get('Session')), array('id' => "desc"));
     return array('entity' => $entities);
 }
开发者ID:Jrbebel,项目名称:GestionTitre,代码行数:11,代码来源:DefaultController.php

示例12: indexAction

 public function indexAction()
 {
     $login_session = $this->getRequest()->getSession();
     if (!$login_session) {
         $login_session = new Session();
     }
     $this->setConfig();
     // Is the user already logged in? Redirect user to the private page
     if ($login_session->has('username')) {
         // if logged in redirect to users page
         return $this->redirect($this->generateUrl('user_page'));
         //all Symfony versions
         // return $this->redirectToRoute('user_page'); // Symfony 2.6 and above
     }
     if ($this->getRequest()->request->has('submit')) {
         $login_success = $this->doLogin();
         if ($login_success) {
             return $this->redirect($this->generateUrl('user_page'));
             //all Symfony versions
         } else {
             $login_error = "The submitted login info is incorrect or you're not a Tux Coffee Corner user.";
         }
     }
     //render login-form
     return $this->render('TuxCoffeeCornerUserBundle::userLogin.html.php', array('login_error' => $login_error));
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:26,代码来源:LoginController.php

示例13: setUp

 /**
  * {@inheritDoc}
  */
 protected function setUp()
 {
     $session = new Session(new MockArraySessionStorage());
     $session->setId('12345');
     $this->tokenStorage = new TokenStorage();
     $this->generator = new UserSessionStorageKeyGenerator($this->tokenStorage, $session);
 }
开发者ID:alinnflorinn,项目名称:CraueFormFlowBundle,代码行数:10,代码来源:UserSessionStorageKeyGeneratorTest.php

示例14: createAction

 public function createAction($article_id, Request $request)
 {
     $repository = $this->getDoctrine()->getRepository('BlogArticlesBundle:Article');
     $query = $repository->createQueryBuilder('a')->where('a.isActive = 1')->where('a.id = :id')->setParameter('id', $article_id)->setMaxResults(1)->getQuery();
     $article = $query->getOneOrNullResult();
     if (!$article) {
         throw $this->createNotFoundException('The article does not exist');
     }
     $comment = new Comment();
     $form = $this->getForm($article_id, $comment);
     $form->handleRequest($request);
     $session = new Session();
     if ($request->isMethod('POST')) {
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $comment->setArticle($article);
             $comment->setIsActive(1);
             $comment->setCreatedAt(new \DateTime('now'));
             $em->persist($comment);
             $em->flush();
             $session->getFlashBag()->add('sucess', 'Save Done');
         } else {
             //                $errors = array();
             //                foreach ($form->getErrors(true , true) as $key => $error) {
             //                    $errors[] = $error->getMessage();
             //                }
             $session->getFlashBag()->add('error', 'All fileds required');
         }
     }
     return $this->redirect($this->generateUrl('BlogArticles_view', ['slug' => $article->getSlug()]) . '#comments');
 }
开发者ID:kamalsolimen,项目名称:symfony-blog,代码行数:31,代码来源:DefaultController.php

示例15: registerBag

 protected function registerBag(SymfonySession $session)
 {
     $bag = new AttributeBag('_' . self::BAG_NAME);
     $bag->setName(self::BAG_NAME);
     $session->registerBag($bag);
     $this->sessionBag = $session->getBag(self::BAG_NAME);
 }
开发者ID:keboola,项目名称:oauth-v2-bundle,代码行数:7,代码来源:SessionController.php


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