Permalink
Browse files

Fix Propel writer not opened and enhance error handling in document, …

…fix #72.

Signed-off-by: Toha <tohenk@yahoo.com>
  • Loading branch information...
1 parent b3a3958 commit f49ba6e31b2d4447ce2e8604a9d3b96f67e61683 @tohenk tohenk committed Oct 23, 2012
@@ -33,28 +33,15 @@
// enable autoloading of classes
autoload();
-use \MwbExporter\Bootstrap;
use \MwbExporter\Formatter\Doctrine1\Yaml\Formatter;
-// lets stop the time
-$start = microtime(true);
-
// formatter setup
$setup = array(
Formatter::CFG_USE_LOGGED_STORAGE => true,
Formatter::CFG_INDENTATION => 2,
Formatter::CFG_FILENAME => '%entity%.%extension%',
Formatter::CFG_EXTEND_TABLENAME_WITH_SCHEMA => false,
);
-$filename = __DIR__.'/data/sakila.mwb';
-$outDir = __DIR__.'/result';
-
-$bootstrap = new Bootstrap();
-$formatter = $bootstrap->getFormatter('doctrine1-yaml');
-$formatter->setup($setup);
-$document = $bootstrap->export($formatter, $filename, $outDir, 'zip');
-
-// show the time needed to parse the mwb file
-$end = microtime(true);
-output($document, $end - $start);
+// lets do it
+export('doctrine1-yaml', $setup);
@@ -33,12 +33,8 @@
// enable autoloading of classes
autoload();
-use \MwbExporter\Bootstrap;
use \MwbExporter\Formatter\Doctrine2\Annotation\Formatter;
-// lets stop the time
-$start = microtime(true);
-
// formatter setup
$setup = array(
Formatter::CFG_USE_LOGGED_STORAGE => true,
@@ -51,15 +47,6 @@
Formatter::CFG_AUTOMATIC_REPOSITORY => true,
Formatter::CFG_SKIP_GETTER_SETTER => false,
);
-$filename = __DIR__.'/data/sakila.mwb';
-$outDir = __DIR__.'/result';
-
-$bootstrap = new Bootstrap();
-$formatter = $bootstrap->getFormatter('doctrine2-annotation');
-$formatter->setup($setup);
-$document = $bootstrap->export($formatter, $filename, $outDir, 'zip');
-
-// show the time needed to parse the mwb file
-$end = microtime(true);
-output($document, $end - $start);
+// lets do it
+export('doctrine2-annotation', $setup);
@@ -33,12 +33,8 @@
// enable autoloading of classes
autoload();
-use \MwbExporter\Bootstrap;
use \MwbExporter\Formatter\Doctrine2\Yaml\Formatter;
-// lets stop the time
-$start = microtime(true);
-
// formatter setup
$setup = array(
Formatter::CFG_USE_LOGGED_STORAGE => true,
@@ -50,15 +46,6 @@
Formatter::CFG_EXTEND_TABLENAME_WITH_SCHEMA => false,
Formatter::CFG_AUTOMATIC_REPOSITORY => true,
);
-$filename = __DIR__.'/data/sakila.mwb';
-$outDir = __DIR__.'/result';
-
-$bootstrap = new Bootstrap();
-$formatter = $bootstrap->getFormatter('doctrine2-yaml');
-$formatter->setup($setup);
-$document = $bootstrap->export($formatter, $filename, $outDir, 'zip');
-
-// show the time needed to parse the mwb file
-$end = microtime(true);
-output($document, $end - $start);
+// lets do it
+export('doctrine2-yaml', $setup);
@@ -33,29 +33,15 @@
// enable autoloading of classes
autoload();
-use \MwbExporter\Bootstrap;
use \MwbExporter\Formatter\Propel1\Xml\Formatter;
-// lets stop the time
-$start = microtime(true);
-
// formatter setup
$setup = array(
Formatter::CFG_USE_LOGGED_STORAGE => true,
Formatter::CFG_INDENTATION => 4,
Formatter::CFG_ADD_VENDOR => false,
Formatter::CFG_NAMESPACE => 'Acme\Namespace',
-
);
-$filename = __DIR__.'/data/sakila.mwb';
-$outDir = __DIR__.'/result';
-
-$bootstrap = new Bootstrap();
-$formatter = $bootstrap->getFormatter('propel1-xml');
-$formatter->setup($setup);
-$document = $bootstrap->export($formatter, $filename, $outDir, 'zip');
-
-// show the time needed to parse the mwb file
-$end = microtime(true);
-output($document, $end - $start);
+// lets do it
+export('propel1-xml', $setup);
@@ -33,18 +33,15 @@
// enable autoloading of classes
autoload();
-use \MwbExporter\Bootstrap;
use \MwbExporter\Formatter\Propel1\Xml\Formatter as PropelFormatter;
use \MwbExporter\Formatter\Doctrine2\Annotation\Formatter as DoctrineFormatter;
-// lets stop the time
-$start = microtime(true);
-
/**********************************************
* *
* start generation for Propel1 Xml Formatter *
* *
**********************************************/
+
$setup = array(
PropelFormatter::CFG_USE_LOGGED_STORAGE => true,
PropelFormatter::CFG_INDENTATION => 4,
@@ -53,19 +50,8 @@
);
-$filename = __DIR__.'/data/sakila.mwb';
-$outDir = __DIR__.'/result';
-
-$bootstrap = new Bootstrap();
-
-$formatter = $bootstrap->getFormatter('propel1-xml');
-$formatter->setup($setup);
-$document1 = $bootstrap->export($formatter, $filename, $outDir, 'zip');
-
-// show the time needed to parse the mwb file
-$end = microtime(true);
-output($document1, $end - $start); // output Propel1 Xml
-
+// lets do it
+export('propel1-xml', $setup);
/*******************************************************
* *
@@ -84,10 +70,6 @@
DoctrineFormatter::CFG_AUTOMATIC_REPOSITORY => true,
DoctrineFormatter::CFG_SKIP_GETTER_SETTER => false,
);
-$formatter = $bootstrap->getFormatter('doctrine2-annotation');
-$formatter->setup($setup);
-$document2 = $bootstrap->export($formatter, $filename, $outDir, 'zip');
-// show the time needed to parse the mwb file
-$end = microtime(true);
-output($document2, $end - $start); // output Doctrine2 Annotation
+// lets do it again
+export('doctrine2-annotation', $setup);
@@ -33,12 +33,8 @@
// enable autoloading of classes
autoload();
-use \MwbExporter\Bootstrap;
use \MwbExporter\Formatter\Sencha\ExtJS3\Formatter;
-// lets stop the time
-$start = microtime(true);
-
// formatter setup
$setup = array(
Formatter::CFG_USE_LOGGED_STORAGE => true,
@@ -47,15 +43,6 @@
Formatter::CFG_CLASS_PREFIX => 'SysX.App',
Formatter::CFG_PARENT_CLASS => 'SysX.Ui.App',
);
-$filename = __DIR__.'/data/sakila.mwb';
-$outDir = __DIR__.'/result';
-
-$bootstrap = new Bootstrap();
-$formatter = $bootstrap->getFormatter('sencha-extjs3');
-$formatter->setup($setup);
-$document = $bootstrap->export($formatter, $filename, $outDir, 'zip');
-
-// show the time needed to parse the mwb file
-$end = microtime(true);
-output($document, $end - $start);
+// lets do it
+export('sencha-extjs3', $setup);
View
@@ -58,4 +58,31 @@ function output($document, $time)
} else {
echo "<p>Export not performed, please review your code.</p>\n";
}
-}
+}
+
+function export($target, $setup = array())
+{
+ try {
+ // lets stop the time
+ $start = microtime(true);
+ $filename = __DIR__.'/data/sakila.mwb';
+ $outDir = __DIR__.'/result';
+
+ $bootstrap = new \MwbExporter\Bootstrap();
+ $formatter = $bootstrap->getFormatter($target);
+ $formatter->setup($setup);
+ $document = $bootstrap->export($formatter, $filename, $outDir, 'zip');
+
+ // show the time needed to parse the mwb file
+ $end = microtime(true);
+
+ output($document, $end - $start);
+
+ return $document;
+ } catch (\Exception $e) {
+ echo "<h2>Error:</h2>\n";
+ echo "<textarea cols=\"100\" rows=\"5\">\n";
+ echo $e->getMessage()."\n";
+ echo "</textarea>\n";
+ }
+}
@@ -33,12 +33,8 @@
// enable autoloading of classes
autoload();
-use \MwbExporter\Bootstrap;
use \MwbExporter\Formatter\Zend\DbTable\Formatter;
-// lets stop the time
-$start = microtime(true);
-
// formatter setup
$setup = array(
Formatter::CFG_USE_LOGGED_STORAGE => true,
@@ -49,15 +45,6 @@
Formatter::CFG_GENERATE_DRI => false,
Formatter::CFG_GENERATE_GETTER_SETTER => false,
);
-$filename = __DIR__.'/data/sakila.mwb';
-$outDir = __DIR__.'/result';
-
-$bootstrap = new Bootstrap();
-$formatter = $bootstrap->getFormatter('zend-dbtable');
-$formatter->setup($setup);
-$document = $bootstrap->export($formatter, $filename, $outDir, 'zip');
-
-// show the time needed to parse the mwb file
-$end = microtime(true);
-output($document, $end - $start);
+// lets do it
+export('zend-dbtable', $setup);
@@ -33,12 +33,8 @@
// enable autoloading of classes
autoload();
-use \MwbExporter\Bootstrap;
use \MwbExporter\Formatter\Zend\Controller\Formatter;
-// lets stop the time
-$start = microtime(true);
-
// formatter setup
$setup = array(
Formatter::CFG_USE_LOGGED_STORAGE => true,
@@ -47,15 +43,6 @@
Formatter::CFG_TABLE_PREFIX => '',
Formatter::CFG_PARENT_TABLE => 'Zend_Rest_Controller',
);
-$filename = __DIR__.'/data/sakila.mwb';
-$outDir = __DIR__.'/result';
-
-$bootstrap = new Bootstrap();
-$formatter = $bootstrap->getFormatter('zend-rest-controller');
-$formatter->setup($setup);
-$document = $bootstrap->export($formatter, $filename, $outDir, 'zip');
-
-// show the time needed to parse the mwb file
-$end = microtime(true);
-output($document, $end - $start);
+// lets do it
+export('zend-rest-controller', $setup);
@@ -212,7 +212,10 @@ public function export(FormatterInterface $formatter, $filename, $outDir, $stora
$writer->setStorage($storage);
$document = new Document($formatter, $filename);
$document->write($writer);
-
+ if ($e = $document->getError()) {
+ throw $e;
+ }
+
return $document;
}
}
@@ -26,8 +26,8 @@
namespace MwbExporter\Formatter\Propel1\Xml;
-use MwbExporter\Formatter\Propel1\DatatypeConverter as Base;
+use MwbExporter\Formatter\Propel1\DatatypeConverter as BaseDatatypeConverter;
-class DatatypeConverter extends Base
+class DatatypeConverter extends BaseDatatypeConverter
{
}
@@ -39,14 +39,23 @@ protected function init()
$this->setDatatypeConverter(new DatatypeConverter());
$this->addConfigurations(array(
static::CFG_INDENTATION => 4,
- static::CFG_FILENAME => 'schema.xml',
+ static::CFG_FILENAME => '%s.schema.xml',
static::CFG_NAMESPACE => '',
static::CFG_ADD_VENDOR => false,
));
}
/**
* (non-PHPdoc)
+ * @see MwbExporter.Formatter::createSchema()
+ */
+ public function createSchema(Base $parent, $node)
+ {
+ return new Model\Schema($parent, $node);
+ }
+
+ /**
+ * (non-PHPdoc)
* @see MwbExporter.Formatter::createTable()
*/
public function createTable(Base $parent, $node)
Oops, something went wrong.

0 comments on commit f49ba6e

Please sign in to comment.