From dafb4c06bc12c3b61943d4a440dbdd37717d42c3 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 27 Aug 2015 00:47:54 +0200 Subject: [PATCH] Change base URL etc. in config.php file --- .../core/src/Api/Serializers/ForumSerializer.php | 8 ++++---- framework/core/src/Core.php | 11 +++++++++++ .../Commands/RequestPasswordResetHandler.php | 2 +- .../Users/Listeners/EmailConfirmationMailer.php | 2 +- .../core/src/Install/Actions/InstallAction.php | 4 +--- .../core/src/Install/Console/DataFromUser.php | 12 ++++++++---- .../core/src/Install/Console/DefaultData.php | 15 ++++++++++++--- .../core/src/Install/Console/InstallCommand.php | 5 +++++ .../core/src/Install/Console/ProvidesData.php | 2 ++ framework/core/src/Support/Action.php | 2 +- 10 files changed, 46 insertions(+), 17 deletions(-) diff --git a/framework/core/src/Api/Serializers/ForumSerializer.php b/framework/core/src/Api/Serializers/ForumSerializer.php index 799a5d95b..a77dd6a2a 100644 --- a/framework/core/src/Api/Serializers/ForumSerializer.php +++ b/framework/core/src/Api/Serializers/ForumSerializer.php @@ -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; diff --git a/framework/core/src/Core.php b/framework/core/src/Core.php index 702f2a852..63b0cd19d 100644 --- a/framework/core/src/Core.php +++ b/framework/core/src/Core.php @@ -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; + } } diff --git a/framework/core/src/Core/Users/Commands/RequestPasswordResetHandler.php b/framework/core/src/Core/Users/Commands/RequestPasswordResetHandler.php index d09338e21..505885734 100644 --- a/framework/core/src/Core/Users/Commands/RequestPasswordResetHandler.php +++ b/framework/core/src/Core/Users/Commands/RequestPasswordResetHandler.php @@ -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'), ]; diff --git a/framework/core/src/Core/Users/Listeners/EmailConfirmationMailer.php b/framework/core/src/Core/Users/Listeners/EmailConfirmationMailer.php index 06b8b3513..7e94f4f7f 100755 --- a/framework/core/src/Core/Users/Listeners/EmailConfirmationMailer.php +++ b/framework/core/src/Core/Users/Listeners/EmailConfirmationMailer.php @@ -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') ]; } diff --git a/framework/core/src/Install/Actions/InstallAction.php b/framework/core/src/Install/Actions/InstallAction.php index 982dcc3fe..695085b61 100644 --- a/framework/core/src/Install/Actions/InstallAction.php +++ b/framework/core/src/Install/Actions/InstallAction.php @@ -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')); diff --git a/framework/core/src/Install/Console/DataFromUser.php b/framework/core/src/Install/Console/DataFromUser.php index d9d149f2d..8c0fb4b37 100644 --- a/framework/core/src/Install/Console/DataFromUser.php +++ b/framework/core/src/Install/Console/DataFromUser.php @@ -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', diff --git a/framework/core/src/Install/Console/DefaultData.php b/framework/core/src/Install/Console/DefaultData.php index eb0a9ae1a..787f55c25 100644 --- a/framework/core/src/Install/Console/DefaultData.php +++ b/framework/core/src/Install/Console/DefaultData.php @@ -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; diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 8864a1f23..d185a0a35 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -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'); diff --git a/framework/core/src/Install/Console/ProvidesData.php b/framework/core/src/Install/Console/ProvidesData.php index 48e07503f..8a5c6144e 100644 --- a/framework/core/src/Install/Console/ProvidesData.php +++ b/framework/core/src/Install/Console/ProvidesData.php @@ -14,6 +14,8 @@ interface ProvidesData { public function getDatabaseConfiguration(); + public function getBaseUrl(); + public function getAdminUser(); public function getSettings(); diff --git a/framework/core/src/Support/Action.php b/framework/core/src/Support/Action.php index 5442f70e0..85264e756 100644 --- a/framework/core/src/Support/Action.php +++ b/framework/core/src/Support/Action.php @@ -38,7 +38,7 @@ abstract class Action */ protected function redirectTo($url) { - $url = Core::config('base_url') . $url; + $url = Core::url() . $url; $content = sprintf('