/**
  * Load workbench schema and generate the code.
  *
  * @param \MwbExporter\Formatter\FormatterInterface $formatter
  * @param string                                    $filename
  * @param string                                    $outDir
  * @param string                                    $storage
  *
  * @return \MwbExporter\Model\Document
  */
 public function export(FormatterInterface $formatter, $filename, $outDir, $storage = 'file')
 {
     if ($formatter && ($storage = $this->getStorage($storage))) {
         if ($formatter->getRegistry()->config->get(FormatterInterface::CFG_USE_LOGGED_STORAGE)) {
             $storage = new LoggedStorage($storage);
         }
         $storage->setOutdir(realpath($outDir) ? realpath($outDir) : $outDir);
         $storage->setBackup($formatter->getRegistry()->config->get(FormatterInterface::CFG_BACKUP_FILE));
         $writer = $this->getWriter($formatter->getPreferredWriter());
         $writer->setStorage($storage);
         $document = new Document($formatter, $filename);
         if (strlen($logFile = $formatter->getRegistry()->config->get(FormatterInterface::CFG_LOG_FILE))) {
             $logger = new LoggerFile(array('filename' => $logFile));
         } elseif ($formatter->getRegistry()->config->get(FormatterInterface::CFG_LOG_TO_CONSOLE)) {
             $logger = new LoggerConsole();
         } else {
             $logger = new Logger();
         }
         $document->setLogger($logger);
         $document->write($writer);
         if ($e = $document->getError()) {
             throw $e;
         }
         return $document;
     }
 }
 /**
  * Load workbench schema and generate the code.
  *
  * @param \MwbExporter\Formatter\FormatterInterface $formatter
  * @param string $filename
  * @param string $outDir
  * @param string $storage
  * @return \MwbExporter\Model\Document
  */
 public function export(FormatterInterface $formatter, $filename, $outDir, $storage = 'file')
 {
     if (!is_readable($filename)) {
         throw new \InvalidArgumentException(sprintf('Document not found "%s".', $filename));
     }
     if ($formatter && ($storage = $this->getStorage($storage))) {
         if ($formatter->getRegistry()->config->get(FormatterInterface::CFG_USE_LOGGED_STORAGE)) {
             $storage = new LoggedStorage($storage);
         }
         $storage->setName(basename($filename, '.mwb'));
         $storage->setOutdir(realpath($outDir) ? realpath($outDir) : $outDir);
         $storage->setBackup($formatter->getRegistry()->config->get(FormatterInterface::CFG_BACKUP_FILE));
         $writer = $this->getWriter($formatter->getPreferredWriter());
         $writer->setStorage($storage);
         if ($eol = strtolower(trim($formatter->getRegistry()->config->get(FormatterInterface::CFG_EOL)))) {
             switch ($eol) {
                 case FormatterInterface::EOL_WIN:
                     $writer->getBuffer()->setEol("\r\n");
                     break;
                 case FormatterInterface::EOL_UNIX:
                     $writer->getBuffer()->setEol("\n");
                     break;
             }
         }
         $document = new Document($formatter);
         if (strlen($logFile = $formatter->getRegistry()->config->get(FormatterInterface::CFG_LOG_FILE))) {
             $logger = new LoggerFile(array('filename' => $logFile));
         } elseif ($formatter->getRegistry()->config->get(FormatterInterface::CFG_LOG_TO_CONSOLE)) {
             $logger = new LoggerConsole();
         } else {
             $logger = new Logger();
         }
         $document->setLogger($logger);
         $document->load($filename);
         $document->write($writer);
         if ($e = $document->getError()) {
             throw $e;
         }
         return $document;
     }
 }