Skip to content

Commit 0862c03

Browse files
author
Marco Bunge
committed
Finalize integration
1 parent eeae647 commit 0862c03

File tree

6 files changed

+94
-59
lines changed

6 files changed

+94
-59
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hawkbit/persistence",
3-
"type": "library",
3+
"type": "hawkbit-component",
44
"description": "Persistence layer for Hawkbit PSR-7 Micro PHP framework",
55
"keywords": [
66
"doctrine",
@@ -19,11 +19,11 @@
1919
"require": {
2020
"php": ">=5.5.0",
2121
"league/plates": "~3.0",
22-
"robclancy/presenter": "~1.3.1",
23-
"hawkbit/hawkbit": "~2.0"
22+
"robclancy/presenter": "~1.3.1"
2423
},
2524
"require-dev": {
26-
"phpunit/phpunit": "~4.8"
25+
"phpunit/phpunit": "~4.8",
26+
"hawkbit/hawkbit": "~2.0"
2727
},
2828
"autoload": {
2929
"psr-4": {

src/PersistenceServiceProvider.php

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: marco.bunge
5+
* Date: 14.10.2016
6+
* Time: 13:40
7+
*/
8+
9+
namespace Hawkbit\Persistence;
10+
11+
12+
use League\Container\ServiceProvider\AbstractServiceProvider;
13+
use League\Plates\Engine;
14+
15+
class PresentationServiceProvider extends AbstractServiceProvider
16+
{
17+
18+
protected $provides = [
19+
Engine::class
20+
];
21+
/**
22+
* @var array
23+
*/
24+
private $templates;
25+
26+
/**
27+
* PresentationServiceProvider constructor.
28+
* @param array $templates
29+
*/
30+
public function __construct($templates)
31+
{
32+
$this->templates = $templates;
33+
}
34+
35+
/**
36+
* Use the register method to register items with the container via the
37+
* protected $this->container property or the `getContainer` method
38+
* from the ContainerAwareTrait.
39+
*
40+
* @return void
41+
*/
42+
public function register()
43+
{
44+
$this->registerTemplateEngine();
45+
}
46+
47+
/**
48+
* Register template engine
49+
*
50+
* @return $this
51+
*/
52+
protected function registerTemplateEngine()
53+
{
54+
$container = $this->getContainer();
55+
$this->getContainer()->add(Engine::class, function () use ($container) {
56+
$templates = $this->templates;
57+
if (isset($templates['default'])) {
58+
$default = $templates['default'];
59+
// unset($templates['default']);
60+
} else {
61+
$default = reset($templates);
62+
// $defaultKey = key($default);
63+
// unset($templates[$defaultKey]);
64+
}
65+
$engine = new Engine($default);
66+
foreach ($templates as $name => $template) {
67+
$engine->addFolder($name, $template, false);
68+
}
69+
return $engine;
70+
});
71+
return $this;
72+
}
73+
}

tests/IntegrationTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@
1414
use Hawkbit\Application;
1515
use Hawkbit\Persistence\PersistenceService;
1616
use Hawkbit\Persistence\PersistenceServiceInterface;
17-
use Hawkbit\Persistence\PersistenceServiceProvider;
17+
use Hawkbit\Persistence\PresentationServiceProvider;
18+
use League\Plates\Engine;
19+
use org\bovigo\vfs\vfsStream;
1820

1921
class IntegrationTest extends \PHPUnit_Framework_TestCase
2022
{
2123

2224
public function testIntegration()
2325
{
24-
$this->markTestSkipped();
2526
$app = new Application(require __DIR__ . '/assets/config.php');
27+
$app->register(new PresentationServiceProvider($app->getConfig('templates')));
2628

29+
$engine = $app[Engine::class];
30+
$result = $engine->render('index', ['world' => 'World']);
2731

32+
33+
$this->assertInstanceOf(Engine::class, $engine);
34+
$this->assertEquals('Hello World', $result);
2835
}
2936
}

tests/assets/config.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
<?php
22
return [
3-
'doctrine' => [
4-
'connection' => [
5-
'orm_default' => [
6-
'driver_class' => Doctrine\DBAL\Driver\PDOSqlite\Driver::class,
7-
'params' => [
8-
[
9-
'url' => 'sqlite:///:memory:',
10-
'memory' => true
11-
]
12-
],
13-
],
14-
],
15-
'driver' => [
16-
'orm_default' => [
17-
'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
18-
'cache' => 'array',
19-
'paths' => __DIR__ . '/doctrine',
20-
],
21-
],
3+
'templates' => [
4+
'default' => __DIR__ . '/../templates/default'
225
],
236
];

tests/templates/default/index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
$world = isset($world) ? $world : null ;
4+
5+
?>
6+
Hello <?php echo $world ?>

0 commit comments

Comments
 (0)