diff --git a/Response.php b/Response.php new file mode 100644 index 0000000..ffca26b --- /dev/null +++ b/Response.php @@ -0,0 +1,48 @@ +getResponse(); + + /** + * Create a rest response + */ + if ( + is_string($response) || + is_int($response) || + is_float($response) || + is_double($response) || + is_array($response) + ) return is_array($response) ? Rest::response()->json($response)->send() : Rest::response($response)->send(); + + if (is_bool($response)) return Rest::response($response ? 'true' : 'false')->send(); + + if ($response instanceof Rest) return $response->send(); + + /** + * Create a redirect + */ + if ($response instanceof Redirect) return $response->send(); + + /** + * Avoid "Segmentation fault (core dumped)" + */ + echo ''; + } +} diff --git a/Upstart.php b/Upstart.php index ae6ffaf..e4c4dbb 100644 --- a/Upstart.php +++ b/Upstart.php @@ -39,12 +39,20 @@ class Upstart */ protected $request; + /** + * $response + * + * @var mixed + */ + protected $response; + /** * Start application * - * @return void + * @param bool|null $isConsole + * @return Upstart $this */ - public function boot(?bool $isConsole = false) : void + public function boot(?bool $isConsole = false) : Upstart { /** * Add cors to the request @@ -55,7 +63,7 @@ public function boot(?bool $isConsole = false) : void * Don't load framework components, if * the application has already started. */ - if (Upstart::$isReady) return; + if (Upstart::$isReady) return $this; /** * Load application components @@ -69,6 +77,8 @@ public function boot(?bool $isConsole = false) : void * it has started. */ Upstart::$isReady = true; + + return $this; } /** @@ -148,4 +158,14 @@ public function getRequest() { return $this->request; } + + /** + * Get application response + * + * @return mixed + */ + public function getResponse() + { + return $this->response; + } } diff --git a/Upstart/SwishEvents.php b/Upstart/SwishEvents.php index d15f655..a7e6359 100644 --- a/Upstart/SwishEvents.php +++ b/Upstart/SwishEvents.php @@ -2,11 +2,9 @@ namespace Modulus\Framework\Upstart; -use Modulus\Http\Rest; use Modulus\Http\Status; use Modulus\Http\Request; use Modulus\Utility\View; -use Modulus\Http\Redirect; use Modulus\Utility\Events; use AtlantisPHP\Swish\Route; use Modulus\Utility\Reflect; @@ -112,24 +110,6 @@ private function swishView() */ private function handleResponse($response) { - /** - * Create a rest response - */ - if ( - is_string($response) || - is_int($response) || - is_float($response) || - is_double($response) || - is_array($response) - ) return is_array($response) ? Rest::response()->json($response)->send() : Rest::response($response)->send(); - - if (is_bool($response)) return Rest::response($response ? 'true' : 'false')->send(); - - if ($response instanceof Rest) return $response->send(); - - /** - * Create a redirect - */ - if ($response instanceof Redirect) return $response->send(); + $this->response = $response; } } diff --git a/composer.json b/composer.json index ffc157b..41d62e3 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "modulusphp/framework", "description": "Framework component for Modulus", - "version": "1.9.8.11", + "version": "1.9.9.0", "license": "MIT", "type": "package", "authors": [{