Merge branch 'fix-document-and-tests'
This commit is contained in:
13
.travis.yml
Normal file
13
.travis.yml
Normal file
@ -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
|
70
README.md
70
README.md
@ -1 +1,69 @@
|
||||
# Slim-Blade-View
|
||||
# Slim-Blade-View
|
||||
|
||||
[](https://travis-ci.org/rubellum/Slim-Blade-View)
|
||||
[](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/)
|
||||
|
||||
```bash
|
||||
$ composer require hiropeke/slim-blade-view
|
||||
```
|
||||
|
||||
Requires Slim Framework 3 and PHP 5.5.0 or newer.
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
// 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
|
||||
|
||||
```bash
|
||||
$ phpunit
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](LICENSE) for more information.
|
||||
|
@ -14,7 +14,7 @@
|
||||
"authors": [
|
||||
{
|
||||
"name": "Hiroaki Matsuura",
|
||||
"email": "hiropeke.jp@gmail.com"
|
||||
"email": "lib2jp@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
@ -28,7 +28,7 @@
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.0",
|
||||
"phpunit/phpunit": "^4.0",
|
||||
"slim/slim": "^3.0"
|
||||
}
|
||||
}
|
1
example/.gitignore
vendored
Normal file
1
example/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/vendor
|
2
example/cache/.gitignore
vendored
Normal file
2
example/cache/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
6
example/composer.json
Normal file
6
example/composer.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"require": {
|
||||
"slim/slim": "^3.0",
|
||||
"hiropeke/slim-blade-view": "^0.1.1"
|
||||
}
|
||||
}
|
40
example/public/index.php
Normal file
40
example/public/index.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// Slim Settings
|
||||
$config = [
|
||||
'settings' => [
|
||||
'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();
|
1
example/views/profile.blade.php
Normal file
1
example/views/profile.blade.php
Normal file
@ -0,0 +1 @@
|
||||
Hello, {{ $name }}
|
@ -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',
|
||||
]);
|
||||
|
Reference in New Issue
Block a user