diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2019-11-27 19:11:37 +0100 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2019-12-08 02:12:56 +0100 |
commit | 89742ecd5542c740f3625af76c843a7471dbe98a (patch) | |
tree | 71c0c78ceb6a3a24b63c51c94a655cf5b33dc044 /src/helpers.php | |
parent | be39c63f46562eea173747d80cd91ac81e0b8e09 (diff) |
Response: Added with and withInput methods and back/redirect functions
Diffstat (limited to 'src/helpers.php')
-rw-r--r-- | src/helpers.php | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/helpers.php b/src/helpers.php index de140c4e..7cb17ea9 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -4,6 +4,7 @@ use Engelsystem\Application; use Engelsystem\Config\Config; use Engelsystem\Helpers\Authenticator; use Engelsystem\Helpers\Translation\Translator; +use Engelsystem\Http\Redirector; use Engelsystem\Http\Request; use Engelsystem\Http\Response; use Engelsystem\Http\UrlGeneratorInterface; @@ -28,7 +29,7 @@ function app($id = null) /** * @return Authenticator */ -function auth() +function auth(): Authenticator { return app('authenticator'); } @@ -37,12 +38,25 @@ function auth() * @param string $path * @return string */ -function base_path($path = '') +function base_path($path = ''): string { return app('path') . (empty($path) ? '' : DIRECTORY_SEPARATOR . $path); } /** + * @param int $status + * @param array $headers + * @return Response + */ +function back($status = 302, $headers = []): Response +{ + /** @var Redirector $redirect */ + $redirect = app('redirect'); + + return $redirect->back($status, $headers); +} + +/** * Get or set config values * * @param string|array $key @@ -70,12 +84,26 @@ function config($key = null, $default = null) * @param string $path * @return string */ -function config_path($path = '') +function config_path($path = ''): string { return app('path.config') . (empty($path) ? '' : DIRECTORY_SEPARATOR . $path); } /** + * @param string $path + * @param int $status + * @param array $headers + * @return Response + */ +function redirect(string $path, $status = 302, $headers = []): Response +{ + /** @var Redirector $redirect */ + $redirect = app('redirect'); + + return $redirect->to($path, $status, $headers); +} + +/** * @param string $key * @param mixed $default * @return Request|mixed @@ -97,7 +125,7 @@ function request($key = null, $default = null) * @param array $headers * @return Response */ -function response($content = '', $status = 200, $headers = []) +function response($content = '', $status = 200, $headers = []): Response { /** @var Response $response */ $response = app('psr7.response'); @@ -155,7 +183,7 @@ function trans($key = null, $replace = []) * @param array $replace * @return string */ -function __($key, $replace = []) +function __($key, $replace = []): string { /** @var Translator $translator */ $translator = app('translator'); @@ -172,7 +200,7 @@ function __($key, $replace = []) * @param array $replace * @return string */ -function _e($key, $keyPlural, $number, $replace = []) +function _e($key, $keyPlural, $number, $replace = []): string { /** @var Translator $translator */ $translator = app('translator'); |