Skip to content

Commit

Permalink
使用常见的 app, db 缩写,作为配置下标
Browse files Browse the repository at this point in the history
  • Loading branch information
ueaner committed Mar 30, 2018
1 parent 7e91ab9 commit 6b0df33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ server
// 基本配置信息
$config = array(
// 应用
'application' => array(
'app' => array(
'viewsDir' => BASE_PATH . '/views/',
'logDir' => BASE_PATH . '/var/log/',
'cacheDir' => BASE_PATH . '/var/cache/',
),
// 数据库
'database' => array(
'db' => array(
'dsn' => 'mysql:host=localhost;port=3306;dbname=test;charset=utf8',
'username' => 'root',
'password' => 'root',
Expand Down Expand Up @@ -186,7 +186,7 @@ server
// 配置数据库信息, Model中默认获取的数据库连接标志为"db"
// 可使用不同的服务名称设置不同的数据库连接信息,供 Model 中做多库的选择
$container->setShared('db', function () {
return new DbConnection($this->config->database);
return new DbConnection($this->config->db);
});

// 路由
Expand All @@ -212,15 +212,15 @@ server
$config = $this->config;

$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->setViewsDir($config->app->viewsDir);
$view->setViewExtension('.twig');

// 通过匿名函数来设置模版引擎,延迟对模版引擎的实例化
$view->setEngine(function () use ($config, $view) {
$engine = new TwigEngine($view);
// 开启 debug 不进行缓存
//$engine->setDebug(true);
$engine->setCacheDir($config->application->cacheDir . 'twig');
$engine->setCacheDir($config->app->cacheDir . 'twig');
return $engine;
});

Expand All @@ -234,7 +234,7 @@ server
$config = $this->config;

$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->setViewsDir($config->app->viewsDir);
$view->setViewExtension('.tpl');

// 通过匿名函数来设置模版引擎,延迟对模版引擎的实例化
Expand All @@ -243,8 +243,8 @@ server
// 开启 debug 不进行缓存
$engine->setDebug(true);
$engine->setOptions(array(
'compile_dir' => $config->application->cacheDir . 'templates_c',
'cache_dir' => $config->application->cacheDir . 'templates',
'compile_dir' => $config->app->cacheDir . 'templates_c',
'cache_dir' => $config->app->cacheDir . 'templates',
'caching' => true,
'caching_type' => 'file',
'cache_lifetime' => 86400,
Expand Down
4 changes: 2 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* 基本配置信息
*/
return new \Soli\Config([
'application' => [
'app' => [
'viewsDir' => BASE_PATH . '/views/',
'logDir' => BASE_PATH . '/var/log/',
'cacheDir' => BASE_PATH . '/var/cache/',
],
'database' => [
'db' => [
'dsn' => 'mysql:host=localhost;port=3306;dbname=test;charset=utf8',
'username' => 'root',
'password' => 'root',
Expand Down
8 changes: 4 additions & 4 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
// 配置数据库信息, Model中默认获取的数据库连接标志为"db"
// 可使用不同的服务名称设置不同的数据库连接信息,供 Model 中做多库的选择
$container->setShared('db', function () {
return new DbConnection($this->config->database);
return new DbConnection($this->config->db);
});

// 日志记录器
$container->setShared('logger', function () {
$logFile = $this->config->application->logDir . '/soli.log';
$logFile = $this->config->app->logDir . '/soli.log';
$stream = new StreamHandler($logFile, Logger::DEBUG);

// 创建应用的主要日志服务实例
Expand Down Expand Up @@ -58,15 +58,15 @@
$config = $this->config;

$view = new View();
$view->setViewsDir($config->application->viewsDir);
$view->setViewsDir($config->app->viewsDir);
$view->setViewExtension('.twig');

// 通过匿名函数来设置模版引擎,延迟对模版引擎的实例化
$view->setEngine(function () use ($config, $view) {
$engine = new TwigEngine($view);
// 开启 debug 不进行缓存
$engine->setDebug(true);
$engine->setCacheDir($config->application->cacheDir . 'twig');
$engine->setCacheDir($config->app->cacheDir . 'twig');
return $engine;
});

Expand Down

0 comments on commit 6b0df33

Please sign in to comment.