public function __construct()
 {
     if (!\R::getDatabaseAdapter()) {
         $dbConfig = (require_once __DIR__ . '/cnf.php');
         static::$_host = $dbConfig['host'];
         static::$_dbname = $dbConfig['dbname'];
         static::$_user = $dbConfig['user'];
         static::$_password = $dbConfig['password'];
         \R::setup('mysql:host=' . static::$_host . ';dbname=' . static::$_dbname, static::$_user, static::$_password, true);
         //for both mysql or mariaDB
     }
     $this->_redbeans = \R::getToolBox()->getRedBean();
     $this->_rbToolbox = \R::getToolBox();
 }
Exemple #2
0
 /**
  * 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;
 }
Exemple #3
0
 /**
  * @param string $password
  *
  * @return void
  */
 public static function setPassword($password)
 {
     static::$_password = $password;
 }