Change base URL etc. in config.php file

This commit is contained in:
Franz Liedke 2015-08-27 00:47:54 +02:00
parent 6e52762b7a
commit dafb4c06bc
10 changed files with 46 additions and 17 deletions

View File

@ -34,10 +34,10 @@ class ForumSerializer extends Serializer
{
$attributes = [
'title' => Core::config('forum_title'),
'baseUrl' => Core::config('base_url'),
'basePath' => parse_url(Core::config('base_url'), PHP_URL_PATH) ?: '',
'baseUrl' => Core::url(),
'basePath' => parse_url(Core::url(), PHP_URL_PATH) ?: '',
'debug' => Core::inDebugMode(),
'apiUrl' => Core::config('api_url'),
'apiUrl' => Core::url('api'),
'welcomeTitle' => Core::config('welcome_title'),
'welcomeMessage' => Core::config('welcome_message'),
'themePrimaryColor' => Core::config('theme_primary_color'),
@ -48,7 +48,7 @@ class ForumSerializer extends Serializer
];
if ($this->actor->isAdmin()) {
$attributes['adminUrl'] = Core::config('admin_url');
$attributes['adminUrl'] = Core::url('admin');
}
return $attributes;

View File

@ -30,4 +30,15 @@ class Core
return app('Flarum\Core\Settings\SettingsRepository')->get($key, $default);
}
public static function url($name = null)
{
$url = static::config('url');
if ($name) {
$url .= '/' . static::config("paths.$name");
}
return $url;
}
}

View File

@ -76,7 +76,7 @@ class RequestPasswordResetHandler
// password route be part of core??
$data = [
'username' => $user->username,
'url' => $this->settings->get('base_url').'/reset/'.$token->id,
'url' => Core::url().'/reset/'.$token->id,
'forumTitle' => $this->settings->get('forum_title'),
];

View File

@ -108,7 +108,7 @@ class EmailConfirmationMailer
// email route be part of core??
return [
'username' => $user->username,
'url' => $this->settings->get('base_url').'/confirm/'.$token->id,
'url' => Core::url().'/confirm/'.$token->id,
'forumTitle' => $this->settings->get('forum_title')
];
}

View File

@ -70,10 +70,8 @@ class InstallAction extends Action
]);
$baseUrl = rtrim((string) $request->getAttribute('originalUri'), '/');
$data->setBaseUrl($baseUrl);
$data->setSetting('admin_url', $baseUrl . '/admin');
$data->setSetting('api_url', $baseUrl . '/api.php');
$data->setSetting('base_url', $baseUrl);
$data->setSetting('forum_title', array_get($input, 'forumTitle'));
$data->setSetting('mail_from', 'noreply@' . preg_replace('/^www\./i', '', parse_url($baseUrl, PHP_URL_HOST)));
$data->setSetting('welcome_title', 'Welcome to ' . array_get($input, 'forumTitle'));

View File

@ -24,6 +24,8 @@ class DataFromUser implements ProvidesData
protected $questionHelper;
protected $baseUrl;
public function __construct(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper)
{
@ -44,6 +46,11 @@ class DataFromUser implements ProvidesData
];
}
public function getBaseUrl()
{
return $this->baseUrl = rtrim($this->ask('Base URL:'), '/');
}
public function getAdminUser()
{
return [
@ -55,16 +62,13 @@ class DataFromUser implements ProvidesData
public function getSettings()
{
$baseUrl = rtrim($this->ask('Base URL:'), '/');
$title = $this->ask('Forum title:');
$baseUrl = $this->baseUrl ?: 'http://localhost';
return [
'admin_url' => $baseUrl . '/admin',
'allow_post_editing' => 'reply',
'allow_renaming' => '10',
'allow_sign_up' => '1',
'api_url' => $baseUrl . '/api.php',
'base_url' => $baseUrl,
'custom_less' => '',
'default_locale' => 'en',
'default_route' => '/all',

View File

@ -21,6 +21,8 @@ class DefaultData implements ProvidesData
'prefix' => '',
];
protected $baseUrl = 'http://flarum.dev';
protected $adminUser = [
'username' => 'admin',
'password' => 'admin',
@ -28,12 +30,9 @@ class DefaultData implements ProvidesData
];
protected $settings = [
'admin_url' => 'http://flarum.dev/admin',
'allow_post_editing' => 'reply',
'allow_renaming' => '10',
'allow_sign_up' => '1',
'api_url' => 'http://flarum.dev/api.php',
'base_url' => 'http://flarum.dev',
'custom_less' => '',
'default_locale' => 'en',
'default_route' => '/all',
@ -60,6 +59,16 @@ class DefaultData implements ProvidesData
$this->databaseConfiguration = $databaseConfiguration;
}
public function getBaseUrl()
{
return $this->baseUrl;
}
public function setBaseUrl($baseUrl)
{
$this->baseUrl = $baseUrl;
}
public function getAdminUser()
{
return $this->adminUser;

View File

@ -129,6 +129,11 @@ class InstallCommand extends Command
'prefix' => $dbConfig['prefix'],
'strict' => false
],
'url' => $this->dataSource->getBaseUrl(),
'paths' => [
'api' => 'api',
'admin' => 'admin',
],
];
$this->info('Testing config');

View File

@ -14,6 +14,8 @@ interface ProvidesData
{
public function getDatabaseConfiguration();
public function getBaseUrl();
public function getAdminUser();
public function getSettings();

View File

@ -38,7 +38,7 @@ abstract class Action
*/
protected function redirectTo($url)
{
$url = Core::config('base_url') . $url;
$url = Core::url() . $url;
$content = sprintf('
<!DOCTYPE html>