Ejemplo n.º 1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param Compressor $compressor
  *
  * @return string
  */
 protected function getFileName(InputInterface $input, OutputInterface $output, Compressor $compressor)
 {
     $namePrefix = '';
     $nameSuffix = '';
     if ($input->getOption('xml')) {
         $nameExtension = '.xml';
     } else {
         $nameExtension = '.sql';
     }
     if ($input->getOption('add-time') !== false) {
         $timeStamp = date('Y-m-d_His');
         if ($input->getOption('add-time') == 'suffix') {
             $nameSuffix = '_' . $timeStamp;
         } else {
             $namePrefix = $timeStamp . '_';
         }
     }
     if ((($fileName = $input->getArgument('filename')) === null || ($isDir = is_dir($fileName))) && !$input->getOption('stdout')) {
         /** @var DialogHelper $dialog */
         $dialog = $this->getHelper('dialog');
         $defaultName = VerifyOrDie::filename($namePrefix . $this->dbSettings['dbname'] . $nameSuffix . $nameExtension);
         if (isset($isDir) && $isDir) {
             $defaultName = rtrim($fileName, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $defaultName;
         }
         if (!$input->getOption('force')) {
             $fileName = $dialog->ask($output, '<question>Filename for SQL dump:</question> [<comment>' . $defaultName . '</comment>]', $defaultName);
         } else {
             $fileName = $defaultName;
         }
     } else {
         if ($input->getOption('add-time')) {
             $pathParts = pathinfo($fileName);
             $fileName = ($pathParts['dirname'] == '.' ? '' : $pathParts['dirname'] . DIRECTORY_SEPARATOR) . $namePrefix . $pathParts['filename'] . $nameSuffix . '.' . $pathParts['extension'];
         }
     }
     $fileName = $compressor->getFileName($fileName);
     return $fileName;
 }