1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author : Korotkov Danila <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2018, Korotkov Danila |
8
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3.0 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Rudra\Traits; |
12
|
|
|
|
13
|
|
|
use Rudra\Interfaces\ContainerInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Trait ContainerTrait |
17
|
|
|
* @package Rudra\Container\Traits |
18
|
|
|
*/ |
19
|
|
|
trait ContainerTrait |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return mixed |
24
|
|
|
*/ |
25
|
|
|
public function validation() |
26
|
|
|
{ |
27
|
|
|
return $this->container()->get('validation'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param null $target |
|
|
|
|
32
|
|
|
* @return mixed |
33
|
|
|
*/ |
34
|
|
|
public function redirect($target = null) |
35
|
|
|
{ |
36
|
|
|
return isset($target) ? $this->container()->get('redirect')->run($target) : $this->container()->get('redirect'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param null $key |
|
|
|
|
41
|
|
|
* @return mixed |
42
|
|
|
*/ |
43
|
|
|
public function post($key = null) |
44
|
|
|
{ |
45
|
|
|
return $this->container()->getPost($key); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $object |
50
|
|
|
* @param null $params |
|
|
|
|
51
|
|
|
* @return mixed |
52
|
|
|
*/ |
53
|
|
|
public function new($object, $params = null) |
54
|
|
|
{ |
55
|
|
|
return $this->container()->new($object, $params); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $key |
60
|
|
|
* @param string|null $subKey |
61
|
|
|
*/ |
62
|
|
|
public function unsetSession(string $key, string $subKey = null) |
63
|
|
|
{ |
64
|
|
|
$this->container()->unsetSession($key, $subKey); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return mixed |
69
|
|
|
*/ |
70
|
|
|
public function pagination() |
71
|
|
|
{ |
72
|
|
|
return $this->container()->get('pagination'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param $value |
77
|
|
|
*/ |
78
|
|
|
public function setPagination($value): void |
79
|
|
|
{ |
80
|
|
|
$this->container()->set('pagination', new \Rudra\Pagination($value['id']), 'raw'); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $key |
86
|
|
|
* @param string $value |
87
|
|
|
* @param string|null $subKey |
88
|
|
|
*/ |
89
|
|
|
public function setSession(string $key, string $value, string $subKey = null): void |
90
|
|
|
{ |
91
|
|
|
$this->container()->setSession($key, $value, $subKey); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public function db() |
98
|
|
|
{ |
99
|
|
|
return $this->container()->get('db'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return mixed |
104
|
|
|
*/ |
105
|
|
|
abstract public function container(): ContainerInterface; |
106
|
|
|
} |
107
|
|
|
|