2017-01-21 23:07:20 +01:00
|
|
|
<?php
|
|
|
|
// Some useful functions
|
|
|
|
|
|
|
|
use Engelsystem\Config\Config;
|
2017-08-31 17:30:54 +02:00
|
|
|
use Engelsystem\Container\Container;
|
2017-07-18 21:38:53 +02:00
|
|
|
use Engelsystem\Http\Request;
|
2017-07-20 02:22:18 +02:00
|
|
|
use Engelsystem\Renderer\Renderer;
|
2017-08-29 16:21:25 +02:00
|
|
|
use Engelsystem\Routing\UrlGenerator;
|
2017-08-30 19:57:01 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
2017-01-21 23:07:20 +01:00
|
|
|
|
2017-08-31 17:30:54 +02:00
|
|
|
/**
|
|
|
|
* Get the global container instance
|
|
|
|
*
|
|
|
|
* @param string $id
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function app($id = null)
|
|
|
|
{
|
|
|
|
if (is_null($id)) {
|
|
|
|
return Container::getInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Container::getInstance()->get($id);
|
|
|
|
}
|
|
|
|
|
2017-01-21 23:07:20 +01:00
|
|
|
/**
|
|
|
|
* Get or set config values
|
|
|
|
*
|
|
|
|
* @param string|array $key
|
|
|
|
* @param mixed $default
|
|
|
|
* @return mixed|Config
|
|
|
|
*/
|
|
|
|
function config($key = null, $default = null)
|
|
|
|
{
|
2017-08-31 17:30:54 +02:00
|
|
|
$config = app('config');
|
|
|
|
|
2017-01-21 23:07:20 +01:00
|
|
|
if (empty($key)) {
|
2017-08-31 17:30:54 +02:00
|
|
|
return $config;
|
2017-01-21 23:07:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($key)) {
|
2017-08-31 17:30:54 +02:00
|
|
|
$config->set($key);
|
|
|
|
return true;
|
2017-01-21 23:07:20 +01:00
|
|
|
}
|
|
|
|
|
2017-08-31 17:30:54 +02:00
|
|
|
return $config->get($key, $default);
|
2017-01-21 23:07:20 +01:00
|
|
|
}
|
2017-07-18 21:38:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $key
|
|
|
|
* @param mixed $default
|
|
|
|
* @return Request|mixed
|
|
|
|
*/
|
|
|
|
function request($key = null, $default = null)
|
|
|
|
{
|
2017-08-31 17:30:54 +02:00
|
|
|
$request = app('request');
|
2017-07-18 21:38:53 +02:00
|
|
|
|
|
|
|
if (is_null($key)) {
|
|
|
|
return $request;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $request->input($key, $default);
|
|
|
|
}
|
2017-07-20 02:22:18 +02:00
|
|
|
|
2017-08-30 19:57:01 +02:00
|
|
|
/**
|
|
|
|
* @param string $key
|
|
|
|
* @param mixed $default
|
|
|
|
* @return SessionInterface|mixed
|
|
|
|
*/
|
|
|
|
function session($key = null, $default = null)
|
|
|
|
{
|
|
|
|
$session = request()->getSession();
|
|
|
|
|
|
|
|
if (is_null($key)) {
|
|
|
|
return $session;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $session->get($key, $default);
|
|
|
|
}
|
|
|
|
|
2017-07-20 02:22:18 +02:00
|
|
|
/**
|
|
|
|
* @param string $template
|
|
|
|
* @param mixed[] $data
|
|
|
|
* @return Renderer|string
|
|
|
|
*/
|
|
|
|
function view($template = null, $data = null)
|
|
|
|
{
|
2017-08-31 17:30:54 +02:00
|
|
|
$renderer = app('renderer');
|
2017-07-20 02:22:18 +02:00
|
|
|
|
|
|
|
if (is_null($template)) {
|
|
|
|
return $renderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $renderer->render($template, $data);
|
|
|
|
}
|
2017-08-29 16:21:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $path
|
|
|
|
* @param array $parameters
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function url($path, $parameters = [])
|
|
|
|
{
|
|
|
|
return UrlGenerator::to($path, $parameters);
|
|
|
|
}
|