Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-rpc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-rpc
Commits
89d6c6d5
Commit
89d6c6d5
authored
Jan 18, 2020
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加通用方法
parent
5be98e14
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
+93
-0
functions.php
src/functions.php
+93
-0
No files found.
src/functions.php
View file @
89d6c6d5
<?php
use
Hyperf\HttpServer\Contract\RequestInterface
;
use
Hyperf\HttpServer\Contract\ResponseInterface
;
use
Hyperf\Utils\ApplicationContext
;
/**
* 容器实例
*/
if
(
!
function_exists
(
'container'
))
{
function
container
()
{
return
ApplicationContext
::
getContainer
();
}
}
/**
* redis 客户端实例
*/
if
(
!
function_exists
(
'redis'
))
{
function
redis
()
{
return
container
()
->
get
(
\Redis
::
class
);
}
}
if
(
!
function_exists
(
'request'
))
{
/**
* 请求实例
* @param array|string|null $key
* @param mixed $default
* @return RequestInterface|string|array|mixed
*/
function
request
(
$key
=
null
,
$default
=
null
)
{
if
(
is_null
(
$key
))
{
return
container
()
->
get
(
RequestInterface
::
class
);
}
if
(
is_array
(
$key
))
{
return
container
()
->
get
(
RequestInterface
::
class
)
->
inputs
(
$key
);
}
$value
=
container
()
->
get
(
RequestInterface
::
class
)
->
input
(
$key
);
return
is_null
(
$value
)
?
value
(
$default
)
:
$value
;
}
}
/**
* 响应实例
*/
if
(
!
function_exists
(
'response'
))
{
function
response
()
{
return
container
()
->
get
(
ResponseInterface
::
class
);
}
}
if
(
!
function_exists
(
'success'
))
{
/**
* 成功响应实例
* @param string $msg
* @param mixed $data
* @param int $code
* @return mixed
*/
function
success
(
$msg
=
''
,
$data
=
null
,
$code
=
200
)
{
return
response
()
->
json
([
'msg'
=>
$msg
,
'data'
=>
$data
,
'code'
=>
$code
]);
}
}
if
(
!
function_exists
(
'fail'
))
{
/**
* 失败响应实例
* @param string $msg
* @param mixed $data
* @param int $code
* @return mixed
*/
function
fail
(
$msg
=
''
,
$data
=
null
,
$code
=
400
)
{
return
response
()
->
json
([
'msg'
=>
$msg
,
'data'
=>
$data
,
'code'
=>
$code
]);
}
}
if
(
!
function_exists
(
'decimal_to_abc'
))
{
/**
* 数字转换对应26个字母
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment