forked from flojon/KoalaContentBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMercuryRegions.php
73 lines (60 loc) · 1.33 KB
/
MercuryRegions.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
<?php
/**
* Helper class to encapsulate Mercury Region data
*
* @author Jonas Flodén
*/
namespace Koala\ContentBundle;
class MercuryRegions implements \ArrayAccess, \Iterator
{
var $regions;
var $keys;
function __construct($regions)
{
$this->regions = $regions;
}
public function offsetExists($offset)
{
return isset($this->regions[$offset]);
}
public function offsetGet($offset)
{
$region = $this->regions[$offset];
switch ($region["type"]) {
case "image":
return $region['attributes']['src'];
default:
return $region['value'];
}
}
public function offsetSet($offset, $value)
{
$this->regions[$offset] = array('type'=>'simple', 'value'=>$value);
}
public function offsetUnset($offset)
{
unset($this->regions[$offset]);
}
public function rewind()
{
$this->keys = array_keys($this->regions);
reset($this->keys);
}
public function current()
{
$offset = current($this->keys);
return $this[$offset];
}
public function key()
{
return current($this->keys);
}
public function next()
{
next($this->keys);
}
public function valid()
{
return ($this->key() !== FALSE);
}
}