Skip to content

Commit a7a0ab5

Browse files
committed
init
0 parents  commit a7a0ab5

File tree

17 files changed

+745
-0
lines changed

17 files changed

+745
-0
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
indent_style = space
7+
indent_size = 4
8+
trim_trailing_whitespace = true

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
!.gitkeep
2+
examples/vendor/*
3+
examples/cache/*
4+
examples/composer.lock
5+
examples/composer.json

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Soli View
2+
--------------
3+
4+
此项目对常用模版引擎进行封装,便于集成到开发者所熟悉的框架。
5+
目前支持以下模版引擎:
6+
7+
- Twig
8+
- Smarty
9+
10+
## 安装
11+
12+
使用 `composer` 安装到你的项目:
13+
14+
composer require soliphp/view
15+
16+
## 使用
17+
18+
详见:[examples].
19+
20+
## License
21+
22+
MIT Public License
23+
24+
25+
[examples]: examples

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "soliphp/view",
3+
"description": "Smarty and Twig View Parser package",
4+
"type": "library",
5+
"keywords": ["templating", "view", "soliphp"],
6+
"homepage": "https://github.com/soliphp/view",
7+
"support": {
8+
"issues": "https://github.com/soliphp/view/issues",
9+
"source": "https://github.com/soliphp/view"
10+
},
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "ueaner",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"require": {
19+
"php": ">=5.5.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Soli\\": "src/"
24+
}
25+
},
26+
"suggest": {
27+
"smarty/smarty": "Smarty templating system",
28+
"twig/twig": "Twig templating system"
29+
}
30+
}

examples/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Soli View examples
2+
------------------
3+
4+
当前目录提供了 Soli View 的相关示例。
5+
6+
## 使用
7+
8+
首先需要安装 Soli View 包:
9+
10+
composer require soliphp/view
11+
12+
### Twig
13+
14+
安装 Twig 模版引擎:
15+
16+
composer require twig/twig
17+
18+
运行:
19+
20+
php twig.php
21+
22+
### Smarty
23+
24+
安装 Smarty 模版引擎:
25+
26+
composer require smarty/smarty
27+
28+
运行:
29+
30+
php smarty.php

examples/smarty.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Soli\View;
4+
use Soli\View\Engine\Smarty as SmartyEngine;
5+
6+
include __DIR__ . "/vendor/autoload.php";
7+
8+
$config = [
9+
'viewsDir' => __DIR__ . '/views/smarty/',
10+
'viewsCacheDir' => __DIR__ . '/cache/templates/',
11+
'viewsCompileDir' => __DIR__ . '/cache/templates_c/',
12+
];
13+
14+
$view = new View();
15+
$view->setViewsDir($config['viewsDir']);
16+
$view->setViewExtension('.tpl');
17+
18+
// 通过匿名函数来设置模版引擎,延迟对模版引擎的实例化
19+
$view->setEngine(function () use ($config, $view) {
20+
$engine = new SmartyEngine($view);
21+
// 开启 debug 不进行缓存
22+
$engine->setDebug(true);
23+
$engine->setOptions(array(
24+
'compile_dir' => $config['viewsCompileDir'],
25+
'cache_dir' => $config['viewsCacheDir'],
26+
'caching' => true,
27+
'caching_type' => 'file',
28+
'cache_lifetime' => 86400,
29+
'left_delimiter' => '{{',
30+
'right_delimiter' => '}}',
31+
));
32+
return $engine;
33+
});
34+
35+
$view->setVar('name', 'Soli');
36+
37+
$template = 'home/index';
38+
39+
echo $view->render($template);
40+
41+

examples/twig.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Soli\View;
4+
use Soli\View\Engine\Twig as TwigEngine;
5+
6+
include __DIR__ . "/vendor/autoload.php";
7+
8+
$config = [
9+
'viewsDir' => __DIR__ . '/views/twig/',
10+
'viewsCacheDir' => __DIR__ . '/cache/twig/',
11+
];
12+
13+
$view = new View();
14+
$view->setViewsDir($config['viewsDir']);
15+
$view->setViewExtension('.twig');
16+
17+
// 通过匿名函数来设置模版引擎,延迟对模版引擎的实例化
18+
$view->setEngine(function () use ($config, $view) {
19+
$engine = new TwigEngine($view);
20+
// 开启 debug 不进行缓存
21+
$engine->setDebug(true);
22+
$engine->setCacheDir($config['viewsCacheDir']);
23+
// 使用扩展
24+
// $engine->addExtension(new MyTwigExtension());
25+
return $engine;
26+
});
27+
28+
$view->setVar('name', 'Soli');
29+
30+
$template = 'home/index';
31+
32+
echo $view->render($template);
33+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hi, {{$name}}.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hi, {{ name }}.

phpcs.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Soli Coding Standard">
3+
<description>Soli Coding Standard</description>
4+
5+
<!-- display progress -->
6+
<arg value="p"/>
7+
<!-- display sniff codes -->
8+
<arg value="s"/>
9+
<!-- use colors in output -->
10+
<arg name="colors"/>
11+
<!-- file extensions -->
12+
<arg name="extensions" value="php"/>
13+
14+
<!-- inherit rules from: -->
15+
<rule ref="PSR2"/>
16+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
17+
<rule ref="PSR1">
18+
<exclude name="PSR1.Classes.ClassDeclaration"/>
19+
</rule>
20+
21+
<!-- ignore vendor -->
22+
<exclude-pattern>*/vendor/*</exclude-pattern>
23+
<exclude-pattern>*/examples/*</exclude-pattern>
24+
</ruleset>

0 commit comments

Comments
 (0)