Skip to content

Instantly share code, notes, and snippets.

@devmsh
Created December 24, 2019 23:03
Show Gist options
  • Select an option

  • Save devmsh/4a106d56d5f2f9158a93602c229d591a to your computer and use it in GitHub Desktop.

Select an option

Save devmsh/4a106d56d5f2f9158a93602c229d591a to your computer and use it in GitHub Desktop.
<?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