Completed
Push — master ( 6e3c38...ba7825 )
by Korotkov
01:53
created

ContainerGlobalsTrait::setPost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Date: 06.04.17
7
 * Time: 15:00
8
 *
9
 * @author    : Korotkov Danila <[email protected]>
10
 * @copyright Copyright (c) 2016, Korotkov Danila
11
 * @license   http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
12
 */
13
14
namespace Rudra;
15
16
/**
17
 * Class ContainerFilesTrait
18
 *
19
 * @package Rudra
20
 */
21
trait ContainerGlobalsTrait
22
{
23
24
    /**
25
     * @var array
26
     */
27
    protected $get;
28
29
    /**
30
     * @var array
31
     */
32
    protected $post;
33
34
    /**
35
     * @var array
36
     */
37
    protected $server;
38
39
    /**
40
     * @var array
41
     */
42
    protected $files;
43
44
    /**
45
     * Container constructor.
46
     */
47
    protected function __construct()
48
    {
49
        $this->get    = $_GET;
50
        $this->post   = $_POST;
51
        $this->server = $_SERVER;
52
        $this->files  = $_FILES;
53
    }
54
55
    /**
56
     * @param string|null $key
57
     *
58
     * @return array|mixed
59
     */
60
    public function getGet(string $key = null)
61
    {
62
        return empty($key) ? $this->get : $this->get[$key];
63
    }
64
65
    /**
66
     * @param array $get
67
     */
68
    public function setGet(array $get): void
69
    {
70
        $this->get = $get;
71
    }
72
73
74
    /**
75
     * @param string $key
76
     *
77
     * @return bool
78
     */
79
    public function hasGet(string $key): bool
80
    {
81
        return isset($this->get[$key]);
82
    }
83
84
    /**
85
     * @param string|null $key
86
     *
87
     * @return array|mixed
88
     */
89
    public function getPost(string $key = null)
90
    {
91
        return empty($key) ? $this->post : $this->post[$key];
92
    }
93
94
    /**
95
     * @param array $post
96
     */
97
    public function setPost(array $post): void
98
    {
99
        $this->post = $post;
100
    }
101
102
    /**
103
     * @param string $key
104
     *
105
     * @return bool
106
     */
107
    public function hasPost(string $key): bool
108
    {
109
        return isset($this->post[$key]);
110
    }
111
112
    /**
113
     * @param string $key
114
     *
115
     * @return array|mixed|null
116
     */
117
    public function getServer(string $key)
118
    {
119
        return $this->server[$key] ?? null;
120
    }
121
122
    /**
123
     * @param array $server
124
     */
125
    public function setServer(array $server)
126
    {
127
        $this->server = $server;
128
    }
129
130
    /**
131
     * @param array $files
132
     */
133
    public function setFiles(array $files)
134
    {
135
        $this->files = $files;
136
    }
137
138
    /**
139
     * @param string $key
140
     * @param string $fieldName
141
     * @param string $formName
142
     *
143
     * @return string
144
     */
145
    public function getUpload(string $key, string $fieldName, string $formName = 'upload') : string
146
    {
147
        return $this->files[$formName][$fieldName][$key];
148
    }
149
150
    /**
151
     * @param string $value
152
     * @param string $formName
153
     *
154
     * @return bool
155
     */
156
    public function isUploaded(string $value, string $formName = 'upload') : bool
157
    {
158
        return ($this->files[$formName]['name'][$value] !== '');
159
    }
160
161
    /**
162
     * @param string $key
163
     * @param string $value
164
     *
165
     * @return bool
166
     */
167
    public function isFileType(string $key, string $value) : bool
168
    {
169
        return ($this->files['type'][$key] == $value) ? true : false;
170
    }
171
}