Skip to content

Commit

Permalink
改进多应用的判断
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Aug 15, 2019
1 parent a1c09e2 commit 949fb11
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/think/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ protected function runWithRequest(Request $request)
$this->app->middleware->import(include $this->app->getBasePath() . 'middleware.php');
}

if ($this->multi) {
$this->parseMultiApp();
$autoMulti = $this->app->config->get('app.auto_multi_app', false);

if ($this->multi || $autoMulti) {
$this->multi(true);
$this->parseMultiApp($autoMulti);
}

// 设置开启事件机制
Expand Down Expand Up @@ -270,10 +273,11 @@ protected function getScriptName(): string

/**
* 解析多应用
* @param bool $autoMulti 自动多应用
*/
protected function parseMultiApp(): void
protected function parseMultiApp($autoMulti): void
{
if ($this->app->config->get('app.auto_multi_app', false)) {
if ($autoMulti) {
// 自动多应用识别
$this->bindDomain = false;

Expand Down
12 changes: 11 additions & 1 deletion src/think/console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class Command
private $console;
private $name;
private $processTitle;
private $aliases = [];
private $aliases = [];
private $definition;
private $help;
private $description;
Expand Down Expand Up @@ -500,4 +500,14 @@ protected function table(Table $table): string
$this->output->writeln($content);
return $content;
}

/**
* 判断当前应用是否多应用
* @return bool
*/
protected function isMultiApp(): bool
{
$autoMulti = $this->app->config->get('app.auto_multi_app', false);
return $autoMulti || !is_dir($this->app->getBasePath() . 'controller');
}
}
2 changes: 1 addition & 1 deletion src/think/console/command/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function execute(Input $input, Output $output)
{
$app = $input->getArgument('app');

if (empty($app) && !is_dir($this->app->getBasePath() . 'controller')) {
if (empty($app) && $this->isMultiApp()) {
$output->writeln('<error>Miss app name!</error>');
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/think/console/command/optimize/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function execute(Input $input, Output $output)
{
$app = $input->getArgument('app');

if (empty($app) && !is_dir($this->app->getBasePath() . 'controller')) {
if (empty($app) && $this->isMultiApp()) {
$output->writeln('<error>Miss app name!</error>');
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/think/console/command/optimize/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function execute(Input $input, Output $output)
$dbName = $input->getOption('db');
$tables = $this->app->db->getConnection()->getTables($dbName);
} else {
if (empty($app) && !is_dir($this->app->getBasePath() . 'controller')) {
if (empty($app) && $this->isMultiApp()) {
$output->writeln('<error>Miss app name!</error>');
return false;
}
Expand Down

0 comments on commit 949fb11

Please sign in to comment.