From 1def00f1295592c383e86e08b5a1584616a46bc8 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 1 Mar 2019 20:10:29 +0300 Subject: [PATCH] Flextype Slim Integration - next round of integration --- flextype/Cache.php | 2 +- flextype/bootstrap.php | 6 ++-- flextype/twig/EmitterTwigExtension.php | 2 +- flextype/twig/EntriesTwigExtension.php | 8 +---- flextype/twig/FlashTwigExtension.php | 49 ++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 flextype/twig/FlashTwigExtension.php diff --git a/flextype/Cache.php b/flextype/Cache.php index 29f0868a..604750b2 100755 --- a/flextype/Cache.php +++ b/flextype/Cache.php @@ -73,7 +73,7 @@ class Cache $this->driver = $this->getCacheDriver(); // Set the cache namespace to our unique key - $this->driver->setNamespace($this->$key); + $this->driver->setNamespace($this->key); } diff --git a/flextype/bootstrap.php b/flextype/bootstrap.php index 7554b238..7250c0b4 100755 --- a/flextype/bootstrap.php +++ b/flextype/bootstrap.php @@ -265,11 +265,11 @@ $flextype['view'] = function ($container) { // Add Entries Twig Extension $view->addExtension(new EntriesTwigExtension($container)); - // Add Registry Twig Extension - $view->addExtension(new RegistryTwigExtension()); + // Add Emitter Twig Extension + $view->addExtension(new EmitterTwigExtension($container)); // Add Emitter Twig Extension - $view->addExtension(new EmitterTwigExtension()); + $view->addExtension(new FlashTwigExtension($container)); return $view; }; diff --git a/flextype/twig/EmitterTwigExtension.php b/flextype/twig/EmitterTwigExtension.php index 7aa7638e..dc497471 100644 --- a/flextype/twig/EmitterTwigExtension.php +++ b/flextype/twig/EmitterTwigExtension.php @@ -27,6 +27,6 @@ class EmitterTwigExtension extends \Twig_Extension public function emit(string $event) { - return $this->flextype['emitter']->emit($event); + $this->flextype['emitter']->emit($event); } } diff --git a/flextype/twig/EntriesTwigExtension.php b/flextype/twig/EntriesTwigExtension.php index 333f14df..9ddf66b7 100644 --- a/flextype/twig/EntriesTwigExtension.php +++ b/flextype/twig/EntriesTwigExtension.php @@ -1,11 +1,5 @@ flextype = $flextype; + } + + /** + * Callback for twig. + * + * @return array + */ + public function getFunctions() : array + { + return [ + new \Twig_SimpleFunction('flash', [$this, 'getMessages']), + ]; + } + + /** + * Returns Flash messages; If key is provided then returns messages + * for that key. + * + * @param string $key + * @return array + */ + public function getMessages($key = null) : array + { + if (null !== $key) { + return $this->flextype['flash']->getMessage($key); + } + return $this->flextype['flash']->getMessages(); + } +}