1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-13 08:34:19 +02:00

Flextype Slim Integration - next round of integration

This commit is contained in:
Awilum
2019-03-01 20:10:29 +03:00
parent 3dab92a5c0
commit 1def00f129
5 changed files with 55 additions and 12 deletions

View File

@@ -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);
}

View File

@@ -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;
};

View File

@@ -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);
}
}

View File

@@ -1,11 +1,5 @@
<?php
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/slimphp/Twig-View
* @copyright Copyright (c) 2011-2015 Josh Lockhart
* @license https://github.com/slimphp/Twig-View/blob/master/LICENSE.md (MIT License)
*/
namespace Flextype;
class EntriesTwigExtension extends \Twig_Extension

View File

@@ -0,0 +1,49 @@
<?php
namespace Flextype;
use Slim\Flash\Messages;
class FlashTwigExtension extends \Twig_Extension
{
/**
* Flextype Dependency Container
*/
private $flextype;
/**
* Constructor.
*/
public function __construct($flextype)
{
$this->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();
}
}