Skip to content
This repository was archived by the owner on Jul 18, 2022. It is now read-only.

Commit a92da42

Browse files
committed
Remove default template engine. #7
1 parent e4a2f3b commit a92da42

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

README.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,33 @@ $ composer create-project overtrue/yaf-skeleton myapp -vvv
2424
```
2525

2626
3. Web server rewrite rules:
27-
27+
2828
#### Apache
29-
29+
3030
```conf
3131
#.htaccess
3232
RewriteEngine On
3333
RewriteCond %{REQUEST_FILENAME} !-f
3434
RewriteRule .* index.php
3535
```
36-
36+
3737
#### Nginx
38-
38+
3939
```
4040
server {
4141
listen 80;
4242
server_name myapp.com;
4343
root /path/to/myapp;
4444
index index.php index.html index.htm;
45-
45+
4646
if (!-e $request_filename) {
4747
rewrite ^/(.*) /index.php/$1 last;
4848
}
4949
}
5050
```
51-
51+
5252
#### Lighttpd
53-
53+
5454
```
5555
$HTTP["host"] =~ "(www.)?myapp.com$" {
5656
url.rewrite = (
@@ -63,15 +63,15 @@ $ composer create-project overtrue/yaf-skeleton myapp -vvv
6363
# Application structor
6464
6565
```
66-
├── .scripts
66+
├── .scripts
6767
│   ├── .gitkeep
6868
│   ├── common.sh
6969
│   ├── job_phpcs.sh
7070
│   ├── job_phpmd.sh
7171
│   ├── job_phpunit.sh
7272
│   ├── sami.phar
7373
│   └── sami.php
74-
├── app
74+
├── app
7575
│   ├── commands # sora commands (namespace:\App\Commands)
7676
│   ├── controllers # Yaf Controllers (namespace:\)
7777
│   ├── exceptions # Exceptions (namespace:\App\Exceptions)
@@ -89,12 +89,12 @@ $ composer create-project overtrue/yaf-skeleton myapp -vvv
8989
│   └── index.php
9090
├── sora # The command line tool
9191
├── tests # Unit tests
92-
└── vendor #
92+
└── vendor #
9393
├── phpunit.xml.dist # PHPUnit config file
9494
├── .gitignore
9595
├── .php_cs # PHP-CS-Fixer config file
96-
├── composer.json
97-
├── composer.lock
96+
├── composer.json
97+
├── composer.lock
9898
├── README.md
9999
```
100100
@@ -103,8 +103,8 @@ $ composer create-project overtrue/yaf-skeleton myapp -vvv
103103
104104
105105
```shell
106-
$ ./sora make:controller Foo_Bar # or:foo_bar/FooBar/FooBarController
107-
#
106+
$ ./sora make:controller Foo_Bar # or:foo_bar/FooBar/FooBarController
107+
#
108108
# /www/myapp/app/controllers/Foo/Bar.php Created!
109109
# /www/myapp/tests/controllers/Foo/BarTest.php Created!
110110
```
@@ -128,7 +128,7 @@ The controller entry method `handle()`:
128128
<?php
129129

130130

131-
class ExampleController extends BaseController
131+
class ExampleController extends BaseController
132132
{
133133
public function handle()
134134
{
@@ -140,14 +140,18 @@ class ExampleController extends BaseController
140140
}
141141

142142
```
143-
143+
144144
# Views
145145

146-
The default we are using the template engine [Plates](http://platesphp.com/v3/), Plates is a native PHP template system that's fast, easy to use and easy to extend.
146+
There is no built-in template engine. If you need to use a PHP template, we recommend that you use [Plates](http://platesphp.com/v3/), Plates is a native PHP template system that's fast, easy to use and easy to extend.
147+
148+
```sh
149+
$ composer require league/plates -vvv
150+
```
147151

148152
You can use `view(string $template, array $data)` helper in controller `handle` method as a result.
149153

150-
for example:
154+
for example:
151155

152156
```php
153157
public function handle()
@@ -188,7 +192,7 @@ To create a controller test object, use,you can use the `mock_controller` func
188192
$controller = mock_controller(Foo_BarController::class);
189193

190194
// Indicates the method to mock, and the protected method is also mockable
191-
$controller = mock_controller(Foo_BarController::class, ['getUsers', 'getApp']);
195+
$controller = mock_controller(Foo_BarController::class, ['getUsers', 'getApp']);
192196
```
193197

194198
## Assertion
@@ -220,7 +224,7 @@ public function testHandle()
220224
'has_extend' => 1,
221225
'simplify' => 0,
222226
'is_encoded' => 0,
223-
'foo' => 'bar',
227+
'foo' => 'bar',
224228
];
225229

226230
Request::shouldReceive('only')

app/helpers.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ function config($property, $default = null)
4040
*/
4141
function view(string $template, array $data)
4242
{
43-
$body = Registry::get('services.view')->render($template, (array) $data);
43+
$engine = Registry::get('services.view');
44+
45+
if (!$engine) {
46+
abort('No template engine found.');
47+
}
48+
49+
$body = $engine->render($template, (array) $data);
4450

4551
return new Response(200, ['content-type' => 'text/html;charset=utf-8'], $body);
4652
}

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"psr/http-message": "~1.0",
3434
"symfony/console": "3.*",
3535
"monolog/monolog": "~1.0",
36-
"league/plates": "~3.0",
3736
"psr/container": "^1.0"
3837
},
3938
"require-dev": {
@@ -54,5 +53,8 @@
5453
"*": "dist"
5554
}
5655
},
56+
"suggest": {
57+
"league/plates": "Plates is a native PHP template system that's fast, easy to use and easy to extend."
58+
},
5759
"license": "MIT"
5860
}

0 commit comments

Comments
 (0)