PHP Classes

File: src/Session.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Jaxon for Zend Framework   src/Session.php   Download  
File: src/Session.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Jaxon for Zend Framework
Zend plugin to call PHP classes from with AJAX
Author: By
Last change: Adapted to the new class hierarchy is jaxon-core.
Date: 2 years ago
Size: 2,821 bytes
 

Contents

Class file image Download
<?php

namespace Jaxon\Zend;

use
Jaxon\Contracts\Session as SessionContract;
use
Zend\Session\Container;

class
Session implements SessionContract
{
   
/**
     * The Zend Framework session
     *
     * @var object
     */
   
protected $xContainer = null;

    public function
__construct()
    {
       
$this->setContainerName('base');
    }

   
/**
     * Set the Zend Framework
     *
     * @param string $sKey The session key
     *
     * @return void
     */
   
public function setContainerName($sName)
    {
       
$this->xContainer = new Container($sName);
    }

   
/**
     * Get the current session id
     *
     * @return string The session id
     */
   
public function getId()
    {
        return
$this->xContainer->getManager()->getId();
    }

   
/**
     * Generate a new session id
     *
     * @param bool $bDeleteData Whether to delete data from the previous session
     *
     * @return void
     */
   
public function newId($bDeleteData = false)
    {
       
$this->xContainer->getManager()->regenerateId($bDeleteData);
    }

   
/**
     * Save data in the session
     *
     * @param string $sKey The session key
     * @param string $xValue The session value
     *
     * @return void
     */
   
public function set($sKey, $xValue)
    {
       
$this->xContainer->offsetSet($sKey, $xValue);
    }

   
/**
     * Check if a session key exists
     *
     * @param string $sKey The session key
     *
     * @return bool True if the session key exists, else false
     */
   
public function has($sKey)
    {
        return
$this->xContainer->offsetExists($sKey);
    }

   
/**
     * Get data from the session
     *
     * @param string $sKey The session key
     * @param string $xDefault The default value
     *
     * @return mixed|$xDefault The data under the session key, or the $xDefault parameter
     */
   
public function get($sKey, $xDefault = null)
    {
        return
$this->has($sKey) ? $this->xContainer->offsetGet($sKey) : $xDefault;
    }

   
/**
     * Get all data in the session
     *
     * @return array An array of all data in the session
     */
   
public function all()
    {
        return
$this->xContainer->getArrayCopy();
    }

   
/**
     * Delete a session key and its data
     *
     * @param string $sKey The session key
     *
     * @return void
     */
   
public function delete($sKey)
    {
       
$this->xContainer->offsetUnset($sKey);
    }

   
/**
     * Delete all data in the session
     *
     * @return void
     */
   
public function clear()
    {
       
$this->xContainer->exchangeArray([]);
    }
}