blob: db9361919c708a0f4ea167db8377a9330de64ce5 (
plain)
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
|
<?php
/**
* Adapter to fake user_data property in UserManagement
*
* @author noack
* @license GPL2
*/
class UserDataAdapter implements ArrayAccess, Countable, IteratorAggregate
{
private $user;
public function __construct(User $user)
{
$this->user = $user;
}
/**
* @param string $offset
* @return string
*/
public function adaptOffset($offset)
{
$adapted = trim(mb_strstr($offset, '.'), '.');
return $adapted ?: $offset;
}
/**
* ArrayAccess: Check whether the given offset exists.
*/
public function offsetExists($offset)
{
return $this->user->offsetExists($this->adaptOffset($offset));
}
/**
* ArrayAccess: Get the value at the given offset.
*/
public function offsetGet($offset)
{
return $this->user->offsetGet($this->adaptOffset($offset));
}
/**
* ArrayAccess: Set the value at the given offset.
*/
public function offsetSet($offset, $value)
{
return $this->user->offsetSet($this->adaptOffset($offset), $value);
}
/**
* ArrayAccess: unset the value at the given offset.
*/
public function offsetUnset($offset)
{
return $this->user->offsetUnset($this->adaptOffset($offset));
}
/**
* @see Countable::count()
*/
public function count()
{
return $this->user->count();
}
/**
* @see IteratorAggregate::getIterator()
*/
public function getIterator()
{
return $this->user->getIterator();
}
/**
* @param array $data
* @param bool $reset
*/
public function setData($data, $reset = false)
{
$adapted_data = [];
foreach ($data as $k => $v) {
$adapted_data[$this->adaptOffset($k)] = $v;
}
$this->user->setData($adapted_data, $reset);
}
}
|