summaryrefslogtreecommitdiff
path: root/src/helpers.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers.php')
-rw-r--r--src/helpers.php40
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');