Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rvock committed Mar 28, 2016
2 parents f3084bf + 9e0b239 commit 8dfe341
Show file tree
Hide file tree
Showing 67 changed files with 120 additions and 7,054 deletions.
463 changes: 48 additions & 415 deletions README.md

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions bin/mysql-workbench-schema-export
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ const CMD_OPT_HELP = 'help';
function showTitle()
{
$version = FormatterInterface::VERSION;
$year = date('Y');
echo <<<EOF
MySQL Workbench Schema Exporter version $version.
Copyright (c) 2010-2014 Johannes Mueller <circus2@web.de>
Copyright (c) 2012-2014 Toha <tohenk@yahoo.com>
Copyright (c) 2010-{$year} Johannes Mueller <circus2@web.de>
Copyright (c) 2012-{$year} Toha <tohenk@yahoo.com>
EOF;
Expand All @@ -69,7 +70,7 @@ Usage:
$self [options] FILENAME [DEST]
Options:
--export=type Select the exporter, for a list of available exportor
--export=type Select the exporter, for a list of available exporter
use --list-exporter option.
--config=file Read file for export parameters, in JSON format.
--saveconfig Save export parameters to file.
Expand Down Expand Up @@ -200,6 +201,13 @@ function listFormatter($bootstrap, $ordered = false)
{
$i = 0;
$formatters = $bootstrap->getFormatters();
if (!$formatters) {
echo "ERROR: No formatters found. Formatters are separate projects which need to be installed via composer.\n";
echo " You can find all formatters at https://github.com/mysql-workbench-schema-exporter.\n";
echo " Example: \n";
echo " php composer.phar require --dev mysql-workbench-schema-exporter/doctrine2-exporter\n";
return [];
}
// find the longest formatter name
$len = max(array_map('strlen', array_keys($formatters))) + 1;
$nlen = strlen((string) count($formatters));
Expand Down Expand Up @@ -369,4 +377,4 @@ try {
die(1);
}

// ----------------------------------------- EOF ----------------------------------------------------- //
// ----------------------------------------- EOF ----------------------------------------------------- //
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"zend",
"sequelizejs"
],
"homepage" : "https://github.com/johmue/mysql-workbench-schema-exporter",
"homepage" : "https://github.com/mysql-workbench-schema-exporter/mysql-workbench-schema-exporter",
"license" : "MIT",
"authors" : [{
"name" : "Johannes Mueller",
Expand All @@ -23,12 +23,15 @@
"name" : "Toha",
"email" : "tohenk@yahoo.com",
"role" : "Developer"
}, {
"name" : "Robert Vock",
"email" : "robertvock82@gmail.com",
"role" : "Developer"
}
],
"require" : {
"php" : ">=5.3.0",
"doctrine/inflector" : "1.0.*@dev",
"symfony/yaml" : "2.5.*@dev"
"php" : ">=5.4.0",
"doctrine/inflector" : "^1.0.0"
},
"bin" : [
"bin/mysql-workbench-schema-export",
Expand All @@ -39,4 +42,4 @@
"MwbExporter\\" : "lib/"
}
}
}
}
73 changes: 50 additions & 23 deletions lib/MwbExporter/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,45 @@ class Bootstrap
*
* @return array
*/
public function getFormatters()
{
if (null === self::$formatters) {
self::$formatters = array();
$pattern = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Formatter', '*', '*', 'Formatter.php'));
foreach (glob($pattern) as $filename) {
$dirs = explode(DIRECTORY_SEPARATOR, dirname(realpath($filename)));
$subVendor = array_pop($dirs);
$vendor = array_pop($dirs);
$formatter = strtolower(implode('-', array($vendor, $subVendor)));
$formatterClass = sprintf('\\MwbExporter\\Formatter\\%s\\%s\\Formatter', $vendor, $subVendor);
self::$formatters[$formatter] = $formatterClass;
}
}

return self::$formatters;
}
public function getFormatters()
{
if (null === self::$formatters) {
self::$formatters = array();
$DS = DIRECTORY_SEPARATOR;
$pattern = implode($DS, array(__DIR__, 'Formatter', '*', '*', 'Formatter.php'));

// check if mwbse is installed via composer
if (strpos($pattern, 'vendor' . $DS . 'mysql-workbench-schema-exporter' . $DS) !== false) {
$pattern = str_replace('mysql-workbench-schema-exporter' . $DS . 'mysql-workbench-schema-exporter' . $DS, 'mysql-workbench-schema-exporter' . $DS . '*' . $DS, $pattern);
}
foreach (glob($pattern) as $filename) {
$dirs = explode(DIRECTORY_SEPARATOR, dirname(realpath($filename)));
$subVendor = array_pop($dirs);
$vendor = array_pop($dirs);
$formatter = strtolower(implode('-', array($vendor, $subVendor)));
$formatterClass = sprintf('\\MwbExporter\\Formatter\\%s\\%s\\Formatter', $vendor, $subVendor);
self::$formatters[$formatter] = $formatterClass;
}

if ($position = strpos(__DIR__, 'vendor' . $DS . 'mysql-workbench-schema-exporter' . $DS)) {
// possibly executed via composer. There might be more exporters in the current project
$currentProject = substr(__DIR__, 0, $position);

$pattern = implode($DS, array($currentProject, 'lib', 'MwbExporter', 'Formatter', '*', '*', 'Formatter.php'));

foreach (glob($pattern) as $filename) {
$dirs = explode(DIRECTORY_SEPARATOR, dirname(realpath($filename)));
$subVendor = array_pop($dirs);
$vendor = array_pop($dirs);
$formatter = strtolower(implode('-', array($vendor, $subVendor)));
$formatterClass = sprintf('\\MwbExporter\\Formatter\\%s\\%s\\Formatter', $vendor, $subVendor);
self::$formatters[$formatter] = $formatterClass;
}
}
}

return self::$formatters;
}

/**
* Get formatter.
Expand All @@ -74,16 +96,21 @@ public function getFormatter($name)
{
$formatters = $this->getFormatters();
if (!array_key_exists($name, $formatters)) {
throw new \InvalidArgumentException(sprintf('Unknown formatter "%s".', $name));
list($vendor, $subVendor) = explode('-', $name, 2);
$class = 'MwbExporter\\Formatter\\' . ucfirst(strtolower($vendor)) . '\\' . ucfirst(strtolower($subVendor)) . '\\Formatter';
if (!class_exists($class)) {
throw new \InvalidArgumentException(sprintf('Unknown formatter "%s".', $name));
}
} else {
$class = $formatters[$name];
}
$class = $formatters[$name];

return new $class($name);
}

/**
* Get writer.
*
*
* @param string $name The writer name
* @return \MwbExporter\Writer\WriterInterface
*/
Expand All @@ -101,7 +128,7 @@ public function getWriter($name)

/**
* Get storage.
*
*
* @param string $name The storage name
* @return \MwbExporter\Storage\StorageInterface
*/
Expand Down Expand Up @@ -133,7 +160,7 @@ public function export(FormatterInterface $formatter, $filename, $outDir, $stora
}
if ($formatter && $storage = $this->getStorage($storage)) {
if ($formatter->getRegistry()->config->get(FormatterInterface::CFG_USE_LOGGED_STORAGE)) {
$storage = new LoggedStorage($storage);
$storage = new LoggedStorage($storage);
}
$storage->setName(basename($filename, '.mwb'));
$storage->setOutdir(realpath($outDir) ? realpath($outDir) : $outDir);
Expand Down Expand Up @@ -169,4 +196,4 @@ public function export(FormatterInterface $formatter, $filename, $outDir, $stora
return $document;
}
}
}
}
96 changes: 0 additions & 96 deletions lib/MwbExporter/Formatter/Doctrine1/DatatypeConverter.php

This file was deleted.

51 changes: 0 additions & 51 deletions lib/MwbExporter/Formatter/Doctrine1/Formatter.php

This file was deleted.

48 changes: 0 additions & 48 deletions lib/MwbExporter/Formatter/Doctrine1/Yaml/DatatypeConverter.php

This file was deleted.

Loading

0 comments on commit 8dfe341

Please sign in to comment.