From beb1b41317c33a327e772636d278ce1f29f2f02b Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 22 Oct 2018 11:27:30 +0300 Subject: [PATCH] Added `Grav\Framework\DI\Container` class --- CHANGELOG.md | 1 + system/src/Grav/Common/Grav.php | 6 +++--- ...rInitEvent.php => RequestHandlerEvent.php} | 2 +- .../Common/Processors/RequestProcessor.php | 4 ++-- system/src/Grav/Framework/DI/Container.php | 20 +++++++++++++++++++ 5 files changed, 27 insertions(+), 6 deletions(-) rename system/src/Grav/Common/Processors/Events/{RequestHandlerInitEvent.php => RequestHandlerEvent.php} (93%) create mode 100644 system/src/Grav/Framework/DI/Container.php diff --git a/CHANGELOG.md b/CHANGELOG.md index d6e44a757..ff4a80078 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Added PSR-7 and PSR-15 classes * Added `RequestHandler` class * Added `Page::httpResponseCode()` and `Page::httpHeaders()` methods + * Added `Grav\Framework\DI\Container` class 1. [](#improved) * Added apcu autoloader optimization 1. [](#bugfix) diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 1cf93256d..551930b8d 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -29,11 +29,11 @@ use Grav\Common\Processors\SiteSetupProcessor; use Grav\Common\Processors\TasksProcessor; use Grav\Common\Processors\ThemesProcessor; use Grav\Common\Processors\TwigProcessor; +use Grav\Framework\DI\Container; use Grav\Framework\Psr7\Response; use Grav\Framework\RequestHandler\RequestHandler; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use RocketTheme\Toolbox\DI\Container; use RocketTheme\Toolbox\Event\Event; use RocketTheme\Toolbox\Event\EventDispatcher; @@ -140,7 +140,7 @@ class Grav extends Container */ public function process() { - $container = new \Pimple\Psr11\Container(new Container( + $container = new Container( [ 'siteSetupProcessor' => function () { return new SiteSetupProcessor($this); @@ -194,7 +194,7 @@ class Grav extends Container return new RenderProcessor($this); }, ] - )); + ); $default = function (ServerRequestInterface $request) { return new Response(404); diff --git a/system/src/Grav/Common/Processors/Events/RequestHandlerInitEvent.php b/system/src/Grav/Common/Processors/Events/RequestHandlerEvent.php similarity index 93% rename from system/src/Grav/Common/Processors/Events/RequestHandlerInitEvent.php rename to system/src/Grav/Common/Processors/Events/RequestHandlerEvent.php index 5fcd849af..824fb672a 100644 --- a/system/src/Grav/Common/Processors/Events/RequestHandlerInitEvent.php +++ b/system/src/Grav/Common/Processors/Events/RequestHandlerEvent.php @@ -13,7 +13,7 @@ use Grav\Framework\RequestHandler\RequestHandler; use Psr\Http\Server\MiddlewareInterface; use RocketTheme\Toolbox\Event\Event; -class RequestHandlerInitEvent extends Event +class RequestHandlerEvent extends Event { public function addMiddleware($name, MiddlewareInterface $middleware) { diff --git a/system/src/Grav/Common/Processors/RequestProcessor.php b/system/src/Grav/Common/Processors/RequestProcessor.php index 25f67d5c9..3608303af 100644 --- a/system/src/Grav/Common/Processors/RequestProcessor.php +++ b/system/src/Grav/Common/Processors/RequestProcessor.php @@ -9,11 +9,11 @@ namespace Grav\Common\Processors; +use Grav\Common\Processors\Events\RequestHandlerEvent; use Grav\Common\Uri; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; -use RocketTheme\Toolbox\Event\Event; class RequestProcessor extends ProcessorBase { @@ -28,7 +28,7 @@ class RequestProcessor extends ProcessorBase ->withAttribute('route', Uri::getCurrentRoute()) ->withAttribute('referrer', $this->container['uri']->referrer()); - $event = new Event(['handler' => $handler]); + $event = new RequestHandlerEvent(['handler' => $handler]); $this->container->fireEvent('onRequestHandlerInit', $event); $this->stopTimer(); diff --git a/system/src/Grav/Framework/DI/Container.php b/system/src/Grav/Framework/DI/Container.php new file mode 100644 index 000000000..ca187e1af --- /dev/null +++ b/system/src/Grav/Framework/DI/Container.php @@ -0,0 +1,20 @@ +offsetGet($id); + } + + public function has($id) + { + return $this->offsetExists($id); + } +} \ No newline at end of file