From ff678a723cbf027260ffac573ebf44b7fd69d64e Mon Sep 17 00:00:00 2001 From: Hiroaki Matsuura Date: Wed, 11 Jan 2017 10:25:37 +0900 Subject: [PATCH 1/7] fix test for no cache directory path --- tests/BladeTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/BladeTest.php b/tests/BladeTest.php index a6bca4d..cdca93a 100644 --- a/tests/BladeTest.php +++ b/tests/BladeTest.php @@ -30,7 +30,7 @@ class BladeTest extends \PHPUnit_Framework_TestCase { $views = new Blade([ 'One' => __DIR__ . '/templates', - ]); + ], __DIR__ . '/../data/cache'); $output = $views->fetch('example', [ 'name' => 'Josh', ]); @@ -42,7 +42,7 @@ class BladeTest extends \PHPUnit_Framework_TestCase $views = new Blade([ 'One' => __DIR__ . '/templates', 'Two' => __DIR__ . '/another', - ]); + ], __DIR__ . '/../data/cache'); $outputOne = $views->fetch('example', [ 'name' => 'Peter', ]); From 7437b6d100c1528831ec03a862928f1f45b0f1b8 Mon Sep 17 00:00:00 2001 From: Hiroaki Matsuura Date: Wed, 11 Jan 2017 10:28:43 +0900 Subject: [PATCH 2/7] add travis settings --- .travis.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1b021fc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: php + +php: + - '5.5' + - '5.6' + - '7.0' + - '7.1' + - hhvm + - nightly + +before_script: composer install + +script: phpunit --configuration phpunit.xml.dist From 12654f65d58380e15f4173205e6168e7494bcf75 Mon Sep 17 00:00:00 2001 From: Hiroaki Matsuura Date: Wed, 11 Jan 2017 10:36:51 +0900 Subject: [PATCH 3/7] =?UTF-8?q?change=20phpunit=20version,=20so=20phpunit5?= =?UTF-8?q?=20does=20not=20support=20php=205.5=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Slim Framework 3 requires >=php5.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e30870b..cd06358 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ } }, "require-dev": { - "phpunit/phpunit": "^5.0", + "phpunit/phpunit": "^4.0", "slim/slim": "^3.0" } } \ No newline at end of file From 4ee82fa036ab6fbd84d3cf09983c36640556e2d2 Mon Sep 17 00:00:00 2001 From: Hiroaki Matsuura Date: Wed, 11 Jan 2017 11:01:29 +0900 Subject: [PATCH 4/7] =?UTF-8?q?change=20author=E2=80=99s=20email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cd06358..c3d98ce 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "authors": [ { "name": "Hiroaki Matsuura", - "email": "hiropeke.jp@gmail.com" + "email": "lib2jp@gmail.com" } ], "require": { From 63dac28733d3923c855286d871f0685688879b99 Mon Sep 17 00:00:00 2001 From: Hiroaki Matsuura Date: Wed, 11 Jan 2017 11:02:42 +0900 Subject: [PATCH 5/7] update README --- README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d9db70..de82e78 100644 --- a/README.md +++ b/README.md @@ -1 +1,69 @@ -# Slim-Blade-View \ No newline at end of file +# Slim-Blade-View + +[![Build Status](https://travis-ci.org/rubellum/Slim-Blade-View.svg?branch=master)](https://travis-ci.org/rubellum/Slim-Blade-View) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) + +This is a Slim Framework view helper built on top of the Blade component. + +You can use this component to create and render templates in your Slim Framework application. + +## Install + +Via [Composer](https://getcomposer.org/) + +``` +$ composer require hiropeke/slim-blade-view +``` + +Requires Slim Framework 3 and PHP 5.5.0 or newer. + +## Usage + +``` +// Slim Settings +$config = [ + 'settings' => [ + 'displayErrorDetails' => true, // set to false in production + + // Renderer settings + 'renderer' => [ + 'blade_template_path' => 'path/to/views', // String or array of multiple paths + 'blade_cache_path' => 'path/to/cache', // Mandatory by default, though could probably turn caching off for development + ], + ], +]; + +// Create Slim app +$app = new \Slim\App($config); + +// Fetch DI Container +$container = $app->getContainer(); + +// Register Blade View helper +$container['view'] = function ($container) { + return new \Slim\Views\Blade( + $container['settings']['renderer']['blade_template_path'], + $container['settings']['renderer']['blade_cache_path'] + ); +}; + +// Define named route +$app->get('/hello/{name}/', function ($request, $response, $args) { + return $this->view->render($response, 'profile', [ + 'name' => $args['name'], + ]); +})->setName('profile'); + +// Run app +$app->run(); +``` + +## Testing + +``` +$ phpunit +``` + +## License + +The MIT License (MIT). Please see [License File](LICENSE) for more information. From 7c234615e4d39a10663ba2d5d673aa095592f192 Mon Sep 17 00:00:00 2001 From: Hiroaki Matsuura Date: Wed, 11 Jan 2017 11:03:38 +0900 Subject: [PATCH 6/7] add example codes. --- example/.gitignore | 1 + example/cache/.gitignore | 2 ++ example/composer.json | 6 +++++ example/public/index.php | 40 +++++++++++++++++++++++++++++++++ example/views/profile.blade.php | 1 + 5 files changed, 50 insertions(+) create mode 100644 example/.gitignore create mode 100644 example/cache/.gitignore create mode 100644 example/composer.json create mode 100644 example/public/index.php create mode 100644 example/views/profile.blade.php diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..61ead86 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/example/cache/.gitignore b/example/cache/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/example/cache/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/example/composer.json b/example/composer.json new file mode 100644 index 0000000..6a53655 --- /dev/null +++ b/example/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "slim/slim": "^3.0", + "hiropeke/slim-blade-view": "^0.1.1" + } +} diff --git a/example/public/index.php b/example/public/index.php new file mode 100644 index 0000000..f83f894 --- /dev/null +++ b/example/public/index.php @@ -0,0 +1,40 @@ + [ + 'displayErrorDetails' => true, // set to false in production + + // Renderer settings + 'renderer' => [ + 'blade_template_path' => __DIR__ . '/../views', // String or array of multiple paths + 'blade_cache_path' => __DIR__ . '/../cache', // Mandatory by default, though could probably turn caching off for development + ], + ], +]; + +// Create Slim app +$app = new \Slim\App($config); + +// Fetch DI Container +$container = $app->getContainer(); + +// Register Blade View helper +$container['view'] = function ($container) { + return new \Slim\Views\Blade( + $container['settings']['renderer']['blade_template_path'], + $container['settings']['renderer']['blade_cache_path'] + ); +}; + +// Define named route +$app->get('/hello/{name}/', function ($request, $response, $args) { + return $this->view->render($response, 'profile', [ + 'name' => $args['name'], + ]); +})->setName('profile'); + +// Run app +$app->run(); diff --git a/example/views/profile.blade.php b/example/views/profile.blade.php new file mode 100644 index 0000000..063cd81 --- /dev/null +++ b/example/views/profile.blade.php @@ -0,0 +1 @@ +Hello, {{ $name }} From aa9dfbe75fdbeded3559b4d8d7eca3d2cdc72028 Mon Sep 17 00:00:00 2001 From: Hiroaki Matsuura Date: Wed, 11 Jan 2017 11:06:18 +0900 Subject: [PATCH 7/7] update README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index de82e78..2f8ffeb 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ You can use this component to create and render templates in your Slim Framework Via [Composer](https://getcomposer.org/) -``` +```bash $ composer require hiropeke/slim-blade-view ``` @@ -19,7 +19,7 @@ Requires Slim Framework 3 and PHP 5.5.0 or newer. ## Usage -``` +```php // Slim Settings $config = [ 'settings' => [ @@ -60,7 +60,7 @@ $app->run(); ## Testing -``` +```bash $ phpunit ```