summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Application.php25
-rw-r--r--src/Container/Container.php35
-rw-r--r--src/helpers.php8
3 files changed, 52 insertions, 16 deletions
diff --git a/src/Application.php b/src/Application.php
new file mode 100644
index 00000000..674b3869
--- /dev/null
+++ b/src/Application.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace Engelsystem;
+
+use Engelsystem\Container\Container;
+use Psr\Container\ContainerInterface;
+
+class Application extends Container
+{
+ public function __construct()
+ {
+ $this->registerBaseBindings();
+ }
+
+ protected function registerBaseBindings()
+ {
+ self::setInstance($this);
+ Container::setInstance($this);
+ $this->instance('app', $this);
+ $this->instance('container', $this);
+ $this->instance(Container::class, $this);
+ $this->instance(Application::class, $this);
+ $this->instance(ContainerInterface::class, $this);
+ }
+}
diff --git a/src/Container/Container.php b/src/Container/Container.php
index df2f92fe..9af5c1e6 100644
--- a/src/Container/Container.php
+++ b/src/Container/Container.php
@@ -49,6 +49,17 @@ class Container implements ContainerInterface
*/
public function instance($abstract, $instance)
{
+ $this->singleton($abstract, $instance);
+ }
+
+ /**
+ * Register a shared entry as singleton in the container
+ *
+ * @param string $abstract
+ * @param mixed $instance
+ */
+ public function singleton($abstract, $instance)
+ {
$this->instances[$abstract] = $instance;
}
@@ -69,9 +80,20 @@ class Container implements ContainerInterface
}
/**
+ * Resolve the requested object
+ *
+ * @param string $abstract
+ * @return mixed
+ */
+ protected function resolve($abstract)
+ {
+ return $this->instances[$abstract];
+ }
+
+ /**
* Get the globally available instance of the container
*
- * @return Container
+ * @return self
*/
public static function getInstance()
{
@@ -91,15 +113,4 @@ class Container implements ContainerInterface
{
static::$instance = $container;
}
-
- /**
- * Resolve the requested object
- *
- * @param string $abstract
- * @return mixed
- */
- protected function resolve($abstract)
- {
- return $this->instances[$abstract];
- }
}
diff --git a/src/helpers.php b/src/helpers.php
index 733b902d..b942068f 100644
--- a/src/helpers.php
+++ b/src/helpers.php
@@ -1,15 +1,15 @@
<?php
// Some useful functions
+use Engelsystem\Application;
use Engelsystem\Config\Config;
-use Engelsystem\Container\Container;
use Engelsystem\Http\Request;
use Engelsystem\Renderer\Renderer;
use Engelsystem\Routing\UrlGenerator;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
/**
- * Get the global container instance
+ * Get the global app instance
*
* @param string $id
* @return mixed
@@ -17,10 +17,10 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
function app($id = null)
{
if (is_null($id)) {
- return Container::getInstance();
+ return Application::getInstance();
}
- return Container::getInstance()->get($id);
+ return Application::getInstance()->get($id);
}
/**