commit 5b54461ec8e82e967e048481be1a45fc6fa8aae8
parent 8f50b900c865cd29e299504d7f9440b0eb41fcb5
Author: Felicitus <felicitus@felicitus.org>
Date: Wed, 18 Jul 2012 02:49:08 +0200
Reworked CLI stuff in order to have a separate generate-proxy command as well as partkeepr-related commands separated from doctrine
Diffstat:
6 files changed, 122 insertions(+), 62 deletions(-)
diff --git a/build.xml b/build.xml
@@ -280,7 +280,6 @@
<exclude name="partkeepr.jsb3.template" />
<exclude name="pre-commit.hook" />
<exclude name="RELEASE-TODO" />
- <exclude name="doctrine.php" />
<exclude name="build.properties" />
<exclude name="build.xml" />
<exclude name="cli-config.php" />
@@ -350,8 +349,8 @@
<!-- Builds the jsb3 file and build the minified JS files -->
<target name="jsbuilder">
<property name="jsbuilder.sources" value="--source=${project.basedir}/3rdparty/extjs/examples/ux/TabCloseMenu.js --source=${project.basedir}/src/frontend/js --source=${project.basedir}/3rdparty/ext-wizard/Ext.ux.Wizard/ --source=${project.basedir}/3rdparty/Ext.ux.Exporter/ --source ${project.basedir}/3rdparty/extjs/examples/ux/statusbar/"/>
- <exec passthru="true" command="php doctrine.php partkeepr:js-minify ${project.basedir}/frontend/js/partkeepr-debug.js ${jsbuilder.sources}" />
- <exec passthru="true" command="php doctrine.php partkeepr:js-minify ${project.basedir}/frontend/js/partkeepr.js --compress ${jsbuilder.sources}" />
+ <exec passthru="true" command="php partkeepr.php partkeepr:js-minify ${project.basedir}/frontend/js/partkeepr-debug.js ${jsbuilder.sources}" />
+ <exec passthru="true" command="php partkeepr.php partkeepr:js-minify ${project.basedir}/frontend/js/partkeepr.js --compress ${jsbuilder.sources}" />
</target>
<!-- Checks all JavaScript files for common mistakes. Requires JSLint from http://www.javascriptlint.com -->
diff --git a/cli-config.php b/cli-config.php
@@ -1,8 +0,0 @@
-<?php
-use PartKeepr\PartKeepr;
-
-$helpers = array(
- 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper(PartKeepr::getEM()->getConnection()),
- 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper(PartKeepr::getEM())
-);
-
diff --git a/doctrine.php b/doctrine.php
@@ -1,59 +1,88 @@
<?php
namespace PartKeepr\Console;
-use PartKeepr\PartKeepr;
+use PartKeepr\PartKeepr,
+ PartKeepr\Util\Configuration as PartKeeprConfiguration;
include("src/backend/PartKeepr/PartKeepr.php");
-PartKeepr::initialize("");
-// Variable $helperSet is defined inside cli-config.php
-$helpers = array();
+PartKeepr::initializeClassLoaders();
+PartKeepr::initializeConfig();
-require __DIR__ . '/cli-config.php';
-
-$cli = new \Symfony\Component\Console\Application('PartKeepr Console', \PartKeepr\PartKeeprVersion::PARTKEEPR_VERSION);
+$cli = new \Symfony\Component\Console\Application('PartKeepr Doctrine Console', \PartKeepr\PartKeeprVersion::PARTKEEPR_VERSION);
$cli->setCatchExceptions(true);
-$helperSet = $cli->getHelperSet();
-foreach ($helpers as $name => $helper) {
- $helperSet->set($helper, $name);
-}
-$cli->addCommands(array(
- // DBAL Commands
- new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),
- new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),
-
- // ORM Commands
- new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(),
- new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(),
- new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(),
- new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(),
- new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(),
- new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(),
- new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(),
- new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(),
- new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(),
- new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(),
- new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(),
- new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(),
- new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(),
- new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(),
-
-));
-$cli->addCommands(array(
-// ...
+try {
+ PartKeepr::initializeDoctrine();
+
+ $helperSet = $cli->getHelperSet();
+
+ $helpers = array(
+ 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper(PartKeepr::getEM()->getConnection()),
+ 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper(PartKeepr::getEM())
+ );
+
+ foreach ($helpers as $name => $helper) {
+ $helperSet->set($helper, $name);
+ }
+
+ $cli->addCommands(array(
+ // DBAL Commands
+ new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),
+ new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(),
-// Migrations Commands
-new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
-new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
-new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
-new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
-new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
-new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
-));
+ // ORM Commands
+ new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(),
+ new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(),
+ ));
+
+ $cli->addCommands(array(
+ // Migrations Commands
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(),
+ new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()
+ ));
+
+} catch (\Exception $e) {
+ // Inject fake connection
+ PartKeeprConfiguration::setOption("partkeepr.database.driver", "pdo_sqlite");
+
+ PartKeepr::initializeDoctrine();
+
+ $helperSet = $cli->getHelperSet();
+
+ $helpers = array(
+ 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper(PartKeepr::getEM()->getConnection()),
+ 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper(PartKeepr::getEM())
+ );
+
+ foreach ($helpers as $name => $helper) {
+ $helperSet->set($helper, $name);
+ }
+
+ echo "\n";
+ echo "======================================================================================\n";
+ echo "Warning: Couldn't find a database configuration - disabling database-related commands.\n";
+ echo "======================================================================================\n\n";
+}
$cli->addCommands(array(
- new \PartKeepr\Console\Commands\MinifyJSCommand()
+ new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(),
-));
+ ));
$cli->run();
diff --git a/partkeepr.php b/partkeepr.php
@@ -0,0 +1,35 @@
+<?php
+namespace PartKeepr\Console;
+
+use PartKeepr\PartKeepr;
+
+include("src/backend/PartKeepr/PartKeepr.php");
+
+PartKeepr::initializeClassLoaders();
+PartKeepr::initializeConfig();
+
+$cli = new \Symfony\Component\Console\Application('PartKeepr Console', \PartKeepr\PartKeeprVersion::PARTKEEPR_VERSION);
+$cli->setCatchExceptions(true);
+
+try {
+ PartKeepr::initializeDoctrine();
+
+ $helperSet = $cli->getHelperSet();
+
+ $helpers = array(
+ 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper(PartKeepr::getEM()->getConnection()),
+ 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper(PartKeepr::getEM())
+ );
+
+ foreach ($helpers as $name => $helper) {
+ $helperSet->set($helper, $name);
+ }
+
+} catch (\Exception $e) {
+
+}
+$cli->addCommands(array(
+ new \PartKeepr\Console\Commands\MinifyJSCommand()
+
+ ));
+$cli->run();+
\ No newline at end of file
diff --git a/src/backend/PartKeepr/Console/Commands/MinifyJSCommand.php b/src/backend/PartKeepr/Console/Commands/MinifyJSCommand.php
@@ -32,7 +32,8 @@ class MinifyJSCommand extends Console\Command\Command
->addOption('minify', null, InputOption::VALUE_NONE,
'Specifies if the files should be minified (removal of whitespaces and line breaks). If not ' .
'specified, this only merges the JS files.')
- ->setDescription(<<<EOT
+ ->setDescription('Minifies JavaScript files in their correct order')
+ ->setHelp(<<<EOT
Minifies JavaScript files in their correct order. To do this correctly, we parse all JavaScript files and look for the ExtJS-specific 'extend' directives. With that information,
we can build a hierarchical tree of files which represent the dependencies and output a parsed tree. That tree is then converted into an ordered list, which is then compressed.
EOT
diff --git a/src/backend/PartKeepr/PartKeepr.php b/src/backend/PartKeepr/PartKeepr.php
@@ -43,8 +43,7 @@ class PartKeepr {
*/
public static function initializeClassLoaders() {
require_once 'Doctrine/Common/ClassLoader.php';
-
-
+
$classLoader = new ClassLoader('PartKeepr', self::getRootDirectory() . "/src/backend");
$classLoader->register();
@@ -96,9 +95,13 @@ class PartKeepr {
*/
public static function initializeConfig ($environment = null) {
if ($environment != null) {
- include(self::getRootDirectory()."/config-$environment.php");
+ $config = self::getRootDirectory()."/config-$environment.php";
} else {
- include(self::getRootDirectory()."/config.php");
+ $config = self::getRootDirectory()."/config.php";
+ }
+
+ if (file_exists($config)) {
+ include($config);
}
// Check if the files path is set. If not, fall back to <partkeepr-root>/data/
@@ -221,7 +224,7 @@ class PartKeepr {
public static function createConnectionOptionsFromConfig () {
$connectionOptions = array();
-
+
$driver = PartKeeprConfiguration::getOption("partkeepr.database.driver");
switch ($driver) {