Passed
Push — master ( 6ce97f...1fe2f9 )
by huang
05:13
created

helpers.php ➔ input()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
use FastD\Application;
10
use FastD\Config\Config;
11
use FastD\Http\JsonResponse;
12
use FastD\Http\Response;
13
use FastD\Model\Database;
14
use FastD\Model\Model;
15
use FastD\Model\ModelFactory;
16
use FastD\Packet\Swoole;
17
use FastD\Routing\RouteCollection;
18
use Monolog\Logger;
19
use Psr\Http\Message\ServerRequestInterface;
20
use Symfony\Component\Cache\Adapter\AbstractAdapter;
21
use Symfony\Component\Console\Input\InputInterface;
22
use Symfony\Component\Console\Output\OutputInterface;
23
24
/**
25
 * @return Application
26
 */
27
function app()
28
{
29
    return Application::$app;
30
}
31
32
/**
33
 * @return string
34
 */
35
function version()
36
{
37
    return Application::VERSION;
38
}
39
40
/**
41
 * @return RouteCollection
42
 */
43
function route()
44
{
45
    return app()->get('router');
46
}
47
48
/**
49
 * @return Config
50
 */
51
function config()
52
{
53
    return app()->get('config');
54
}
55
56
/**
57
 * @return ServerRequestInterface
58
 */
59
function request()
60
{
61
    return app()->get('request');
62
}
63
64
/**
65
 * @return Response
66
 */
67
function response()
68
{
69
    return app()->get('response');
70
}
71
72
/**
73
 * @return \Exception
74
 */
75
function exception()
76
{
77
    return app()->get('exception');
78
}
79
80
/**
81
 * @param array $content
82
 * @param int   $statusCode
83
 *
84
 * @return Response
85
 */
86
function binary(array $content, $statusCode = Response::HTTP_OK)
87
{
88
    return new Response(Swoole::encode($content), $statusCode);
89
}
90
91
/**
92
 * @param array $content
93
 * @param int   $statusCode
94
 *
95
 * @return Response
96
 */
97
function json(array $content = [], $statusCode = Response::HTTP_OK)
98
{
99
    return new JsonResponse($content, $statusCode);
100
}
101
102
/**
103
 * @param $statusCode
104
 * @param $message
105
 *
106
 * @throws Exception
107
 */
108
function abort($statusCode, $message = null)
109
{
110
    throw new Exception((is_null($message) ? Response::$statusTexts[$statusCode] : $message), $statusCode);
111
}
112
113
/**
114
 * @return Logger
115
 */
116
function logger()
117
{
118
    return app()->get('logger');
119
}
120
121
/**
122
 * @param $key
123
 *
124
 * @return AbstractAdapter
125
 */
126
function cache($key = 'default')
127
{
128
    return app()->get('cache')->getCache($key);
129
}
130
131
/**
132
 * @param $key
133
 *
134
 * @return Database
135
 */
136
function database($key = 'default')
137
{
138
    return app()->get('database')->getConnection($key);
139
}
140
141
/**
142
 * @param $name
143
 * @param $key
144
 *
145
 * @return Model
146
 */
147
function model($name, $key = 'default')
148
{
149
    return ModelFactory::createModel($name, $key);
150
}
151
152
function client()
153
{
154
}
155
156
/**
157
 * @return \FastD\Swoole\Server
158
 */
159
function server()
160
{
161
    return app()->get('server');
162
}
163
164
function task()
165
{
166
}
167
168
/**
169
 * @return swoole_server
170
 */
171
function swoole()
172
{
173
    return server()->getSwoole();
174
}
175
176
/**
177
 * Get cli argvInput object.
178
 *
179
 * @return InputInterface
180
 */
181
function input()
182
{
183
    return app()->get('input');
184
}
185
186
/**
187
 * Get cli console output object.
188
 *
189
 * @return OutputInterface
190
 */
191
function output()
192
{
193
    return app()->get('output');
194
}
195