protected function loadUserDatatypes()
 {
     $dataTypeConverter = $this->formatter->getDataTypeConverter();
     $dataTypes = array();
     $userTypes = $this->node->xpath("//value[@key='userDatatypes']")[0];
     foreach ($userTypes as $userType) {
         $dataTypes[(string) $userType['id']] = $dataTypeConverter->getDataType((string) $userType->xpath("link[@key='actualType']")[0]);
     }
     $dataTypeConverter->registerUserDatatypes($dataTypes);
 }
 /**
  * @param $fromFile
  * @param $toFile
  */
 private function createWorkModelClass($fromFile, $toFile)
 {
     $fromFileContent = file_get_contents($fromFile);
     $toFileContent = preg_replace('/Model\\\\/', '', $fromFileContent);
     $toFileContent = preg_replace('/\\\\Model/', '', $toFileContent);
     $toFileContent = preg_replace('/(class) ([^\\s]+)/', '\\1 \\2 extends Model\\\\\\2', $toFileContent);
     file_put_contents($toFile, $toFileContent);
     $this->removeUse($toFile);
     $this->removeORMAnatation($toFile);
     $this->removeClassBody($toFile);
     $this->createRepository($toFile, $this->formatter->getRegistry()->config->get(FormatterInterface::CFG_BASE_NAMESPASE));
 }
 /**
  * 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;
     }
 }
 /**
  * Get reference object.
  *
  * @return \MwbExporter\Registry\RegistryHolder
  */
 public function getReference()
 {
     return $this->formatter->getRegistry()->reference;
 }
 /**
  * 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;
     }
 }