diff --git a/README.md b/README.md index bdcb543..224a99d 100644 --- a/README.md +++ b/README.md @@ -39,30 +39,34 @@ For example you are using [BEAR.Package](https://github.com/koriym/BEAR.Package) modifying your `AppModule` as: ```php -namespace YourVendor\YourApp\Module; +namespace MyVendor\MyPackage\Module; +use Madapaja\TwigModule\Annotation\TwigOptions; +use Madapaja\TwigModule\Annotation\TwigPaths; use Madapaja\TwigModule\TwigModule; +use Ray\Di\AbstractModule; class AppModule extends AbstractModule { protected function configure() { - $appDir = dirname(dirname(__DIR__)); - $this->install(new TwigModule([$appDir . '/src/Resource'])); + $this->install(new TwigModule()); // You can add twig template paths by the following - // $this->install(new TwigModule([$appDir . '/src/Resource', $appDir . '/var/lib/twig'])); - - // Or you can set environment options by 2nd argument - // see: http://twig.sensiolabs.org/doc/api.html#environment-options - // $this->install(new TwigModule([$appDir . '/src/Resource'], [ - // 'debug' => true, - // 'cache' => '/tmp/' - // ])); - - // (Existing configurations here) + $appDir = dirname(dirname(__DIR__)); + $paths = [$appDir . '/src/Resource', $appDir . '/var/lib/twig']; + $this->bind()->annotatedWith(TwigPaths::class)->toInstance($paths); + + // Also you can set environment options + // @see http://twig.sensiolabs.org/doc/api.html#environment-options + $options = [ + 'debug' => true, + 'cache' => '/tmp/' + ]; + $this->bind()->annotatedWith(TwigOptions::class)->toInstance($options); } } + ``` And you put twig template file into the resource directory. diff --git a/src/Annotation/TwigOptions.php b/src/Annotation/TwigOptions.php new file mode 100644 index 0000000..775021f --- /dev/null +++ b/src/Annotation/TwigOptions.php @@ -0,0 +1,15 @@ +bind(RenderInterface::class)->to(TwigRenderer::class); - $this->bind()->annotatedWith('twig_paths')->toInstance($this->paths); - $this->bind()->annotatedWith('twig_options')->toInstance($this->options); + if ($this->paths) { + $this->bind()->annotatedWith(TwigPaths::class)->toInstance($this->paths); + $this->bind()->annotatedWith(TwigOptions::class)->toInstance($this->options); + } $this ->bind(Twig_LoaderInterface::class) ->annotatedWith('twig_loader') ->toConstructor( Twig_Loader_Filesystem::class, - 'paths=twig_paths' + 'paths=Madapaja\TwigModule\Annotation\TwigPaths' ); $this ->bind(Twig_Environment::class) ->toConstructor( Twig_Environment::class, - 'loader=twig_loader,options=twig_options' + 'loader=twig_loader,options=Madapaja\TwigModule\Annotation\TwigOptions' ) ->in(Scope::SINGLETON); } diff --git a/src/TwigRenderer.php b/src/TwigRenderer.php index be1b8c0..f05d851 100644 --- a/src/TwigRenderer.php +++ b/src/TwigRenderer.php @@ -81,7 +81,7 @@ private function getReflection(ResourceObject $ro) } /** - * return templete file full path + * return template file full path * * @param ResourceObject $ro * @return string