/** * setDatabase * Set info for database configuration * @param string $dir The application's root directory. * @param \Composer\IO\IOInterface $io IO interface to write to console. * @return boolean */ public static function setDatabase($dir, $io) { $config = $dir . '/config/app.php'; $content = file_get_contents($config); static::$_databaseName = $databaseName = $io->ask('What is your new database name ? [<comment>Ticki</comment>] ', 'Ticki'); $content = str_replace('_DATABASENAME_', $databaseName, $content, $count); if ($count == 0) { $io->write('No Datasources.default.database placeholder to replace.'); return false; } $result = file_put_contents($config, $content); if (!$result) { $io->write('Unable to update Datasources.default.database value.'); return false; } $io->write('Updated Datasources.default.database value in config/app.php'); static::$_hostName = $hostName = $io->ask('What is your database host ip ? [<comment>localhost</comment>] ', 'localhost'); $content = str_replace('_HOST_', $hostName, $content, $count); if ($count == 0) { $io->write('No Datasources.default.host placeholder to replace.'); return false; } $result = file_put_contents($config, $content); if (!$result) { $io->write('Unable to update Datasources.default.host value.'); return false; } $io->write('Updated Datasources.default.host value in config/app.php'); static::$_port = $port = $io->ask('What is your database port number ?[<comment>leave empty for no port</comment>] ', ''); if (empty($port)) { $content = str_replace('_PORT_', '', $content); static::$_port = false; } else { $content = str_replace('_PORT_', "'port' => " . $port . ",", $content); } $result = file_put_contents($config, $content); if (!$result) { $io->write('Unable to update Datasources.default.port value.'); return false; } $io->write('Updated Datasources.default.port value in config/app.php'); static::$_userName = $userName = $io->ask('What is your database login ? [<comment>root</comment>] ', 'root'); $content = str_replace('_USERNAME_', $userName, $content, $count); if ($count == 0) { $io->write('No Datasources.default.username placeholder to replace.'); return false; } $result = file_put_contents($config, $content); if (!$result) { $io->write('Unable to update Datasources.default.username value.'); return false; } $io->write('Updated Datasources.default.username value in config/app.php'); static::$_password = $password = $io->ask('What is your database password ? ', ''); $content = str_replace('_PASSWORD_', $password, $content, $count); $result = file_put_contents($config, $content); if (!$result) { $io->write('Unable to update Datasources.default.password value.'); return false; } $io->write('Updated Datasources.default.password value in config/app.php'); return true; }
/** * @param string $userName * * @return void */ public static function setUserName($userName) { static::$_userName = $userName; }