From b274a69ec27d5747dfcff9541511443fc607d36e Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Wed, 24 Feb 2010 02:54:24 +0000 Subject: [PATCH] [2.0][DDC-364] Added Doctrine\Common\Version which provides the current version of Doctrine. Also added CLI tasks for Common and DBAL, since they may vary in the future. --- lib/Doctrine/Common/Cli/CliController.php | 6 +- lib/Doctrine/Common/Cli/Tasks/VersionTask.php | 61 ++++++++++++++++++ lib/Doctrine/Common/Version.php | 57 +++++++++++++++++ .../DBAL/Tools/Cli/Tasks/VersionTask.php | 62 +++++++++++++++++++ .../ORM/Tools/Cli/Tasks/VersionTask.php | 5 +- 5 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 lib/Doctrine/Common/Cli/Tasks/VersionTask.php create mode 100644 lib/Doctrine/Common/Version.php create mode 100644 lib/Doctrine/DBAL/Tools/Cli/Tasks/VersionTask.php diff --git a/lib/Doctrine/Common/Cli/CliController.php b/lib/Doctrine/Common/Cli/CliController.php index b1a6e2a61..1713d9067 100644 --- a/lib/Doctrine/Common/Cli/CliController.php +++ b/lib/Doctrine/Common/Cli/CliController.php @@ -71,7 +71,8 @@ class CliController extends AbstractNamespace // Include core namespaces of tasks $ns = 'Doctrine\Common\Cli\Tasks'; $this->addNamespace('Core') - ->addTask('help', $ns . '\HelpTask'); + ->addTask('help', $ns . '\HelpTask') + ->addTask('version', $ns . '\VersionTask'); $ns = 'Doctrine\ORM\Tools\Cli\Tasks'; $this->addNamespace('Orm') @@ -85,7 +86,8 @@ class CliController extends AbstractNamespace $ns = 'Doctrine\DBAL\Tools\Cli\Tasks'; $this->addNamespace('Dbal') - ->addTask('run-sql', $ns . '\RunSqlTask'); + ->addTask('run-sql', $ns . '\RunSqlTask') + ->addTask('version', $ns . '\VersionTask'); } /** diff --git a/lib/Doctrine/Common/Cli/Tasks/VersionTask.php b/lib/Doctrine/Common/Cli/Tasks/VersionTask.php new file mode 100644 index 000000000..152c2c6da --- /dev/null +++ b/lib/Doctrine/Common/Cli/Tasks/VersionTask.php @@ -0,0 +1,61 @@ +. + */ + +namespace Doctrine\Common\Cli\Tasks; + +use Doctrine\Common\Version; + +/** + * CLI Task to display the doctrine version + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan Wage + * @author Roman Borschel + */ +class VersionTask extends AbstractTask +{ + /** + * @inheritdoc + */ + public function buildDocumentation() + { + // There're no options on this task + $this->getDocumentation()->getOptionGroup()->clear(); + + $doc = $this->getDocumentation(); + $doc->setName('version') + ->setDescription('Displays the current installed Doctrine version.'); + } + + /** + * Displays the current version of Doctrine + * + */ + public function run() + { + $this->getPrinter()->writeln('You are currently running Doctrine ' . Version::VERSION, 'INFO'); + } +} \ No newline at end of file diff --git a/lib/Doctrine/Common/Version.php b/lib/Doctrine/Common/Version.php new file mode 100644 index 000000000..2e1847dc6 --- /dev/null +++ b/lib/Doctrine/Common/Version.php @@ -0,0 +1,57 @@ +. + */ + +namespace Doctrine\Common; + +/** + * Class to store and retrieve the version of Doctrine + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan Wage + * @author Roman Borschel + */ +class Version +{ + /** + * Current Doctrine Version + */ + const VERSION = '2.0 ALPHA 4'; + + /** + * Compares a Doctrine version with the current one. + * + * @param string $version Doctrine version to compare. + * @return int Returns -1 if older, 0 if it is the same, 1 if version + * passed as argument is newer. + */ + public static function compare($version) + { + $currentVersion = str_replace(' ', '', strtolower(self::VERSION)); + $version = str_replace(' ', '', $version); + + return version_compare($version, $currentVersion); + } +} \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Tools/Cli/Tasks/VersionTask.php b/lib/Doctrine/DBAL/Tools/Cli/Tasks/VersionTask.php new file mode 100644 index 000000000..f21b594f1 --- /dev/null +++ b/lib/Doctrine/DBAL/Tools/Cli/Tasks/VersionTask.php @@ -0,0 +1,62 @@ +. + */ + +namespace Doctrine\DBAL\Tools\Cli\Tasks; + +use Doctrine\Common\Cli\Tasks\AbstractTask, + Doctrine\Common\Version; + +/** + * CLI Task to display the doctrine version + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan Wage + * @author Roman Borschel + */ +class VersionTask extends AbstractTask +{ + /** + * @inheritdoc + */ + public function buildDocumentation() + { + // There're no options on this task + $this->getDocumentation()->getOptionGroup()->clear(); + + $doc = $this->getDocumentation(); + $doc->setName('version') + ->setDescription('Displays the current installed Doctrine version.'); + } + + /** + * Displays the current version of Doctrine + * + */ + public function run() + { + $this->getPrinter()->writeln('You are currently running Doctrine ' . Version::VERSION, 'INFO'); + } +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php b/lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php index b5ddfa846..e73d9d7b2 100644 --- a/lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php +++ b/lib/Doctrine/ORM/Tools/Cli/Tasks/VersionTask.php @@ -21,7 +21,8 @@ namespace Doctrine\ORM\Tools\Cli\Tasks; -use Doctrine\Common\Cli\Tasks\AbstractTask; +use Doctrine\Common\Cli\Tasks\AbstractTask, + Doctrine\Common\Version; /** * CLI Task to display the doctrine version @@ -56,6 +57,6 @@ class VersionTask extends AbstractTask */ public function run() { - $this->getPrinter()->writeln('You are currently running Doctrine 2.0.0 Alpha 4', 'INFO'); + $this->getPrinter()->writeln('You are currently running Doctrine ' . Version::VERSION, 'INFO'); } } \ No newline at end of file