first commit
This commit is contained in:
30
Swoft_BackEndApi/app/Bean/ResponseBean.php
Normal file
30
Swoft_BackEndApi/app/Bean/ResponseBean.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Bean;
|
||||
use Exception;
|
||||
use Swoft\Bean\Annotation\Mapping\Bean;
|
||||
|
||||
/**
|
||||
* @Bean("ResponseBean")
|
||||
* @package App\Bean
|
||||
*/
|
||||
class ResponseBean {
|
||||
public function success($data = [], string $message = "") {
|
||||
$response = context()->getResponse();
|
||||
return $response->withData([
|
||||
'code' => 200,
|
||||
'result' => $data,
|
||||
'message' => $message
|
||||
]);
|
||||
}
|
||||
|
||||
public function fail($e) {
|
||||
$response = context()->getResponse();
|
||||
return $response->withData([
|
||||
'code' => $e->getCode(),
|
||||
'result' => null,
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user