Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Modulus\Framework;

use Modulus\Http\Rest;
use Modulus\Http\Redirect;
use Modulus\Framework\Upstart;

class Response
{
/**
* Make application response
*
* @param Upstart $app
*/
public static function make(Upstart $app)
{
/**
* Get application response
*/
$response = $app->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 '';
}
}
26 changes: 23 additions & 3 deletions Upstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -69,6 +77,8 @@ public function boot(?bool $isConsole = false) : void
* it has started.
*/
Upstart::$isReady = true;

return $this;
}

/**
Expand Down Expand Up @@ -148,4 +158,14 @@ public function getRequest()
{
return $this->request;
}

/**
* Get application response
*
* @return mixed
*/
public function getResponse()
{
return $this->response;
}
}
22 changes: 1 addition & 21 deletions Upstart/SwishEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": [{
Expand Down