<commit_before><?php
/**
 * Created by PhpStorm.
 * User: daghostman
 * Date: 16/09/14
 * Time: 12:34
 */

namespace Wave\Framework\Storage;


use Wave\Framework\Decorator\Decoratable;

class Session extends Decoratable implements \ArrayAccess
{
    protected $sessionName = 'x_session_id';
    protected $uid = null;

    protected $storage = null;

    public function __construct($name = 'x_session_id')
    {
        $this->sessionName = $name;
        $cookie = new Cookie($this->sessionName);
        if (!$cookie->exists()) {
            $cookie->set(uniqid(null, true));
        }

        $this->storage = new Registry(array(
            'mutable' => true,
            'replace' => true
        ));
    }

    public function getId()
    {
        $cookie = new Cookie($this->sessionName);

        if (!$cookie->exists()) {
            throw new \LogicException("Session isn't instantiated properly.");
        }
        return $cookie->get();
    }<commit_msg>Added serialization by using Serialize and Unserialize Delegates<commit_after><?php
/**
 * Created by PhpStorm.
 * User: daghostman
 * Date: 16/09/14
 * Time: 12:34
 */

namespace Wave\Framework\Storage;


use Wave\Framework\Decorator\Decoratable;
use Wave\Framework\Decorator\Decorators\Serialize;
use Wave\Framework\Decorator\Decorators\Unserialize;

class Session extends Decoratable implements \ArrayAccess
{
    protected $sessionName = 'x_session_id';
    protected $uid = null;

    protected $storage = null;

    public function __construct($name = 'x_session_id')
    {
        $this->sessionName = $name;
        $cookie = new Cookie($this->sessionName);
        if (!$cookie->exists()) {
            $cookie->set(uniqid(null, true));
        }

        $this->commitDecorator = new Serialize();
        $this->rollbackDecorator = new Unserialize();

        $this->storage = new Registry(array(
            'mutable' => true,
            'replace' => true
        ));
    }

    public function getId()
    {
        $cookie = new Cookie($this->sessionName);

        if (!$cookie->exists()) {
            throw new \LogicException("Session isn't instantiated properly.");
        }
        return $cookie->get();
    }
{'fraction_non_alphanumeric': 0.1344232515894641, 'fraction_numerical': 0.009082652134423252, 'mean_word_length': 2.5248, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6330275', 'n_tokens_mistral': 674, 'n_tokens_neox': 636, 'n_words': 147}