From d93d51c22e6db2609229b73f4cbec459842ecf94 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 15 Feb 2015 12:13:35 +0900 Subject: [PATCH 1/6] use @TwigOptions @TwigPaths @Named to qualifier annotation --- src/Annotation/TwigOptions.php | 15 +++++++++++++++ src/Annotation/TwigPaths.php | 15 +++++++++++++++ src/TwigModule.php | 10 ++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/Annotation/TwigOptions.php create mode 100644 src/Annotation/TwigPaths.php 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); + $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); } From b00e837d48e3eff2e9cf4e866d567c2a24845abc Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 15 Feb 2015 12:38:51 +0900 Subject: [PATCH 2/6] allow binding outside MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 他のモジュールでこの設定をしたい場合のため --- src/TwigModule.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/TwigModule.php b/src/TwigModule.php index 73fea65..30282fc 100644 --- a/src/TwigModule.php +++ b/src/TwigModule.php @@ -41,8 +41,10 @@ public function __construct($paths = [], $options = []) protected function configure() { $this->bind(RenderInterface::class)->to(TwigRenderer::class); - $this->bind()->annotatedWith(TwigPaths::class)->toInstance($this->paths); - $this->bind()->annotatedWith(TwigOptions::class)->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') From 14bf80f0645d9380efc454840bc6329aa090e5a3 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 15 Feb 2015 12:39:02 +0900 Subject: [PATCH 3/6] update README --- README.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) 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. From 0771a1c904b07a0107e61ded62bdfd64070e95d7 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 15 Feb 2015 12:40:22 +0900 Subject: [PATCH 4/6] fix typo --- src/TwigRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From bb2b5711e7d57f622fe7f733e5b9a40426f55fcd Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 15 Feb 2015 12:52:09 +0900 Subject: [PATCH 5/6] add AnnotationRegistry --- src/DoctrineAnnotations.php | 4 ++++ src/TwigModule.php | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 src/DoctrineAnnotations.php diff --git a/src/DoctrineAnnotations.php b/src/DoctrineAnnotations.php new file mode 100644 index 0000000..662ce02 --- /dev/null +++ b/src/DoctrineAnnotations.php @@ -0,0 +1,4 @@ +bind(RenderInterface::class)->to(TwigRenderer::class); if ($this->paths) { $this->bind()->annotatedWith(TwigPaths::class)->toInstance($this->paths); From 5d953fb0755a6c57baa3e4244d22a7d61ab92332 Mon Sep 17 00:00:00 2001 From: Iwasaki Koji Date: Mon, 16 Feb 2015 11:41:52 +0900 Subject: [PATCH 6/6] fix typo --- src/DoctrineAnnotations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DoctrineAnnotations.php b/src/DoctrineAnnotations.php index 662ce02..aa5fd06 100644 --- a/src/DoctrineAnnotations.php +++ b/src/DoctrineAnnotations.php @@ -1,4 +1,4 @@