Exemplo n.º 1
0
 /**
  * Open and read a configuration file.
  *
  * @param string $path Path to the configuration file
  */
 public function __construct($path)
 {
     if (!File::exists($path)) {
         throw new FilePDOBuilderException('Configuration file does not exists');
     }
     $this->file = new File($path);
     $str = $this->file->read();
     $array = explode("\n", $str);
     if (count($array) < 5) {
         throw new FilePDOBuilderException('Configuration file does not contains all required informations');
     }
     $this->setDriver($array[0]);
     $this->setDatabaseName($array[1]);
     $this->setHost($array[2]);
     $this->setUsername($array[3]);
     $this->setPassword($array[4]);
 }
Exemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = new File($input->hasOption('path') ? $input->getOption('path') : './app/pdo.cfg');
     /** @var QuestionHelper $helper */
     $helper = $this->getHelper('question');
     $question = new ChoiceQuestion('Please select your database driver', array('pgsql', 'mysql'));
     $driver = $helper->ask($input, $output, $question);
     $question = new Question('Please enter the name of your database : ');
     $database = $helper->ask($input, $output, $question);
     $question = new Question('Please enter the host of the database [localhost] : ', 'localhost');
     $host = $helper->ask($input, $output, $question);
     $question = new Question('Please enter the login of the database : ', '');
     $username = $helper->ask($input, $output, $question);
     $question = new Question('Please enter the password of the database (value hidden) : ', '');
     $question->setHidden(true);
     $question->setHiddenFallback(true);
     $pass = $helper->ask($input, $output, $question);
     $file->clear();
     $file->write($driver . PHP_EOL);
     $file->write($database . PHP_EOL);
     $file->write($host . PHP_EOL);
     $file->write($username . PHP_EOL);
     $file->write($pass . PHP_EOL);
 }