35 public function set(
string $key, $value) {
36 $val = \serialize ( $value );
37 $tmp =
"/tmp/$key." . \uniqid (
'',
true ) .
'.tmp';
38 \file_put_contents ( $tmp, $val, LOCK_EX );
39 \rename ( $tmp, $this->getFilename ( $key ) );
51 public function get(
string $key, $default =
null) {
52 $filename = $this->getFilename ( $key );
53 if (\file_exists ( $filename )) {
54 $f = \file_get_contents ( $filename );
55 $val = \unserialize ( $f );
57 return isset ( $val ) ? $val : $default;
60 public function start(
string $name =
null, $root =
null) {
62 if (! isset ( $root )) {
63 $this->folder = \ROOT . \DS . CacheManager::getCacheDirectory () . \DS .
'session' . \DS;
65 $this->folder = $root . \DS .
'session' . \DS;
67 if (isset ( $name )) {
68 $this->folder .= $name . \DS;
70 if (! UCookie::exists ( self::SESSION_ID )) {
71 $id = $this->generateId ();
72 UCookie::set ( self::SESSION_ID, $id );
75 $this->
id = UCookie::get ( self::SESSION_ID );
77 $this->verifyCsrf->start ();
78 UFileSystem::safeMkdir ( $this->folder . $this->
id . \DS );
99 if($deleteOldSession){
101 $this->start($this->name,\rtrim($this->folder,\DS .
'session' . \DS));
104 $newId=$this->generateId();
105 $this->verifyCsrf->clear();
106 UCookie::set ( self::SESSION_ID, $newId );
109 $this->verifyCsrf->start ();
110 return UFileSystem::xmove($this->folder . $oldId . \DS, $this->folder . $newId . \DS);