Skip to content

Commit

Permalink
添加开关量控制composer autoload行为
Browse files Browse the repository at this point in the history
  • Loading branch information
kinosang committed Mar 24, 2016
1 parent 6392ca0 commit 796d144
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 55 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ script:
## LINT
- find . -path ./vendor -prune -o -type f -name \*.php -exec php -l {} \;
## PHP_CodeSniffer
- vendor/bin/phpcs --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 --standard=PSR2 --ignore="vendor/*" ./
- THINK_AUTOLOAD=0 vendor/bin/phpcs --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 --standard=PSR2 --ignore="vendor/*" ./
## PHP Copy/Paste Detector
- vendor/bin/phpcpd --verbose --exclude vendor ./ || true
- THINK_AUTOLOAD=0 vendor/bin/phpcpd --verbose --exclude vendor ./ || true
## PHPLOC
- vendor/bin/phploc --exclude vendor ./
- THINK_AUTOLOAD=0 vendor/bin/phploc --exclude vendor ./
## PHPUNIT
- vendor/bin/phpunit --coverage-clover=coverage.xml --configuration=phpunit.xml
- THINK_AUTOLOAD=0 vendor/bin/phpunit --coverage-clover=coverage.xml --configuration=phpunit.xml

after_success:
- bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion base.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
defined('APP_HOOK') or define('APP_HOOK', false); // 是否开启HOOK
defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_'); // 环境变量的配置前缀
defined('IS_API') or define('IS_API', false); // 是否API接口
defined('APP_AUTO_RUN') or define('APP_AUTO_RUN', strrpos($_SERVER['PHP_SELF'], 'vendor/bin/') !== 0); // 是否自动运行
defined('APP_AUTO_RUN') or define('APP_AUTO_RUN', true); // 是否自动运行
defined('APP_ROUTE_ON') or define('APP_ROUTE_ON', true); // 是否允许路由
defined('APP_ROUTE_MUST') or define('APP_ROUTE_MUST', true); // 是否严格检查路由
defined('CLASS_APPEND_SUFFIX') or define('CLASS_APPEND_SUFFIX', false); // 是否追加类名后缀
Expand Down
52 changes: 3 additions & 49 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,8 @@
namespace think;

// ThinkPHP 引导文件
// 加载基础文件
require __DIR__ . '/base.php';
require CORE_PATH . 'Loader.php';
defined('THINK_AUTOLOAD') or define('THINK_AUTOLOAD', getenv('THINK_AUTOLOAD') !== '0');

// 加载环境变量配置文件
if (is_file(ROOT_PATH . 'env' . EXT)) {
$env = include ROOT_PATH . 'env' . EXT;
foreach ($env as $key => $val) {
$name = ENV_PREFIX . $key;
putenv("$name=$val");
}
}
// 自动识别调试模式
if (!defined('APP_DEBUG')) {
$debug = getenv(ENV_PREFIX . 'APP_DEBUG');
define('APP_DEBUG', $debug);
}

// 加载模式定义文件
$mode = require MODE_PATH . APP_MODE . EXT;

// 加载模式命名空间定义
if (isset($mode['namespace'])) {
Loader::addNamespace($mode['namespace']);
}

// 注册自动加载
Loader::register();

// 加载模式别名定义
if (isset($mode['alias'])) {
Loader::addMap($mode['alias']);
}

// 注册错误和异常处理机制
Error::register();

// 加载模式配置文件
if (isset($mode['config'])) {
is_array($mode['config']) ? Config::set($mode['config']) : Config::load($mode['config']);
}

// 加载模式行为定义
if (APP_HOOK && isset($mode['tags'])) {
Hook::import($mode['tags']);
}

// 是否自动运行
if (APP_AUTO_RUN) {
App::run();
if (THINK_AUTOLOAD) {
require_once __DIR__ . '/think.php';
}
2 changes: 1 addition & 1 deletion tests/mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
// 关闭应用自动执行
define('APP_AUTO_RUN', false);
// 加载框架引导文件
require __DIR__ . '/../start.php';
require __DIR__ . '/../think.php';
\think\Loader::addNamespace('tests', TEST_PATH);
65 changes: 65 additions & 0 deletions think.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------

namespace think;

// ThinkPHP 实际引导文件
// 加载基础文件
require __DIR__ . '/base.php';
require CORE_PATH . 'Loader.php';

// 加载环境变量配置文件
if (is_file(ROOT_PATH . 'env' . EXT)) {
$env = include ROOT_PATH . 'env' . EXT;
foreach ($env as $key => $val) {
$name = ENV_PREFIX . $key;
putenv("$name=$val");
}
}
// 自动识别调试模式
if (!defined('APP_DEBUG')) {
$debug = getenv(ENV_PREFIX . 'APP_DEBUG');
define('APP_DEBUG', $debug);
}

// 加载模式定义文件
$mode = require MODE_PATH . APP_MODE . EXT;

// 加载模式命名空间定义
if (isset($mode['namespace'])) {
Loader::addNamespace($mode['namespace']);
}

// 注册自动加载
Loader::register();

// 加载模式别名定义
if (isset($mode['alias'])) {
Loader::addMap($mode['alias']);
}

// 注册错误和异常处理机制
Error::register();

// 加载模式配置文件
if (isset($mode['config'])) {
is_array($mode['config']) ? Config::set($mode['config']) : Config::load($mode['config']);
}

// 加载模式行为定义
if (APP_HOOK && isset($mode['tags'])) {
Hook::import($mode['tags']);
}

// 是否自动运行
if (APP_AUTO_RUN) {
App::run();
}

0 comments on commit 796d144

Please sign in to comment.