Created
December 24, 2019 23:03
-
-
Save devmsh/4a106d56d5f2f9158a93602c229d591a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class response { | |
| public $response = []; | |
| function __construct(){ | |
| $this->addNormalResponse(); | |
| return $this->response; | |
| } | |
| function data(){ | |
| $this->response[] = [ | |
| 'data' => ['array of data'] | |
| ]; | |
| return $this; | |
| } | |
| function addNormalResponse(){ | |
| $this->response[] = [ | |
| 'response' => true | |
| ]; | |
| } | |
| } | |
| // helper function | |
| function response(){ | |
| return new response(); | |
| } | |
| class Controller{ | |
| public function response(){ | |
| return response(); | |
| } | |
| public function responseWithData(){ | |
| return response()->data(); | |
| } | |
| } | |
| class Kernal{ | |
| public function execute($controller, $method){ | |
| $this->response(call_user_func([new $controller(),$method])); | |
| } | |
| public function response($data){ | |
| header('Content-Type: application/json'); | |
| echo json_encode($data); | |
| } | |
| }; | |
| $kernal = new Kernal(); | |
| $kernal->execute('Controller','response'); | |
| $kernal->execute('Controller','responseWithData'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment