<commit_before><?php

namespace tourze\Base\Component;

use tourze\Base\Base;
use tourze\Base\Component;
use tourze\Base\Helper\Arr;

/**
 * 会话处理组件
 *
 * @package tourze\Base\Component
 */
class Session extends Component
{

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();
        $this->start();
    }

    /**
     * 开始会话
     */
    public function start()
    {
        Base::getHttp()->sessionStart();
    }

    /**
     * 读取指定会话的值
     *
     * @param string $name
     * @param mixed  $default
     * @return mixed
     */
    public function get($name, $default = null)
    {
        return Arr::get($_SESSION, $name, $default);
    }

    /**
     * 设置会话值
     *
     * @param string $name
     * @param mixed  $value
     */
    public function set($name, $value)
    {
        $_SESSION[$name] = $value;
    }

    /**
     * 移除指定会话key
     *
     * @param string $name
     */
    public function remove($name)
    {
        unset($_SESSION[$name]);
    }

    /**
     * 清空会话数据
     *
     * @return bool
     */
    public function destroy()
    {
        return session_destroy();
    }
}<commit_msg>会话组件增加日志<commit_after><?php

namespace tourze\Base\Component;

use tourze\Base\Base;
use tourze\Base\Component;
use tourze\Base\Helper\Arr;

/**
 * 会话处理组件
 *
 * @package tourze\Base\Component
 */
class Session extends Component
{

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();
        $this->start();
    }

    /**
     * 开始会话
     */
    public function start()
    {
        Base::getLog()->info(__METHOD__ . ' session start');
        Base::getHttp()->sessionStart();
    }

    /**
     * 读取指定会话的值
     *
     * @param string $name
     * @param mixed  $default
     * @return mixed
     */
    public function get($name, $default = null)
    {
        Base::getLog()->info(__METHOD__ . ' get session', [
            'name'    => $name,
            'default' => $default,
        ]);
        return Arr::get($_SESSION, $name, $default);
    }

    /**
     * 设置会话值
     *
     * @param string $name
     * @param mixed  $value
     */
    public function set($name, $value)
    {
        Base::getLog()->info(__METHOD__ . ' set session', [
            'name'  => $name,
            'value' => $value,
        ]);
        $_SESSION[$name] = $value;
    }

    /**
     * 移除指定会话key
     *
     * @param string $name
     */
    public function remove($name)
    {
        Base::getLog()->info(__METHOD__ . ' remove session', [
            'name' => $name,
        ]);
        unset($_SESSION[$name]);
    }

    /**
     * 清空会话数据
     *
     * @return bool
     */
    public function destroy()
    {
        Base::getLog()->info(__METHOD__ . ' destroy session');
        return session_destroy();
    }
}
{'fraction_non_alphanumeric': 0.15606114468538926, 'fraction_numerical': 0.0, 'mean_word_length': 1.682554814108675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2068565', 'n_tokens_mistral': 941, 'n_tokens_neox': 957, 'n_words': 173}