forked from vdrok/Basecamp-3-API-PHP-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StorageSession.php
91 lines (83 loc) · 1.58 KB
/
StorageSession.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Basecamp;
/**
* Class StorageSession.
*/
class StorageSession
{
/**
* Class constructor.
*/
public function __construct()
{
if (session_status() == PHP_SESSION_NONE) {
session_id('AtHe3hAtuB');
session_start();
}
}
/**
* Get stored info (ETag).
*
* @param $hash
*
* @return string
*/
public function get($hash)
{
return $_SESSION['basecamp'][$hash];
}
/**
* Save info (ETag).
*
* @param $hash
* @param $etag
*
* @return mixed
*/
public function put($hash, $etag)
{
$_SESSION['basecamp'][$hash] = $etag;
}
/**
* Delete info.
*
* @param $hash
*/
public function delete($hash)
{
unset($_SESSION['basecamp'][$hash]);
}
/**
* Delete all stored hashes.
*/
public function clear()
{
$_SESSION['basecamp'] = [];
}
/**
* Create hash.
*
* @param mixed
*
* @return string
*/
public function createHash()
{
$data = '';
$arg_list = func_get_args();
foreach ($arg_list as $arg) {
switch (gettype($arg)) {
case 'array':
$data .= serialize($arg);
break;
case 'array':
$data .= spl_object_hash($arg);
break;
default:
$data .= serialize($arg);
break;
}
}
return md5($data);
}
}