Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge giws/master

  • Loading branch information...
commit 9c0ec3660f9c8a94d1b6e98d7408601ce70132ac 2 parents f142796 + 130bcb0
@beberlei authored
View
2  .gitignore
@@ -1,7 +1,9 @@
+composer.lock
nbproject
tests/phpunit.xml
build/
vendor/
+tests/Entities/Proxies
# Eclipse files
.settings
View
29 README.markdown
@@ -55,6 +55,35 @@ These methods internally use several others to create and retrieve the data. You
those methods to integrate with existing pagination solutions, a `Zend_Paginator` implementation
is already shipped (`DoctrineExtensions\Paginate\PaginationAdapter`).
+## Phing
+
+There are currently two Phing tasks provided by DoctrineExtensions:
+
+### GenerateProxies
+
+Generates Doctrine 2 proxy files.
+
+```xml
+<!-- assuming you have included the class file first -->
+
+<taskdef classname="DoctrineExtensions\Phing\Task\GenerateProxies" name="d2-proxies" />
+
+<d2-proxies cliConfig="${somedir}/cli-config.php" />
+```
+
+### InstallSql
+
+Generates a valid PHP file containing an array with all SQL that would be
+installed.
+
+```xml
+<!-- assuming you have included the class file first -->
+
+<taskdef classname="DoctrineExtensions\Phing\Task\InstallSql" name="d2-install-sql" />
+
+<d2-install-sql installSqlFile="${somedir}/sql/schema.sql.php" />
+```
+
## PHPUnit
The PHPUnit Extension for Doctrine offers several hooks into PHPUnits Database extension and offers a
View
48 lib/DoctrineExtensions/Phing/Task/AbstractDoctrineTask.php
@@ -13,42 +13,64 @@
namespace DoctrineExtensions\Phing\Task;
+use Symfony\Component\Console\Helper\HelperSet;
+
abstract class AbstractDoctrineTask extends \Task
{
/**
- * @var \Doctrine\Common\Cli\Configuration
+ * @var HelperSet
*/
- static protected $cliConfig = null;
+ protected static $helperSet = null;
+ /**
+ * @var string
+ */
protected $cliConfigFile = "cli-config.php";
- public function setCliConfig($cliConfig)
+ /**
+ * @todo Rename to setCliConfigFile
+ * @param string $cliConfigFile
+ * @return void
+ */
+ public function setCliConfig($cliConfigFile)
{
- $this->cliConfigFile = $cliConfig;
+ $this->cliConfigFile = $cliConfigFile;
}
public function main()
{
- if (self::$cliConfig == null) {
+ if (self::$helperSet === null) {
if (!file_exists($this->cliConfigFile)) {
- throw new \BuildException("Path to CLI Config has to be valid!");
+ throw new \BuildException(
+ "Path to CLI config file must be valid!"
+ );
}
include($this->cliConfigFile);
- if (!isset($cliConfig) || !($cliConfig instanceof \Doctrine\Common\Cli\Configuration)) {
- throw new \BuildException("Doctrine CLI Config file has to create a \$cliConfig variable");
+ if (!isset($helperSet)) {
+ throw new \BuildException(
+ "Doctrine CLI config file must create a \$helperSet"
+ . " variable."
+ );
+ }
+
+ if (!$helperSet instanceof HelperSet) {
+ throw new \BuildException(
+ "\$helperSet must be an instance of"
+ . "Symfony\Component\Console\Helper\HelperSet."
+ );
}
- self::$cliConfig = $cliConfig;
+ self::$helperSet = $helperSet;
}
- $this->_doRun(self::$cliConfig);
+ $this->_doRun(self::$helperSet);
}
/**
- * @param Configuration $cliConfig
+ * @param HelperSet $helperSet
* @return void
*/
- abstract protected function _doRun(\Doctrine\Common\Cli\Configuration $cliConfig);
-}
+ abstract protected function _doRun(HelperSet $helperSet);
+}
View
54 lib/DoctrineExtensions/Phing/Task/GenerateProxies.php
@@ -13,30 +13,38 @@
namespace DoctrineExtensions\Phing\Task;
-require_once "AbstractDoctrineTask.php";
+use Symfony\Component\Console\Helper\HelperSet;
+require_once 'AbstractDoctrineTask.php';
+
+/**
+ * Generate classes proxies to a given directory
+ */
class GenerateProxies extends AbstractDoctrineTask
{
+ /**
+ * @var string
+ */
protected $taskName = "dc2-proxies";
+ /**
+ * @var string
+ */
protected $proxyDir = null;
+ /**
+ * @param string $proxyDir
+ * @return void
+ */
public function setProxyDir($proxyDir)
{
$this->proxyDir = $proxyDir;
}
- /**
- * @param Configuration $cliConfig
- */
- protected function _doRun(\Doctrine\Common\Cli\Configuration $cliConfig)
+ protected function _doRun(HelperSet $helperSet)
{
- if ($this->proxyDir !== null && (!is_dir($this->proxyDir) || !is_writable($this->proxyDir))) {
- throw new \BuildException("Proxy directory is not valid or writable.");
- }
-
- /* @var $cliConfig \Doctrine\Common\Cli\Configuration */
- $em = $cliConfig->getAttribute('em');
+ $emHelper = $helperSet->get('em');
+ $em = $emHelper->getEntityManager();
$cmf = $em->getMetadataFactory();
$classes = $cmf->getAllMetadata();
@@ -45,11 +53,31 @@ protected function _doRun(\Doctrine\Common\Cli\Configuration $cliConfig)
if (empty($classes)) {
$this->log('No classes to generate proxies for.');
} else {
- $proxyDir = ($this->proxyDir != null) ? $this->proxyDir : $em->getConfiguration()->getProxyDir();
+ $proxyDir = ($this->proxyDir !== null)
+ ? $this->proxyDir
+ : $em->getConfiguration()->getProxyDir();
+
+ if ($proxyDir === null) {
+ throw new \BuildException(
+ "Proxy directory is not set."
+ );
+ }
+
+ if (!is_dir($proxyDir)) {
+ throw new \BuildException(
+ "Proxy directory is not a valid directory."
+ );
+ }
+
+ if (!is_writable($proxyDir)) {
+ throw new \BuildException(
+ "Proxy directory is not writable."
+ );
+ }
$factory->generateProxyClasses($classes, $proxyDir);
- $this->log('Doctrine 2 proxy classes generated to: ' . $proxyDir);
+ $this->log("Doctrine 2 proxy classes generated to {$proxyDir}");
}
}
}
View
56 lib/DoctrineExtensions/Phing/Task/InstallSql.php
@@ -13,44 +13,72 @@
namespace DoctrineExtensions\Phing\Task;
-require_once "AbstractDoctrineTask.php";
+use Doctrine\ORM\Tools\SchemaTool;
+use Symfony\Component\Console\Helper\HelperSet;
+require_once 'AbstractDoctrineTask.php';
+
+/**
+ * Write schema SQL to a file
+ */
class InstallSql extends AbstractDoctrineTask
{
+ /**
+ * @var string
+ */
protected $taskName = "dc2-install-sql";
- protected $platformClass = null;
-
/**
* @var string
*/
private $installSqlFile = null;
- public function setInstallSqlFile($installSqlFile) {
+ /**
+ * @param string $installSqlFile
+ * @return void
+ */
+ public function setInstallSqlFile($installSqlFile)
+ {
$this->installSqlFile = $installSqlFile;
}
- /**
- * @param Configuration $cliConfig
- */
- protected function _doRun(\Doctrine\Common\Cli\Configuration $cliConfig)
+ protected function _doRun(HelperSet $helperSet)
{
+ if ($this->installSqlFile === null) {
+ throw new \BuildException(
+ "Schema SQL file is not set."
+ );
+ }
+
+ if (!is_dir(dirname($this->installSqlFile))) {
+ throw new \BuildException(
+ "Schema SQL directory is not a valid directory."
+ );
+ }
+
if (!is_writable(dirname($this->installSqlFile))) {
- throw new \BuildException("Directory to write Install Sql File into is not writable.");
+ throw new \BuildException(
+ "Schema SQL directory is not writable."
+ );
}
- $em = $cliConfig->getAttribute('em');
+ $emHelper = $helperSet->get('em');
+ $em = $emHelper->getEntityManager();
- $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
+ $schemaTool = new SchemaTool($em);
$cmf = $em->getMetadataFactory();
$classes = $cmf->getAllMetadata();
$sql = $schemaTool->getCreateSchemaSql($classes);
- $code = "<?php\n\nreturn ".var_export($sql, true).";\n";
+ $code = sprintf(
+ "<?php\n\nreturn %s;\n",
+ var_export($sql, true)
+ );
+
file_put_contents($this->installSqlFile, $code);
- $this->log("Wrote the Array of SQL statements to create schema to file ".$this->installSqlFile);
+ $this->log("Wrote schema SQL to file {$this->installSqlFile}");
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.