Several fixes
This commit is contained in:
parent
34c2939d14
commit
91d17f713a
4 changed files with 40 additions and 3 deletions
|
@ -5,7 +5,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"nikic/fast-route": "^1.2",
|
"nikic/fast-route": "^1.2",
|
||||||
"guzzlehttp/psr7": "^1.4",
|
"guzzlehttp/psr7": "^1.4",
|
||||||
"php-di/php-di": "^5.4"
|
"php-di/php-di": "^6"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
|
@ -86,14 +86,38 @@ class Context
|
||||||
$this->setResponse($fn($this->getResponse()));
|
$this->setResponse($fn($this->getResponse()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSetting($name, $default = null) {
|
public function getSetting($name, $default = null)
|
||||||
|
{
|
||||||
return $this->settings[$name] ?? $default;
|
return $this->settings[$name] ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getVar($name, $default = null) {
|
public function getVar($name, $default = null)
|
||||||
|
{
|
||||||
return $this->settings[$name] ?? $default;
|
return $this->settings[$name] ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getVars(): array
|
||||||
|
{
|
||||||
|
return $this->vars;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSettings(): array
|
||||||
|
{
|
||||||
|
return $this->settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redirect($to, $status = 302): void {
|
||||||
|
$this->withResponse(function (ResponseInterface $response) use ($to, $status) {
|
||||||
|
return $response->withStatus($status)->withHeader('Location', $to);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function __get($name)
|
public function __get($name)
|
||||||
{
|
{
|
||||||
return $this->context[$name];
|
return $this->context[$name];
|
||||||
|
|
|
@ -155,6 +155,8 @@ class Server
|
||||||
'request' => $context->getRequest(),
|
'request' => $context->getRequest(),
|
||||||
'response' => $context->getResponse(),
|
'response' => $context->getResponse(),
|
||||||
'context' => $context,
|
'context' => $context,
|
||||||
|
'vars' => $context->getVars(),
|
||||||
|
'settings' => $context->getSettings(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->normalizeResponse($output, $context);
|
$this->normalizeResponse($output, $context);
|
||||||
|
|
|
@ -2,9 +2,20 @@
|
||||||
|
|
||||||
namespace BitCommunism\Http;
|
namespace BitCommunism\Http;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
if (function_exists(__NAMESPACE__ . '\\handle')) {
|
if (function_exists(__NAMESPACE__ . '\\handle')) {
|
||||||
function handle($call, $settings = [])
|
function handle($call, $settings = [])
|
||||||
{
|
{
|
||||||
return new Handle($call, $settings);
|
return new Handle($call, $settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (function_exists(__NAMESPACE__ . '\\redirect')) {
|
||||||
|
function redirect($to, $status = 302)
|
||||||
|
{
|
||||||
|
return function (Context $c) use ($to, $status) {
|
||||||
|
$c->redirect($to, $status);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue