diff --git a/README.md b/README.md index b44baee..fe72525 100644 --- a/README.md +++ b/README.md @@ -279,91 +279,6 @@ Visite [Twig Documentaion](http://twig.sensiolabs.org/documentation) for more ti * [jasny/twig-extensions](https://github.com/jasny/twig-extensions) * [twig/markdown-extra](https://github.com/twigphp/markdown-extra) -## Events ## - -This plugin emits several events. - -### Loaders ### - -The default loader can be replace by listening to the `Cake\TwigView\Event\LoaderEvent::EVENT`, for example with [twital](https://github.com/goetas/twital): - -```php - 'loader', - ConstructEvent::EVENT => 'construct', - ]; - } - - public function loader(LoaderEvent $event): void - { - $event->result = new TwitalLoader($event->getLoader()); - } - - /** - * We've also listening in on this event so we can add the needed extensions to check for to the view - */ - public function construct(ConstructEvent $event): void - { - $event->getTwigView()->unshiftExtension('.twital.html'); - $event->getTwigView()->unshiftExtension('.twital.xml'); - $event->getTwigView()->unshiftExtension('.twital.xhtml'); - } -} - - -``` - -### Extensions ### - -Extensions can be added to the twig environment by listening to the `Cake\TwigView\Event\ConstructEvent::EVENT`, for example: - -```php - 'construct', - ]; - } - - public function construct(ConstructEvent $event): void - { - $event->getTwig()->addExtension(new YourTwigExtension); - } -} - -``` - -## Bake - -You can use Bake to generate your basic CRUD views using the `theme` option. -Let's say you have a `TasksController` for which you want to generate twig templates. -You can use the following command to generate your index, add, edit and view file formatted -using Twig : - -```bash -bin/cake bake twig_template Tasks all -t Cake/TwigView -``` - -## Screenshots ## - ### Profiler ### ![Profiler](/docs/images/profiler.png) diff --git a/config/config.sample.php b/config/config.sample.php index 631c407..3c95dca 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -9,8 +9,5 @@ 'markdown' => [ 'engine' => 'engine', // See https://twig.symfony.com/doc/3.x/filters/markdown_to_html.html and then set to `new DefaultMarkdown()` ], - 'flags' => [ - 'potentialDangerous' => false, - ], ], ]; diff --git a/phpstan.neon b/phpstan.neon index f0a216c..887191a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,12 +8,12 @@ parameters: - message: "#^Parameter \\#2 \\$callable of class Twig\\\\TwigFilter constructor expects \\(callable\\(\\)\\: mixed\\)\\|null, 'debug' given\\.$#" count: 1 - path: src/Twig/Extension/Basic.php + path: src/Twig/Extension/BasicExtension.php - message: "#^Constant ROOT not found\\.$#" count: 2 - path: src/Twig/Extension/Profiler.php + path: src/Twig/Extension/ProfilerExtension.php - message: "#^Constant CACHE not found\\.$#" diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 44732ac..cd1e9a2 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,20 +1,13 @@ - - - Shell - parent::__construct($io, $locator) - parent::getOptionParser() - - - + parseExpression parseExpression parseExpression - + parseExpression parseExpression diff --git a/src/Event/ConstructEvent.php b/src/Event/ConstructEvent.php deleted file mode 100644 index 202882b..0000000 --- a/src/Event/ConstructEvent.php +++ /dev/null @@ -1,57 +0,0 @@ - $twigView, - 'twig' => $twig, - ]); - } - - /** - * @return \Cake\TwigView\View\TwigView - */ - public function getTwigView(): TwigView - { - return $this->getData()['twigView']; - } - - /** - * @return \Twig\Environment - */ - public function getTwig(): Environment - { - return $this->getData()['twig']; - } -} diff --git a/src/Event/EnvironmentConfigEvent.php b/src/Event/EnvironmentConfigEvent.php deleted file mode 100644 index 7b33723..0000000 --- a/src/Event/EnvironmentConfigEvent.php +++ /dev/null @@ -1,63 +0,0 @@ -setConfig($config); - - return $event; - } - - /** - * @return array - */ - public function getConfig(): array - { - return $this->config; - } - - /** - * @param array $config Config array - * @return $this - */ - public function setConfig(array $config) - { - /** @psalm-suppress PossiblyNullPropertyAssignmentValue */ - $this->config = array_replace_recursive($this->config, $config); - - return $this; - } -} diff --git a/src/Event/ExtensionsListener.php b/src/Event/ExtensionsListener.php deleted file mode 100644 index b8d8608..0000000 --- a/src/Event/ExtensionsListener.php +++ /dev/null @@ -1,132 +0,0 @@ - 'construct', - ]; - } - - /** - * Event handler. - * - * @param \Cake\TwigView\Event\ConstructEvent $event Event. - * @return void - */ - public function construct(ConstructEvent $event): void - { - if ($event->getTwig()->hasExtension(StringLoaderExtension::class)) { - return; - } - - // Twig core extensions - $event->getTwig()->addExtension(new StringLoaderExtension()); - $event->getTwig()->addExtension(new DebugExtension()); - - // CakePHP bridging extensions - $event->getTwig()->addExtension(new Extension\I18n()); - $event->getTwig()->addExtension(new Extension\Time()); - $event->getTwig()->addExtension(new Extension\Basic()); - $event->getTwig()->addExtension(new Extension\Number()); - $event->getTwig()->addExtension(new Extension\Utils()); - $event->getTwig()->addExtension(new Extension\Arrays()); - $event->getTwig()->addExtension(new Extension\Strings()); - $event->getTwig()->addExtension(new Extension\Inflector()); - - if ( - !Configure::check('TwigView.flags.potentialDangerous') || - ( - Configure::check('TwigView.flags.potentialDangerous') && - Configure::read('TwigView.flags.potentialDangerous') === true - ) - ) { - $event->getTwig()->addExtension(new Extension\PotentialDangerous()); - } - - // Markdown extension - if ( - Configure::check('TwigView.markdown.engine') && - Configure::read('TwigView.markdown.engine') instanceof MarkdownInterface - ) { - $engine = Configure::read('TwigView.markdown.engine'); - $event->getTwig()->addExtension(new MarkdownExtension()); - - $event->getTwig()->addRuntimeLoader(new class ($engine) implements RuntimeLoaderInterface { - /** - * @var \Twig\Extra\Markdown\MarkdownInterface - */ - private $engine; - - /** - * @param \Twig\Extra\Markdown\MarkdownInterface $engine MarkdownInterface instance - */ - public function __construct(MarkdownInterface $engine) - { - $this->engine = $engine; - } - - /** - * @param string $class FQCN - * @return object|null - */ - public function load($class) - { - if ($class === MarkdownRuntime::class) { - return new MarkdownRuntime($this->engine); - } - - return null; - } - }); - } - - // jasny/twig-extensions - $event->getTwig()->addExtension(new DateExtension()); - $event->getTwig()->addExtension(new PcreExtension()); - $event->getTwig()->addExtension(new TextExtension()); - $event->getTwig()->addExtension(new ArrayExtension()); - // @codingStandardsIgnoreEnd - } -} diff --git a/src/Event/LoaderEvent.php b/src/Event/LoaderEvent.php deleted file mode 100644 index 7953981..0000000 --- a/src/Event/LoaderEvent.php +++ /dev/null @@ -1,62 +0,0 @@ - $loader, - ]); - } - - /** - * @return \Twig\Loader\LoaderInterface - */ - public function getLoader(): LoaderInterface - { - return $this->getSubject(); - } - - /** - * @return \Twig\Loader\LoaderInterface - */ - public function getResultLoader(): LoaderInterface - { - if ($this->result instanceof LoaderInterface) { - return $this->result; - } - - if (is_array($this->result) && $this->result['loader'] instanceof LoaderInterface) { - return $this->result['loader']; - } - - return $this->getLoader(); - } -} diff --git a/src/Event/ProfileEvent.php b/src/Event/ProfileEvent.php deleted file mode 100644 index 99143f1..0000000 --- a/src/Event/ProfileEvent.php +++ /dev/null @@ -1,44 +0,0 @@ -getSubject(); - } -} diff --git a/src/Event/ProfilerListener.php b/src/Event/ProfilerListener.php deleted file mode 100644 index 85886b7..0000000 --- a/src/Event/ProfilerListener.php +++ /dev/null @@ -1,60 +0,0 @@ - 'construct', - ]; - } - - /** - * Event handler. - * - * @param \Cake\TwigView\Event\ConstructEvent $event Event. - * @return void - */ - public function construct(ConstructEvent $event): void - { - if ($event->getTwig()->hasExtension(Extension\Profiler::class)) { - return; - } - - $profile = new Profile(); - $event->getTwig()->addExtension(new Extension\Profiler($profile)); - - EventManager::instance()->dispatch(ProfileEvent::create($profile)); - } -} diff --git a/src/Event/TokenParsersListener.php b/src/Event/TokenParsersListener.php deleted file mode 100644 index 599c089..0000000 --- a/src/Event/TokenParsersListener.php +++ /dev/null @@ -1,58 +0,0 @@ - 'construct', - ]; - } - - /** - * Event handler. - * - * @param \Cake\TwigView\Event\ConstructEvent $event Event. - * @return void - */ - public function construct(ConstructEvent $event): void - { - // CakePHP specific tags - try { - $event->getTwig()->addTokenParser(new TokenParser\Cell()); - $event->getTwig()->addTokenParser(new TokenParser\Element()); - } catch (LogicException $d) { - // Nothing to do as token parser already added. - } - } -} diff --git a/src/Panel/TwigPanel.php b/src/Panel/TwigPanel.php index 484ff8e..6aa21dd 100644 --- a/src/Panel/TwigPanel.php +++ b/src/Panel/TwigPanel.php @@ -21,7 +21,7 @@ use Cake\TwigView\Filesystem\TreeScanner; use DebugKit\DebugPanel; -final class TwigPanel extends DebugPanel +class TwigPanel extends DebugPanel { /** * Plugin name. diff --git a/src/Plugin.php b/src/Plugin.php index 76cb12f..f39113b 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -23,7 +23,6 @@ use Cake\Core\Configure; use Cake\Core\Plugin as CorePlugin; use Cake\Core\PluginApplicationInterface; -use Cake\Event\EventManager; use Cake\TwigView\Command\CompileCommand; /** @@ -43,9 +42,6 @@ class Plugin extends BasePlugin */ public function bootstrap(PluginApplicationInterface $app): void { - EventManager::instance()->on(new Event\ExtensionsListener()); - EventManager::instance()->on(new Event\TokenParsersListener()); - if (Configure::read('debug') && CorePlugin::isLoaded('DebugKit')) { Configure::write('DebugKit.panels', array_merge( (array)Configure::read('DebugKit.panels'), @@ -53,7 +49,6 @@ public function bootstrap(PluginApplicationInterface $app): void 'Cake/TwigView.Twig', ] )); - EventManager::instance()->on(new Event\ProfilerListener()); } } diff --git a/src/Twig/Extension/Arrays.php b/src/Twig/Extension/ArraysExtension.php similarity index 93% rename from src/Twig/Extension/Arrays.php rename to src/Twig/Extension/ArraysExtension.php index 83eea05..c9e2b50 100644 --- a/src/Twig/Extension/Arrays.php +++ b/src/Twig/Extension/ArraysExtension.php @@ -22,11 +22,9 @@ use Twig\TwigFunction; /** - * Class Arrays. - * - * @internal + * Class ArraysExtension. */ -final class Arrays extends AbstractExtension +class ArraysExtension extends AbstractExtension { /** * Get declared functions. @@ -55,6 +53,6 @@ public function getFunctions(): array */ public function getName(): string { - return 'array'; + return 'twigview-array'; } } diff --git a/src/Twig/Extension/Basic.php b/src/Twig/Extension/BasicExtension.php similarity index 93% rename from src/Twig/Extension/Basic.php rename to src/Twig/Extension/BasicExtension.php index d188d89..b4cfecb 100644 --- a/src/Twig/Extension/Basic.php +++ b/src/Twig/Extension/BasicExtension.php @@ -22,11 +22,9 @@ use Twig\TwigFilter; /** - * Class Basic. - * - * @internal + * Class BasicExtension. */ -final class Basic extends AbstractExtension +class BasicExtension extends AbstractExtension { /** * Get declared filters. @@ -56,6 +54,6 @@ public function getFilters(): array */ public function getName(): string { - return 'basic'; + return 'twigview-basic'; } } diff --git a/src/Twig/Extension/PotentialDangerous.php b/src/Twig/Extension/ConfigureExtension.php similarity index 77% rename from src/Twig/Extension/PotentialDangerous.php rename to src/Twig/Extension/ConfigureExtension.php index 8904a61..75e8da9 100644 --- a/src/Twig/Extension/PotentialDangerous.php +++ b/src/Twig/Extension/ConfigureExtension.php @@ -19,28 +19,15 @@ namespace Cake\TwigView\Twig\Extension; use Twig\Extension\AbstractExtension; -use Twig\TwigFilter; use Twig\TwigFunction; /** - * Class Basic. + * Class ConfigureExtension. * * @internal */ -class PotentialDangerous extends AbstractExtension +class ConfigureExtension extends AbstractExtension { - /** - * Get declared filters. - * - * @return \Twig\TwigFilter[] - */ - public function getFilters() - { - return [ - new TwigFilter('env', 'env'), - ]; - } - /** * Get declared functions. * @@ -60,6 +47,6 @@ public function getFunctions() */ public function getName() { - return 'potential_dangerous'; + return 'twigview-configure'; } } diff --git a/src/Twig/Extension/I18n.php b/src/Twig/Extension/I18nExtension.php similarity index 92% rename from src/Twig/Extension/I18n.php rename to src/Twig/Extension/I18nExtension.php index a32b3d9..abcdedc 100644 --- a/src/Twig/Extension/I18n.php +++ b/src/Twig/Extension/I18nExtension.php @@ -22,11 +22,9 @@ use Twig\TwigFunction; /** - * Class I18n. - * - * @internal + * Class I18nExtension. */ -final class I18n extends AbstractExtension +class I18nExtension extends AbstractExtension { /** * Get declared functions. @@ -51,6 +49,6 @@ public function getFunctions(): array */ public function getName(): string { - return 'i18n'; + return 'twigview-i18n'; } } diff --git a/src/Twig/Extension/Inflector.php b/src/Twig/Extension/InflectorExtension.php similarity index 93% rename from src/Twig/Extension/Inflector.php rename to src/Twig/Extension/InflectorExtension.php index a405a1e..d79cd8a 100644 --- a/src/Twig/Extension/Inflector.php +++ b/src/Twig/Extension/InflectorExtension.php @@ -22,11 +22,9 @@ use Twig\TwigFilter; /** - * Class Inflector. - * - * @internal + * Class InflectorExtension. */ -final class Inflector extends AbstractExtension +class InflectorExtension extends AbstractExtension { /** * Get filters for this extension. @@ -56,6 +54,6 @@ public function getFilters(): array */ public function getName(): string { - return 'inflector'; + return 'twigview-inflector'; } } diff --git a/src/Twig/Extension/Number.php b/src/Twig/Extension/NumberExtension.php similarity index 94% rename from src/Twig/Extension/Number.php rename to src/Twig/Extension/NumberExtension.php index 3286807..eddeda5 100644 --- a/src/Twig/Extension/Number.php +++ b/src/Twig/Extension/NumberExtension.php @@ -23,11 +23,9 @@ use Twig\TwigFunction; /** - * Class Number. - * - * @internal + * Class NumberExtension. */ -final class Number extends AbstractExtension +class NumberExtension extends AbstractExtension { /** * Get declared functions. @@ -66,6 +64,6 @@ public function getFunctions(): array */ public function getName(): string { - return 'number'; + return 'twigview-number'; } } diff --git a/src/Twig/Extension/Profiler.php b/src/Twig/Extension/ProfilerExtension.php similarity index 90% rename from src/Twig/Extension/Profiler.php rename to src/Twig/Extension/ProfilerExtension.php index b612e62..73afdf5 100644 --- a/src/Twig/Extension/Profiler.php +++ b/src/Twig/Extension/ProfilerExtension.php @@ -19,15 +19,13 @@ namespace Cake\TwigView\Twig\Extension; use DebugKit\DebugTimer; -use Twig\Extension\ProfilerExtension; +use Twig\Extension\ProfilerExtension as TwigProfilerExtension; use Twig\Profiler\Profile; /** - * Class Basic. - * - * @internal + * Class ProfilerExtension. */ -final class Profiler extends ProfilerExtension +class ProfilerExtension extends TwigProfilerExtension { /** * Enter $profile. diff --git a/src/Twig/Extension/Strings.php b/src/Twig/Extension/StringsExtension.php similarity index 95% rename from src/Twig/Extension/Strings.php rename to src/Twig/Extension/StringsExtension.php index f10afe5..1dab5ed 100644 --- a/src/Twig/Extension/Strings.php +++ b/src/Twig/Extension/StringsExtension.php @@ -23,11 +23,9 @@ use Twig\TwigFunction; /** - * Class Strings. - * - * @internal + * Class StringsExtension. */ -final class Strings extends AbstractExtension +class StringsExtension extends AbstractExtension { /** * Get declared filters. @@ -79,6 +77,6 @@ public function getFunctions(): array */ public function getName(): string { - return 'string'; + return 'twigview-string'; } } diff --git a/src/Twig/Extension/Time.php b/src/Twig/Extension/TimeExtension.php similarity index 92% rename from src/Twig/Extension/Time.php rename to src/Twig/Extension/TimeExtension.php index bc7ee79..0502e59 100644 --- a/src/Twig/Extension/Time.php +++ b/src/Twig/Extension/TimeExtension.php @@ -23,11 +23,9 @@ use Twig\TwigFunction; /** - * Class Time. - * - * @internal + * Class TimeExtension. */ -final class Time extends AbstractExtension +class TimeExtension extends AbstractExtension { /** * Get declared functions. @@ -51,6 +49,6 @@ public function getFunctions(): array */ public function getName(): string { - return 'time'; + return 'twigview-time'; } } diff --git a/src/Twig/Extension/Utils.php b/src/Twig/Extension/UtilsExtension.php similarity index 93% rename from src/Twig/Extension/Utils.php rename to src/Twig/Extension/UtilsExtension.php index 6a59e15..e26cf35 100644 --- a/src/Twig/Extension/Utils.php +++ b/src/Twig/Extension/UtilsExtension.php @@ -22,11 +22,9 @@ use Twig\TwigFilter; /** - * Class Utils. - * - * @internal + * Class UtilsExtension. */ -final class Utils extends AbstractExtension +class UtilsExtension extends AbstractExtension { /** * Get declared filters. @@ -55,6 +53,6 @@ public function getFilters(): array */ public function getName(): string { - return 'utils'; + return 'twigview-utils'; } } diff --git a/src/Twig/Extension/View.php b/src/Twig/Extension/View.php deleted file mode 100644 index b4a110f..0000000 --- a/src/Twig/Extension/View.php +++ /dev/null @@ -1,78 +0,0 @@ -view = $view; - } - - /** - * Get declared functions. - * - * @return \Twig\TwigFunction[] - */ - public function getFunctions(): array - { - return [ - new TwigFunction('elementExists', function ($name) { - return $this->view->elementExists($name); - }), - new TwigFunction('getVars', function () { - return $this->view->getVars(); - }), - new TwigFunction('get', function ($var, $default = null) { - return $this->view->get($var, $default); - }), - ]; - } - - /** - * Get extension name. - * - * @return string - */ - public function getName(): string - { - return 'view'; - } -} diff --git a/src/Twig/Loader.php b/src/Twig/Loader.php index 721b2c2..66ff87c 100644 --- a/src/Twig/Loader.php +++ b/src/Twig/Loader.php @@ -30,7 +30,7 @@ * * @internal */ -final class Loader implements LoaderInterface +class Loader implements LoaderInterface { /** * Get the file contents of a template. diff --git a/src/Twig/Node/Cell.php b/src/Twig/Node/Cell.php index a00db87..599b38e 100644 --- a/src/Twig/Node/Cell.php +++ b/src/Twig/Node/Cell.php @@ -26,10 +26,8 @@ /** * Class Cell. - * - * @internal */ -final class Cell extends Node implements NodeOutputInterface +class Cell extends Node implements NodeOutputInterface { /** * Whether to assign the data or not. diff --git a/src/Twig/Node/Element.php b/src/Twig/Node/Element.php index 742d5c1..02e417d 100644 --- a/src/Twig/Node/Element.php +++ b/src/Twig/Node/Element.php @@ -25,10 +25,8 @@ /** * Class Element. - * - * @internal */ -final class Element extends Node +class Element extends Node { /** * Constructor. diff --git a/src/Twig/TokenParser/Cell.php b/src/Twig/TokenParser/CellParser.php similarity index 96% rename from src/Twig/TokenParser/Cell.php rename to src/Twig/TokenParser/CellParser.php index 5c17c44..d9a4ea5 100644 --- a/src/Twig/TokenParser/Cell.php +++ b/src/Twig/TokenParser/CellParser.php @@ -24,11 +24,9 @@ use Twig\TokenParser\IncludeTokenParser; /** - * Class Element. - * - * @internal + * Class CellParser. */ -final class Cell extends IncludeTokenParser +class CellParser extends IncludeTokenParser { /** * Parse token. diff --git a/src/Twig/TokenParser/Element.php b/src/Twig/TokenParser/ElementParser.php similarity index 95% rename from src/Twig/TokenParser/Element.php rename to src/Twig/TokenParser/ElementParser.php index 4be04b1..cbdfee2 100644 --- a/src/Twig/TokenParser/Element.php +++ b/src/Twig/TokenParser/ElementParser.php @@ -24,11 +24,9 @@ use Twig\TokenParser\IncludeTokenParser; /** - * Class Element. - * - * @internal + * Class ElementParser. */ -final class Element extends IncludeTokenParser +class ElementParser extends IncludeTokenParser { /** * Parse token. diff --git a/src/View/TwigView.php b/src/View/TwigView.php index 178594b..fdfffaf 100644 --- a/src/View/TwigView.php +++ b/src/View/TwigView.php @@ -19,14 +19,26 @@ namespace Cake\TwigView\View; use Cake\Core\Configure; -use Cake\TwigView\Event\ConstructEvent; -use Cake\TwigView\Event\EnvironmentConfigEvent; -use Cake\TwigView\Event\LoaderEvent; +use Cake\Core\Plugin; +use Cake\TwigView\Twig\Extension; use Cake\TwigView\Twig\Loader; +use Cake\TwigView\Twig\TokenParser; +use Cake\View\Exception\MissingLayoutException; +use Cake\View\Exception\MissingTemplateException; use Cake\View\View; -use Exception; +use Jasny\Twig\ArrayExtension; +use Jasny\Twig\DateExtension; +use Jasny\Twig\PcreExtension; +use Jasny\Twig\TextExtension; use Twig\Environment; +use Twig\Extension\DebugExtension; +use Twig\Extension\StringLoaderExtension; +use Twig\Extra\Markdown\MarkdownExtension; +use Twig\Extra\Markdown\MarkdownInterface; +use Twig\Extra\Markdown\MarkdownRuntime; use Twig\Loader\LoaderInterface; +use Twig\Profiler\Profile; +use Twig\RuntimeLoader\RuntimeLoaderInterface; /** * Class TwigView. @@ -38,27 +50,29 @@ class TwigView extends View public const ENV_CONFIG = 'TwigView.environment'; /** - * Extension to use. - * - * @var string + * @inheritDoc */ - protected $_ext = self::EXT; + protected $_ext = '.twig'; /** + * List of extensions searched when loading templates. + * * @var string[] */ protected $extensions = [ - self::EXT, - '.php', + '.twig', ]; /** - * Twig instance. - * * @var \Twig\Environment */ protected $twig; + /** + * @var \Twig\Profiler\Profile + */ + protected $profile; + /** * Return empty string when View instance is cast to string. * @@ -76,38 +90,53 @@ public function __toString(): string */ public function initialize(): void { - $this->twig = new Environment($this->getLoader(), $this->resolveConfig()); + parent::initialize(); - $this->getEventManager()->dispatch(ConstructEvent::create($this, $this->twig)); + $this->twig = new Environment($this->createLoader(), $this->createEnvironmentConfig()); + $this->initializeTokenParser(); + $this->initializeExtensions(); - $this->_ext = self::EXT; + if (Configure::read('debug') && Plugin::isLoaded('DebugKit')) { + $this->initializeProfiler(); + } + } - parent::initialize(); + /** + * Get Twig Environment instance. + * + * @return \Twig\Environment + */ + public function getTwig(): Environment + { + return $this->twig; } /** - * @param string $extension Extension. - * @return void + * Gets Twig Profile if profiler enabled. + * + * @return \Twig\Profiler\Profile */ - public function unshiftExtension(string $extension): void + public function getProfile(): Profile { - array_unshift($this->extensions, $extension); + return $this->profile; } /** - * Get twig environment instance. + * Creates the Twig LoaderInterface instance. * - * @return \Twig\Environment + * @return \Twig\Loader\LoaderInterface */ - public function getTwig(): Environment + protected function createLoader(): LoaderInterface { - return $this->twig; + return new Loader(); } /** + * Creates the Twig Environment configuration. + * * @return array */ - protected function resolveConfig(): array + protected function createEnvironmentConfig(): array { $debug = Configure::read('debug', false); @@ -122,110 +151,150 @@ protected function resolveConfig(): array $config['cache'] = CACHE . 'twigView' . DS; } - $configEvent = EnvironmentConfigEvent::create($config); - $this->getEventManager()->dispatch($configEvent); - - return $configEvent->getConfig(); + return $config; } /** - * Create the template loader. + * Adds custom Twig token parsers. * - * @return \Twig\Loader\LoaderInterface + * @return void */ - protected function getLoader(): LoaderInterface + protected function initializeTokenParser(): void { - $event = LoaderEvent::create(new Loader()); - $this->getEventManager()->dispatch($event); - - return $event->getResultLoader(); + $this->twig->addTokenParser(new TokenParser\CellParser()); + $this->twig->addTokenParser(new TokenParser\ElementParser()); } + // phpcs:disable CakePHP.Commenting.FunctionComment.InvalidReturnVoid + /** - * Render the template. + * Adds Twig extensions. * - * @param string $viewFile Template file. - * @param array $data Data that can be used by the template. - * @throws \Exception - * @return string + * @return void */ - protected function _render(string $viewFile, array $data = []): string + protected function initializeExtensions(): void { - if (empty($data)) { - $data = $this->viewVars; - } - - if (substr($viewFile, -3) === 'php') { - $out = parent::_render($viewFile, $data); - } else { - $data = array_merge( - $data, - iterator_to_array($this->helpers()->getIterator()), - [ - '_view' => $this, - ] - ); + // Twig core extensions + $this->twig->addExtension(new StringLoaderExtension()); + $this->twig->addExtension(new DebugExtension()); + + // CakePHP bridging extensions + $this->twig->addExtension(new Extension\ArraysExtension()); + $this->twig->addExtension(new Extension\BasicExtension()); + $this->twig->addExtension(new Extension\ConfigureExtension()); + $this->twig->addExtension(new Extension\I18nExtension()); + $this->twig->addExtension(new Extension\InflectorExtension()); + $this->twig->addExtension(new Extension\NumberExtension()); + $this->twig->addExtension(new Extension\StringsExtension()); + $this->twig->addExtension(new Extension\TimeExtension()); + $this->twig->addExtension(new Extension\UtilsExtension()); + + // Markdown extension + if (Configure::read('TwigView.markdown.engine') instanceof MarkdownInterface) { + $engine = Configure::read('TwigView.markdown.engine'); + $this->twig->addExtension(new MarkdownExtension()); + + $this->twig->addRuntimeLoader(new class ($engine) implements RuntimeLoaderInterface { + /** + * @var \Twig\Extra\Markdown\MarkdownInterface + */ + private $engine; + + /** + * @param \Twig\Extra\Markdown\MarkdownInterface $engine MarkdownInterface instance + */ + public function __construct(MarkdownInterface $engine) + { + $this->engine = $engine; + } - try { - $out = $this->getTwig()->load($viewFile)->render($data); - } catch (Exception $e) { - $previous = $e->getPrevious(); - - if ($previous !== null && $previous instanceof Exception) { - throw $previous; - } else { - throw $e; + /** + * @param string $class FQCN + * @return object|null + */ + public function load($class) + { + if ($class === MarkdownRuntime::class) { + return new MarkdownRuntime($this->engine); + } + + return null; } - } + }); } - return $out; + // jasny/twig-extensions + $this->twig->addExtension(new DateExtension()); + $this->twig->addExtension(new ArrayExtension()); + $this->twig->addExtension(new PcreExtension()); + $this->twig->addExtension(new TextExtension()); } + // phpcs:enable + /** - * @param string|null $name Template name. - * @throws \Exception - * @return string + * Initializes Twig profiler extension. + * + * @return void + */ + protected function initializeProfiler(): void + { + $this->profile = new Profile(); + $this->twig->addExtension(new Extension\ProfilerExtension($this->profile)); + } + + /** + * @inheritDoc + */ + protected function _render(string $templateFile, array $data = []): string + { + $data = array_merge( + empty($data) ? $this->viewVars : $data, + iterator_to_array($this->helpers()->getIterator()), + [ + '_view' => $this, + ] + ); + + return $this->getTwig()->load($templateFile)->render($data); + } + + /** + * @inheritDoc */ protected function _getTemplateFileName(?string $name = null): string { - $rethrow = new Exception('You\'re not supposed to get here'); foreach ($this->extensions as $extension) { $this->_ext = $extension; try { return parent::_getTemplateFileName($name); - } catch (Exception $exception) { - $rethrow = $exception; + } catch (MissingTemplateException $exception) { + $missingException = $exception; } } - throw $rethrow; + throw $missingException ?? new MissingTemplateException($name ?? $this->getTemplate()); } /** - * @param string|null $name Layout name. - * @throws \Exception - * @return string + * @inheritDoc */ protected function _getLayoutFileName(?string $name = null): string { - $rethrow = new Exception('You\'re not supposed to get here'); foreach ($this->extensions as $extension) { $this->_ext = $extension; try { return parent::_getLayoutFileName($name); - } catch (Exception $exception) { - $rethrow = $exception; + } catch (MissingLayoutException $exception) { + $missingException = $exception; } } - throw $rethrow; + throw $missingException ?? new MissingLayoutException($name ?? $this->getLayout()); } /** - * @param string $name Element name. - * @param bool $pluginCheck Whether to check within plugin. - * @return string|false + * @inheritDoc */ protected function _getElementFileName(string $name, bool $pluginCheck = true) { diff --git a/tests/TestCase/Command/CompileCommandTest.php b/tests/TestCase/Command/CompileCommandTest.php index 430fe4e..4adc438 100644 --- a/tests/TestCase/Command/CompileCommandTest.php +++ b/tests/TestCase/Command/CompileCommandTest.php @@ -71,10 +71,10 @@ public function testFileNoArgument() */ public function testFile() { - $this->exec('twig-view compile file ' . TEST_APP . DS . 'templates' . DS . 'layout.twig'); + $this->exec('twig-view compile file ' . TEST_APP . DS . 'templates' . DS . 'simple.twig'); $this->assertExitSuccess(); $this->assertOutputContains('Compiled'); - $this->assertOutputContains(TEST_APP . DS . 'templates' . DS . 'layout.twig'); + $this->assertOutputContains(TEST_APP . DS . 'templates' . DS . 'simple.twig'); } /** diff --git a/tests/TestCase/ConstructEventTest.php b/tests/TestCase/ConstructEventTest.php deleted file mode 100644 index 082e620..0000000 --- a/tests/TestCase/ConstructEventTest.php +++ /dev/null @@ -1,37 +0,0 @@ -prophesize(TwigView::class)->reveal(); - $twigEnvironment = $this->prophesize(Environment::class)->reveal(); - $event = ConstructEvent::create($twigView, $twigEnvironment); - - $this->assertEquals($twigView, $event->getTwigView()); - $this->assertEquals($twigEnvironment, $event->getTwig()); - } -} diff --git a/tests/TestCase/EnvironmentConfigEventTest.php b/tests/TestCase/EnvironmentConfigEventTest.php deleted file mode 100644 index 2e911aa..0000000 --- a/tests/TestCase/EnvironmentConfigEventTest.php +++ /dev/null @@ -1,60 +0,0 @@ - 'bar', - ]; - $event = EnvironmentConfigEvent::create($config); - $this->assertEquals($config, $event->getConfig()); - } - - public function testSetConfig() - { - $event = EnvironmentConfigEvent::create([ - 'foo' => 'bar', - 'beer' => 'crate', - 'baz' => [ - 'oof' => 'rab', - 'foo' => 'bar', - ], - ]); - $event->setConfig([ - 'foo' => 'rab', - 'baz' => [ - 'oof' => 'beer', - ], - ]); - $this->assertEquals([ - 'foo' => 'rab', - 'beer' => 'crate', - 'baz' => [ - 'oof' => 'beer', - 'foo' => 'bar', - ], - ], $event->getConfig()); - } -} diff --git a/tests/TestCase/ExtensionsListenerTest.php b/tests/TestCase/ExtensionsListenerTest.php deleted file mode 100644 index 2387c6c..0000000 --- a/tests/TestCase/ExtensionsListenerTest.php +++ /dev/null @@ -1,106 +0,0 @@ -implementedEvents(); - $this->assertIsArray($eventsList); - $this->assertSame(1, count($eventsList)); - } - - public function testConstruct() - { - $twig = $this->prophesize(Environment::class); - $twig->hasExtension(StringLoaderExtension::class)->shouldBeCalled(); - $twig->addExtension(Argument::type(AbstractExtension::class))->shouldBeCalled(); - - $twigView = new TwigView(); - (new ExtensionsListener())->construct(ConstructEvent::create($twigView, $twig->reveal())); - } - - public function testConstructMarkdownEngine() - { - Configure::write( - 'TwigView.markdown.engine', - $this->prophesize(MarkdownInterface::class)->reveal() - ); - - $twig = $this->prophesize(Environment::class); - $twig->hasExtension(StringLoaderExtension::class)->shouldBeCalled(); - $twig->addExtension(Argument::type(AbstractExtension::class))->shouldBeCalled(); - $twig->addExtension(Argument::type(MarkdownExtension::class))->shouldBeCalled(); - $twig->addRuntimeLoader(Argument::type('object'))->shouldBeCalled(); - - $twigView = new TwigView(); - (new ExtensionsListener())->construct(ConstructEvent::create($twigView, $twig->reveal())); - } - - public function testConstructNoMarkdownEngine() - { - $twig = $this->prophesize(Environment::class); - $twig->hasExtension(StringLoaderExtension::class)->shouldBeCalled(); - $twig->addExtension(Argument::type(AbstractExtension::class))->shouldBeCalled(); - $twig->addExtension(Argument::type(MarkdownExtension::class))->shouldNotBeCalled(); - - $twigView = new TwigView(); - (new ExtensionsListener())->construct(ConstructEvent::create($twigView, $twig->reveal())); - } - - public function testConstructDebug() - { - Configure::write('debug', true); - - $twig = $this->prophesize(Environment::class); - $twig->hasExtension(StringLoaderExtension::class)->shouldBeCalled(); - $twig->addExtension(Argument::type(AbstractExtension::class))->shouldBeCalled(); - - $twigView = new TwigView(); - (new ExtensionsListener())->construct(ConstructEvent::create($twigView, $twig->reveal())); - } - - public function testConstructDebugFalse() - { - Configure::write('debug', false); - - $twig = $this->prophesize(Environment::class); - $twig->hasExtension(StringLoaderExtension::class)->shouldBeCalled(); - $twig->addExtension(Argument::type(AbstractExtension::class))->shouldBeCalled(); - - $twigView = new TwigView(); - (new ExtensionsListener())->construct(ConstructEvent::create($twigView, $twig->reveal())); - } -} diff --git a/tests/TestCase/Filesystem/RelativeScannerTest.php b/tests/TestCase/Filesystem/RelativeScannerTest.php index 52b1b65..e746db6 100644 --- a/tests/TestCase/Filesystem/RelativeScannerTest.php +++ b/tests/TestCase/Filesystem/RelativeScannerTest.php @@ -47,10 +47,10 @@ public function testAll() $expected = [ 'APP' => [ 'Blog/index.twig', - 'element/element.twig', + 'element/blog_entry.twig', 'exception.twig', - 'layout.twig', - 'layout/layout.twig', + 'layout/default.twig', + 'simple.twig', 'syntaxerror.twig', ], 'TestTwigView' => [ diff --git a/tests/TestCase/Filesystem/ScannerTest.php b/tests/TestCase/Filesystem/ScannerTest.php index 23d3889..c7ea4da 100644 --- a/tests/TestCase/Filesystem/ScannerTest.php +++ b/tests/TestCase/Filesystem/ScannerTest.php @@ -47,10 +47,10 @@ public function testAll() $this->assertSame([ 'APP' => [ TEST_APP . 'templates' . DS . 'Blog' . DS . 'index.twig', - TEST_APP . 'templates' . DS . 'element' . DS . 'element.twig', + TEST_APP . 'templates' . DS . 'element' . DS . 'blog_entry.twig', TEST_APP . 'templates' . DS . 'exception.twig', - TEST_APP . 'templates' . DS . 'layout.twig', - TEST_APP . 'templates' . DS . 'layout' . DS . 'layout.twig', + TEST_APP . 'templates' . DS . 'layout' . DS . 'default.twig', + TEST_APP . 'templates' . DS . 'simple.twig', TEST_APP . 'templates' . DS . 'syntaxerror.twig', ], //'Bake' => Scanner::plugin('Bake'), diff --git a/tests/TestCase/Filesystem/TreeScannerTest.php b/tests/TestCase/Filesystem/TreeScannerTest.php index 9a9f9d0..a28d1c1 100644 --- a/tests/TestCase/Filesystem/TreeScannerTest.php +++ b/tests/TestCase/Filesystem/TreeScannerTest.php @@ -47,16 +47,16 @@ public function testAll() $this->assertEquals([ 'APP' => [ 2 => 'exception.twig', - 3 => 'layout.twig', + 4 => 'simple.twig', 5 => 'syntaxerror.twig', 'Blog' => [ 'index.twig', ], 'element' => [ - 'element.twig', + 'blog_entry.twig', ], 'layout' => [ - 'layout.twig', + 'default.twig', ], ], 'TestTwigView' => [ diff --git a/tests/TestCase/LoaderEventTest.php b/tests/TestCase/LoaderEventTest.php deleted file mode 100644 index 34dfcf6..0000000 --- a/tests/TestCase/LoaderEventTest.php +++ /dev/null @@ -1,54 +0,0 @@ -prophesize(LoaderInterface::class)->reveal(); - $event = LoaderEvent::create($loader); - $event->setResult([ - 'loader' => $loader2, - ]); - $this->assertEquals($loader2, $event->getResultLoader()); - } - - public function testResultLoader() - { - $loader = new Loader(); - $loader2 = $this->prophesize(LoaderInterface::class)->reveal(); - $event = LoaderEvent::create($loader); - $event->setResult($loader2); - $this->assertEquals($loader2, $event->getResultLoader()); - } - - public function testLoader() - { - $loader = new Loader(); - $event = LoaderEvent::create($loader); - $this->assertEquals($loader, $event->getResultLoader()); - } -} diff --git a/tests/TestCase/ProfilerListenerTest.php b/tests/TestCase/ProfilerListenerTest.php deleted file mode 100644 index 8fe2dbc..0000000 --- a/tests/TestCase/ProfilerListenerTest.php +++ /dev/null @@ -1,48 +0,0 @@ -implementedEvents(); - $this->assertIsArray($eventsList); - $this->assertSame(1, count($eventsList)); - } - - public function testConstruct() - { - $twig = $this->prophesize(Environment::class); - $twig->hasExtension(Profiler::class)->shouldBeCalled()->willReturn(true); - - $twigView = new TwigView(); - (new ProfilerListener())->construct(ConstructEvent::create($twigView, $twig->reveal())); - } -} diff --git a/tests/TestCase/TokenParsersListenerTest.php b/tests/TestCase/TokenParsersListenerTest.php deleted file mode 100644 index c9008e9..0000000 --- a/tests/TestCase/TokenParsersListenerTest.php +++ /dev/null @@ -1,49 +0,0 @@ -implementedEvents(); - $this->assertIsArray($eventsList); - $this->assertSame(1, count($eventsList)); - } - - public function testConstruct() - { - $twig = $this->prophesize(Environment::class); - $twig->addTokenParser(Argument::type(IncludeTokenParser::class))->shouldBeCalled(); - - $twigView = new TwigView(); - (new TokenParsersListener())->construct(ConstructEvent::create($twigView, $twig->reveal())); - } -} diff --git a/tests/TestCase/Twig/Extension/BasicTest.php b/tests/TestCase/Twig/Extension/BasicExtensionTest.php similarity index 92% rename from tests/TestCase/Twig/Extension/BasicTest.php rename to tests/TestCase/Twig/Extension/BasicExtensionTest.php index cc70a35..82adbd2 100644 --- a/tests/TestCase/Twig/Extension/BasicTest.php +++ b/tests/TestCase/Twig/Extension/BasicExtensionTest.php @@ -18,13 +18,13 @@ namespace Cake\TwigView\Test\TestCase\Twig\Extension; -use Cake\TwigView\Twig\Extension\Basic; +use Cake\TwigView\Twig\Extension\BasicExtension; -final class BasicTest extends AbstractExtensionTest +class BasicExtensionTest extends AbstractExtensionTest { public function setUp(): void { - $this->extension = new Basic(); + $this->extension = new BasicExtension(); parent::setUp(); } diff --git a/tests/TestCase/Twig/Extension/PotentialDangerousTest.php b/tests/TestCase/Twig/Extension/ConfigureExtensionTest.php similarity index 86% rename from tests/TestCase/Twig/Extension/PotentialDangerousTest.php rename to tests/TestCase/Twig/Extension/ConfigureExtensionTest.php index aa6783b..ef25db1 100644 --- a/tests/TestCase/Twig/Extension/PotentialDangerousTest.php +++ b/tests/TestCase/Twig/Extension/ConfigureExtensionTest.php @@ -18,13 +18,13 @@ namespace Cake\TwigView\Test\TestCase\Twig\Extension; -use Cake\TwigView\Twig\Extension\PotentialDangerous; +use Cake\TwigView\Twig\Extension\ConfigureExtension; -final class PotentialDangerousTest extends AbstractExtensionTest +class ConfigureExtensionTest extends AbstractExtensionTest { public function setUp(): void { - $this->extension = new PotentialDangerous(); + $this->extension = new ConfigureExtension(); parent::setUp(); } diff --git a/tests/TestCase/Twig/Extension/StringsTest.php b/tests/TestCase/Twig/Extension/StringsExtensionTest.php similarity index 97% rename from tests/TestCase/Twig/Extension/StringsTest.php rename to tests/TestCase/Twig/Extension/StringsExtensionTest.php index 5c74051..7ab26a8 100644 --- a/tests/TestCase/Twig/Extension/StringsTest.php +++ b/tests/TestCase/Twig/Extension/StringsExtensionTest.php @@ -18,13 +18,13 @@ namespace Cake\TwigView\Test\TestCase\Twig\Extension; -use Cake\TwigView\Twig\Extension\Strings; +use Cake\TwigView\Twig\Extension\StringsExtension; -final class StringsTest extends AbstractExtensionTest +class StringsExtensionTest extends AbstractExtensionTest { public function setUp(): void { - $this->extension = new Strings(); + $this->extension = new StringsExtension(); parent::setUp(); } diff --git a/tests/TestCase/Twig/LoaderTest.php b/tests/TestCase/Twig/LoaderTest.php index 8d441a7..301df15 100644 --- a/tests/TestCase/Twig/LoaderTest.php +++ b/tests/TestCase/Twig/LoaderTest.php @@ -66,8 +66,8 @@ public function testGetSourceNonExistingFile() public function testGetCacheKeyNoPlugin() { $this->assertSame( - TEST_APP . 'templates/layout.twig', - $this->Loader->getCacheKey('layout') + TEST_APP . 'templates/simple.twig', + $this->Loader->getCacheKey('simple') ); } diff --git a/tests/TestCase/View/TwigViewTest.php b/tests/TestCase/View/TwigViewTest.php index 4dd0fc5..a63419a 100644 --- a/tests/TestCase/View/TwigViewTest.php +++ b/tests/TestCase/View/TwigViewTest.php @@ -18,15 +18,9 @@ namespace Cake\TwigView\Test\TestCase; -use Cake\Core\Configure; -use Cake\Event\EventManager; use Cake\TestSuite\TestCase; -use Cake\TwigView\Event\ConstructEvent; -use Cake\TwigView\Event\EnvironmentConfigEvent; -use Cake\TwigView\View\TwigView; -use TestApp\Exception\MissingSomethingException; use TestApp\View\AppView; -use Twig\Environment; +use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; /** @@ -34,141 +28,69 @@ */ class TwigViewTest extends TestCase { - public function testInheritance() - { - $this->assertInstanceOf('Cake\View\View', new TwigView()); - } - - public function testConstruct() + /** + * Test rendering simple twig template. + * + * @return void + */ + public function testRenderSimpleTemplate() { - $this->_hibernateListeners(ConstructEvent::EVENT); - - $callbackFired = false; - $eventCallback = function ($event) use (&$callbackFired) { - self::assertInstanceof(Environment::class, $event->getSubject()->getTwig()); - $callbackFired = true; - }; - EventManager::instance()->on(ConstructEvent::EVENT, $eventCallback); - - new TwigView(); - - EventManager::instance()->off(ConstructEvent::EVENT, $eventCallback); - $this->_wakeupListeners(ConstructEvent::EVENT); + $view = new AppView(); + $output = $view->render('simple', false); - $this->assertTrue($callbackFired); + $this->assertSame('underscore_me', $output); } - public function testConstructConfig() + /** + * Test rendering simple twig template with layout. + * + * @return void + */ + public function testRenderSimpleTemplateWithLayout() { - Configure::write(TwigView::ENV_CONFIG, [ - 'true' => true, - ]); - - $this->_hibernateListeners(EnvironmentConfigEvent::EVENT); - - $callbackFired = false; - $that = $this; - $eventCallback = function ($event) use ($that, &$callbackFired) { - $that->assertIsArray($event->getConfig()); - $that->assertTrue($event->getConfig()['true']); - - $callbackFired = true; - }; - EventManager::instance()->on(EnvironmentConfigEvent::EVENT, $eventCallback); - - new TwigView(); - - EventManager::instance()->off(EnvironmentConfigEvent::EVENT, $eventCallback); - $this->_wakeupListeners(EnvironmentConfigEvent::EVENT); + $view = new AppView(); + $output = $view->render('simple'); - $this->assertTrue($callbackFired); + $this->assertSame('underscore_me', $output); } - public function test_renderPhp() + /** + * Test rendering template with layout. + * + * @return void + */ + public function testRenderLayoutWithElements() { - $output = 'foo:bar with a beer'; - $filename = 'cakephp'; - - $view = new TwigView(); - $renderedView = $view->render($filename); + $view = new AppView(); + $output = $view->render('Blog/index'); - self::assertSame($output, $renderedView); + $this->assertSame('blog_entry', $output); } /** - * Tests that a twig file that throws a custom exception correctly renders the thrown exception and not a Twig one. + * Tests a twig file that throws internal exception throw a Twig exception with message. + * + * @return void */ - public function test_renderTwigCustomException() + public function testThrowWrappedException() { - $this->expectException(MissingSomethingException::class); + $this->expectException(RuntimeError::class); + $this->expectExceptionMessage('Something is missing'); $view = new AppView(); $view->render('exception', false); } /** - * Tests that a twig file that throws a Twig exception correctly throws the twig exception and does not get caught - * byt the modification. + * Tests invalid twig template throws exception. + * + * @return void */ - public function test_renderTwigTwigException() + public function testThrowSyntaxError() { $this->expectException(SyntaxError::class); $view = new AppView(); $view->render('syntaxerror', false); } - - /** - * @param $name - * @return \Cake\TwigView\Test\TestCase\ReflectionMethod - */ - protected static function getMethod($name) - { - $class = new ReflectionClass('Cake\TwigView\View\TwigView'); - $method = $class->getMethod($name); - $method->setAccessible(true); - - return $method; - } - - /** - * @param $name - * @return \Cake\TwigView\Test\TestCase\ReflectionProperty - */ - protected static function getProperty($name) - { - $class = new ReflectionClass('Cake\TwigView\View\TwigView'); - $property = $class->getProperty($name); - $property->setAccessible(true); - - return $property; - } - - protected function _hibernateListeners($eventKey) - { - $this->__preservedEventListeners[$eventKey] = EventManager::instance()->listeners($eventKey); - - foreach ($this->__preservedEventListeners[$eventKey] as $eventListener) { - EventManager::instance()->off($eventListener['callable'], $eventKey); - } - } - - protected function _wakeupListeners($eventKey) - { - if (isset($this->__preservedEventListeners[$eventKey])) { - return; - } - - foreach ($this->__preservedEventListeners[$eventKey] as $eventListener) { - EventManager::instance()->on( - $eventListener['callable'], - $eventKey, - [ - 'passParams' => $eventListener['passParams'], - ] - ); - } - - $this->__preservedEventListeners = []; - } } diff --git a/tests/test_app/templates/Blog/index.twig b/tests/test_app/templates/Blog/index.twig index 8940348..8a0c3b0 100644 --- a/tests/test_app/templates/Blog/index.twig +++ b/tests/test_app/templates/Blog/index.twig @@ -1 +1 @@ -index.twig \ No newline at end of file +{% element 'blog_entry' %} \ No newline at end of file diff --git a/tests/test_app/templates/cakephp.php b/tests/test_app/templates/cakephp.php deleted file mode 100644 index def1132..0000000 --- a/tests/test_app/templates/cakephp.php +++ /dev/null @@ -1 +0,0 @@ -foo:bar with a beer \ No newline at end of file diff --git a/tests/test_app/templates/element/blog_entry.twig b/tests/test_app/templates/element/blog_entry.twig new file mode 100644 index 0000000..6c7d91e --- /dev/null +++ b/tests/test_app/templates/element/blog_entry.twig @@ -0,0 +1 @@ +{{ 'blog_entry' }} \ No newline at end of file diff --git a/tests/test_app/templates/element/element.twig b/tests/test_app/templates/element/element.twig deleted file mode 100644 index ca2014c..0000000 --- a/tests/test_app/templates/element/element.twig +++ /dev/null @@ -1 +0,0 @@ -element.twig \ No newline at end of file diff --git a/tests/test_app/templates/layout.twig b/tests/test_app/templates/layout.twig deleted file mode 100644 index 4db93cc..0000000 --- a/tests/test_app/templates/layout.twig +++ /dev/null @@ -1 +0,0 @@ -layout \ No newline at end of file diff --git a/tests/test_app/templates/layout/default.php b/tests/test_app/templates/layout/default.php deleted file mode 100644 index 444db1f..0000000 --- a/tests/test_app/templates/layout/default.php +++ /dev/null @@ -1 +0,0 @@ -fetch('content'); diff --git a/tests/test_app/templates/layout/default.twig b/tests/test_app/templates/layout/default.twig new file mode 100644 index 0000000..923c466 --- /dev/null +++ b/tests/test_app/templates/layout/default.twig @@ -0,0 +1 @@ +{{ _view.fetch('content')|raw }} \ No newline at end of file diff --git a/tests/test_app/templates/layout/layout.twig b/tests/test_app/templates/layout/layout.twig deleted file mode 100644 index b4007ca..0000000 --- a/tests/test_app/templates/layout/layout.twig +++ /dev/null @@ -1 +0,0 @@ -layout.twig \ No newline at end of file diff --git a/tests/test_app/templates/simple.twig b/tests/test_app/templates/simple.twig new file mode 100644 index 0000000..6becfc6 --- /dev/null +++ b/tests/test_app/templates/simple.twig @@ -0,0 +1 @@ +{{ 'UnderscoreMe'|underscore }} \ No newline at end of file