mirror of
https://github.com/flarum/framework.git
synced 2025-02-06 19:29:47 +08:00
Simplify DataProviderInterface
Instead of passing all these objects / arrays from one object to the next, simply pass an Installation instance around for configuration.
This commit is contained in:
parent
7b2807a839
commit
f2bc007c2d
|
@ -11,18 +11,9 @@
|
||||||
|
|
||||||
namespace Flarum\Install\Console;
|
namespace Flarum\Install\Console;
|
||||||
|
|
||||||
use Flarum\Install\AdminUser;
|
use Flarum\Install\Installation;
|
||||||
use Flarum\Install\DatabaseConfig;
|
|
||||||
|
|
||||||
interface DataProviderInterface
|
interface DataProviderInterface
|
||||||
{
|
{
|
||||||
public function getDatabaseConfiguration(): DatabaseConfig;
|
public function configure(Installation $installation): Installation;
|
||||||
|
|
||||||
public function getBaseUrl();
|
|
||||||
|
|
||||||
public function getAdminUser(): AdminUser;
|
|
||||||
|
|
||||||
public function getSettings();
|
|
||||||
|
|
||||||
public function isDebugMode(): bool;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace Flarum\Install\Console;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Install\AdminUser;
|
use Flarum\Install\AdminUser;
|
||||||
use Flarum\Install\DatabaseConfig;
|
use Flarum\Install\DatabaseConfig;
|
||||||
|
use Flarum\Install\Installation;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
|
@ -53,7 +54,17 @@ class FileDataProvider implements DataProviderInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDatabaseConfiguration(): DatabaseConfig
|
public function configure(Installation $installation): Installation
|
||||||
|
{
|
||||||
|
return $installation
|
||||||
|
->debugMode($this->debug)
|
||||||
|
->baseUrl($this->baseUrl ?? 'http://flarum.local')
|
||||||
|
->databaseConfig($this->getDatabaseConfiguration())
|
||||||
|
->adminUser($this->getAdminUser())
|
||||||
|
->settings($this->settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDatabaseConfiguration(): DatabaseConfig
|
||||||
{
|
{
|
||||||
return new DatabaseConfig(
|
return new DatabaseConfig(
|
||||||
$this->databaseConfiguration['driver'] ?? 'mysql',
|
$this->databaseConfiguration['driver'] ?? 'mysql',
|
||||||
|
@ -66,12 +77,7 @@ class FileDataProvider implements DataProviderInterface
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBaseUrl()
|
private function getAdminUser(): AdminUser
|
||||||
{
|
|
||||||
return $this->baseUrl ?? 'http://flarum.local';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAdminUser(): AdminUser
|
|
||||||
{
|
{
|
||||||
return new AdminUser(
|
return new AdminUser(
|
||||||
$this->adminUser['username'] ?? 'admin',
|
$this->adminUser['username'] ?? 'admin',
|
||||||
|
@ -79,14 +85,4 @@ class FileDataProvider implements DataProviderInterface
|
||||||
$this->adminUser['email'] ?? 'admin@example.com'
|
$this->adminUser['email'] ?? 'admin@example.com'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSettings()
|
|
||||||
{
|
|
||||||
return $this->settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isDebugMode(): bool
|
|
||||||
{
|
|
||||||
return $this->debug;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,16 +89,11 @@ class InstallCommand extends AbstractCommand
|
||||||
|
|
||||||
protected function install()
|
protected function install()
|
||||||
{
|
{
|
||||||
$this->runPipeline(
|
$pipeline = $this->dataSource->configure(
|
||||||
$this->installation
|
$this->installation->configPath($this->input->getOption('config'))
|
||||||
->configPath($this->input->getOption('config'))
|
)->build();
|
||||||
->debugMode($this->dataSource->isDebugMode())
|
|
||||||
->baseUrl($this->dataSource->getBaseUrl())
|
$this->runPipeline($pipeline);
|
||||||
->databaseConfig($this->dataSource->getDatabaseConfiguration())
|
|
||||||
->adminUser($this->dataSource->getAdminUser())
|
|
||||||
->settings($this->dataSource->getSettings())
|
|
||||||
->build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function runPipeline(Pipeline $pipeline)
|
private function runPipeline(Pipeline $pipeline)
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace Flarum\Install\Console;
|
||||||
|
|
||||||
use Flarum\Install\AdminUser;
|
use Flarum\Install\AdminUser;
|
||||||
use Flarum\Install\DatabaseConfig;
|
use Flarum\Install\DatabaseConfig;
|
||||||
|
use Flarum\Install\Installation;
|
||||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
@ -35,7 +36,17 @@ class UserDataProvider implements DataProviderInterface
|
||||||
$this->questionHelper = $questionHelper;
|
$this->questionHelper = $questionHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDatabaseConfiguration(): DatabaseConfig
|
public function configure(Installation $installation): Installation
|
||||||
|
{
|
||||||
|
return $installation
|
||||||
|
->debugMode(false)
|
||||||
|
->baseUrl($this->getBaseUrl())
|
||||||
|
->databaseConfig($this->getDatabaseConfiguration())
|
||||||
|
->adminUser($this->getAdminUser())
|
||||||
|
->settings($this->getSettings());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDatabaseConfiguration(): DatabaseConfig
|
||||||
{
|
{
|
||||||
$host = $this->ask('Database host:');
|
$host = $this->ask('Database host:');
|
||||||
$port = 3306;
|
$port = 3306;
|
||||||
|
@ -55,12 +66,12 @@ class UserDataProvider implements DataProviderInterface
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBaseUrl()
|
private function getBaseUrl()
|
||||||
{
|
{
|
||||||
return $this->baseUrl = rtrim($this->ask('Base URL:'), '/');
|
return $this->baseUrl = rtrim($this->ask('Base URL:'), '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAdminUser(): AdminUser
|
private function getAdminUser(): AdminUser
|
||||||
{
|
{
|
||||||
return new AdminUser(
|
return new AdminUser(
|
||||||
$this->ask('Admin username:'),
|
$this->ask('Admin username:'),
|
||||||
|
@ -90,7 +101,7 @@ class UserDataProvider implements DataProviderInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSettings()
|
private function getSettings()
|
||||||
{
|
{
|
||||||
$title = $this->ask('Forum title:');
|
$title = $this->ask('Forum title:');
|
||||||
$baseUrl = $this->baseUrl ?: 'http://localhost';
|
$baseUrl = $this->baseUrl ?: 'http://localhost';
|
||||||
|
@ -102,14 +113,14 @@ class UserDataProvider implements DataProviderInterface
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function ask($question, $default = null)
|
private function ask($question, $default = null)
|
||||||
{
|
{
|
||||||
$question = new Question("<question>$question</question> ", $default);
|
$question = new Question("<question>$question</question> ", $default);
|
||||||
|
|
||||||
return $this->questionHelper->ask($this->input, $this->output, $question);
|
return $this->questionHelper->ask($this->input, $this->output, $question);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function secret($question)
|
private function secret($question)
|
||||||
{
|
{
|
||||||
$question = new Question("<question>$question</question> ");
|
$question = new Question("<question>$question</question> ");
|
||||||
|
|
||||||
|
@ -118,14 +129,9 @@ class UserDataProvider implements DataProviderInterface
|
||||||
return $this->questionHelper->ask($this->input, $this->output, $question);
|
return $this->questionHelper->ask($this->input, $this->output, $question);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function validationError($message)
|
private function validationError($message)
|
||||||
{
|
{
|
||||||
$this->output->writeln("<error>$message</error>");
|
$this->output->writeln("<error>$message</error>");
|
||||||
$this->output->writeln('Please try again.');
|
$this->output->writeln('Please try again.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isDebugMode(): bool
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user