Completed
Push — menu-rebuild ( 161e9b )
by Arnaud
01:58
created

Site::offsetGet()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4222
c 0
b 0
f 0
cc 5
nc 5
nop 1
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Renderer;
10
11
use Cecil\Builder;
12
use Cecil\Collection\Page\Page;
13
14
/**
15
 * Class Site.
16
 */
17
class Site implements \ArrayAccess
18
{
19
    /**
20
     * Builder object.
21
     *
22
     * @var Builder
23
     */
24
    protected $builder;
25
    /**
26
     * Current language.
27
     *
28
     * @var string
29
     */
30
    protected $language;
31
32
    /**
33
     * Site constructor.
34
     *
35
     * @param Builder     $builder
36
     * @param string|null $language
37
     */
38
    public function __construct(Builder $builder, string $language = null)
39
    {
40
        $this->builder = $builder;
41
        $this->language = $language;
42
    }
43
44
    /**
45
     * Implement ArrayAccess.
46
     *
47
     * @param mixed $offset
48
     *
49
     * @return bool
50
     */
51
    public function offsetExists($offset)
52
    {
53
        return $this->builder->getConfig()->has($offset);
54
    }
55
56
    /**
57
     * Implement ArrayAccess.
58
     *
59
     * @param mixed $offset
60
     *
61
     * @return mixed|null
62
     */
63
    public function offsetGet($offset)
64
    {
65
        // special cases
66
        switch ($offset) {
67
            case 'menus':
68
                return $this->builder->getMenus();
69
            case 'taxonomies':
70
                return $this->builder->getTaxonomies();
71
            case 'language':
72
                return new Language($this->builder->getConfig(), $this->language);
73
            case 'data':
74
                return $this->builder->getData();
75
        }
76
77
        return $this->builder->getConfig()->get($offset, $this->language);
78
    }
79
80
    /**
81
     * Implement ArrayAccess.
82
     *
83
     * @param mixed $offset
84
     * @param mixed $value
85
     */
86
    public function offsetSet($offset, $value)
87
    {
88
    }
89
90
    /**
91
     * Implement ArrayAccess.
92
     *
93
     * @param mixed $offset
94
     */
95
    public function offsetUnset($offset)
96
    {
97
    }
98
99
    /**
100
     * All pages, filtered by published status.
101
     */
102
    public function getPages()
103
    {
104
        return $this->builder->getPages()->filter(function (Page $page) {
105
            return $page->getVariable('published');
106
        });
107
    }
108
109
    /**
110
     * Current time.
111
     */
112
    public function getTime()
113
    {
114
        return time();
115
    }
116
}
117