3 namespace wcf\system\devtools
;
5 use wcf\system\SingletonFactory
;
10 * Enables the rapid deployment of new installations using a central configuration file
11 * in the document root. Requires the developer mode to work.
13 * @author Alexander Ebert
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Devtools\Package
19 class DevtoolsSetup
extends SingletonFactory
22 * configuration file in the server's document root
25 const CONFIGURATION_FILE
= 'wsc-dev-config-53.json';
31 protected $configuration = [];
36 protected function init()
38 if (empty($_SERVER['DOCUMENT_ROOT'])) {
42 $docRoot = FileUtil
::addTrailingSlash(FileUtil
::unifyDirSeparator($_SERVER['DOCUMENT_ROOT']));
43 if (!\file_exists
($docRoot . self
::CONFIGURATION_FILE
)) {
47 $contents = \file_get_contents
($docRoot . self
::CONFIGURATION_FILE
);
49 // allow the exception to go rampage
50 $this->configuration
= JSON
::decode($contents);
54 * Returns the database configuration.
58 public function getDatabaseConfig()
60 if (!isset($this->configuration
['setup']) ||
!isset($this->configuration
['setup']['database'])) {
64 // dirname return a single backslash on Windows if there are no parent directories
65 $dir = \
dirname($_SERVER['SCRIPT_NAME']);
66 $dir = ($dir === '\\') ?
'/' : FileUtil
::addTrailingSlash($dir);
68 throw new \
RuntimeException("Refusing to install in the document root.");
71 $dir = FileUtil
::removeLeadingSlash(FileUtil
::removeTrailingSlash($dir));
72 $dbName = \
implode('_', \
explode('/', $dir));
74 $dbConfig = $this->configuration
['setup']['database'];
77 'auto' => $dbConfig['auto'],
78 'host' => $dbConfig['host'],
79 'password' => $dbConfig['password'],
80 'username' => $dbConfig['username'],
82 'dbNumber' => $dbConfig['dbNumber'],
87 * Returns true if the suggested default paths for the Core and, if exists,
88 * the bundled app should be used.
92 public function useDefaultInstallPath()
94 return isset($this->configuration
['setup']) && isset($this->configuration
['setup']['useDefaultInstallPath']) && $this->configuration
['setup']['useDefaultInstallPath'] === true;
98 * Returns true if a static cookie prefix should be used, instead of the randomized
99 * value used for non-dev-mode installations.
103 public function forceStaticCookiePrefix()
105 return isset($this->configuration
['setup']) && isset($this->configuration
['setup']['forceStaticCookiePrefix']) && $this->configuration
['setup']['forceStaticCookiePrefix'] === true;
109 * List of option values that will be set after the setup has completed.
113 public function getOptionOverrides()
115 if (!isset($this->configuration
['configuration']) ||
empty($this->configuration
['configuration']['option'])) {
119 if (isset($this->configuration
['configuration']['option']['cookie_prefix'])) {
120 throw new \
DomainException("The 'cookie_prefix' option cannot be set during the setup, consider using the 'forceStaticCookiePrefix' setting instead.");
123 return $this->configuration
['configuration']['option'];
127 * Returns a list of users that should be automatically created during setup.
129 * @return array|\Generator
131 public function getUsers()
133 if (empty($this->configuration
['user'])) {
137 foreach ($this->configuration
['user'] as $user) {
138 if ($user['username'] === 'root') {
139 throw new \
LogicException("The 'root' user is automatically created.");
143 'username' => $user['username'],
144 'password' => $user['password'],
145 'email' => $user['email'],
151 * Returns the base path for projects that should be automatically imported.
155 public function getDevtoolsImportPath()
157 return (isset($this->configuration
['configuration']['devtools']) && !empty($this->configuration
['configuration']['devtools']['importFromPath'])) ?
$this->configuration
['configuration']['devtools']['importFromPath'] : '';
161 * Returns the raw configuration data.
165 public function getRawConfiguration()
167 return $this->configuration
;