Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added filter and em parameters to Doctrine tasks; added README

  • Loading branch information...
commit 313cba0930cb144d37969ff19936cf2a1bbd1bd8 1 parent 11d6bcb
heartsentwined authored
View
121 README.md
@@ -0,0 +1,121 @@
+# zf2-phing-task
+
+A collection of Phing Tasks for a ZF2 app.
+
+Note: it will look for `config/application.config.yml` instead of
+`config/application.config.php` on bootstrap. If you use PHP config files,
+you'll have to change the code in each Task's `main()` method.
+
+# Installation
+
+[Composer](http://getcomposer.org/):
+
+```json
+{
+ "require": {
+ "heartsentwined/zf2-phing-task": "1.*"
+ }
+}
+```
+
+# Usage
+
+## ClassmapTask
+
+Generate a classmap for the directory `foo/library` (and its subdirectories), save it at `foo/autoload_classmap.php`.
+
+```xml
+<project>
+ <target>
+ <includepath classpath="vendor/heartsentwined/zf2-phing-task/src/task" />
+ <taskdef name="classmap" classname="ClassmapTask" />
+ <classmap dir="foo/library" output="foo/autoload_classmap.php" />
+ </target>
+</project>
+```
+
+## DoctrineEntityTask
+
+Generate entities for the EntityManager `doctrine.entitymanager.orm_default`, base directory at `foo/src`, with filter `Foo\Entity`.
+
+```xml
+<project>
+ <target>
+ <includepath classpath="vendor/heartsentwined/zf2-phing-task/src/task" />
+ <taskdef name="d-entity" classname="DoctrineEntityTask" />
+ <d-proxy em="doctrine.entitymanager.orm_default" filter="Foo\Entity" output="foo/src" />
+ </target>
+</project>
+```
+
+## DoctrineRepoTask
+
+Generate repositories for the EntityManager `doctrine.entitymanager.orm_default`, base directory at `foo/src`, with filter `Foo\Entity`.
+
+```xml
+<project>
+ <target>
+ <includepath classpath="vendor/heartsentwined/zf2-phing-task/src/task" />
+ <taskdef name="d-repo" classname="DoctrineRepoTask" />
+ <d-repo em="doctrine.entitymanager.orm_default" filter="Foo\Entity" output="foo/src" />
+ </target>
+</project>
+```
+
+## DoctrineProxyTask
+
+Generate proxies for the EntityManager `doctrine.entitymanager.orm_default`, at directory `foo/cache/proxy`, with filter `Foo\Entity`.
+
+```xml
+<project>
+ <target>
+ <includepath classpath="vendor/heartsentwined/zf2-phing-task/src/task" />
+ <taskdef name="d-proxy" classname="DoctrineProxyTask" />
+ <d-proxy em="doctrine.entitymanager.orm_default" filter="Foo\Entity" output="foo/cache/proxy" />
+ </target>
+</project>
+```
+
+## DoctrineUpdateTask
+
+Update database schema for the EntityManager `doctrine.entitymanager.orm_default`.
+
+```xml
+<project>
+ <target>
+ <includepath classpath="vendor/heartsentwined/zf2-phing-task/src/task" />
+ <taskdef name="d-update" classname="DoctrineUpdateTask" />
+ <d-update em="doctrine.entitymanager.orm_default" />
+ </target>
+</project>
+```
+
+## DoctrineDropTask
+
+Drop all database tables from the connection of the EntityManager `doctrine.entitymanager.orm_default`.
+
+**This Task differs from Doctrine CLI's behavior. It drops _ALL_ tables, not just those found in the metadata mapping files.**
+
+```xml
+<project>
+ <target>
+ <includepath classpath="vendor/heartsentwined/zf2-phing-task/src/task" />
+ <taskdef name="d-drop" classname="DoctrineDropTask" />
+ <d-drop em="doctrine.entitymanager.orm_default" />
+ </target>
+</project>
+```
+
+## TwigTask
+
+Load the Twig template `foo/bar`.
+
+```xml
+<project>
+ <target>
+ <includepath classpath="vendor/heartsentwined/zf2-phing-task/src/task" />
+ <taskdef name="twig" classname="TwigTask" />
+ <twig file="foo/bar" />
+ </target>
+</project>
+```
View
4 composer.json
@@ -1,6 +1,6 @@
{
- "name": "heartsentwined/phing-task",
- "description": "phing tasks",
+ "name": "heartsentwined/zf2-phing-task",
+ "description": "A collection of Phing Tasks for a ZF2 app.",
"license": "GPL-3.0",
"authors": [
{
View
17 src/task/DoctrineDropTask.php
@@ -8,9 +8,24 @@
class DoctrineDropTask extends Task
{
+ protected $em;
protected $failonerror;
/**
+ * the ServiceLocator identifier of the EntityManager
+ *
+ * can be either a FQCN, or an alias;
+ * must be registered with ZF2's ServiceManager
+ *
+ * @param string $em
+ * @return void
+ */
+ public function setEm($em)
+ {
+ $this->em = $em;
+ }
+
+ /**
* if error occured, whether build should fail
*
* @param bool $value
@@ -55,7 +70,7 @@ public function main()
}
$application = Application::init(Yaml::parse('config/application.config.yml'));
- $em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
+ $em = $application->getServiceManager()->get($this->em);
chdir($wd);
View
33 src/task/DoctrineEntityTask.php
@@ -1,6 +1,7 @@
<?php
require_once __DIR__ . '/../../../../autoload.php';
+use Doctrine\ORM\Tools\Console\MetadataFilter;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\ORM\Tools\EntityGenerator;
use Symfony\Component\Yaml\Yaml;
@@ -10,6 +11,8 @@
class DoctrineEntityTask extends Task
{
protected $output;
+ protected $filter;
+ protected $em;
protected $failonerror;
/**
@@ -36,6 +39,31 @@ public function setOutput($output)
}
/**
+ * metadata filter
+ *
+ * @param string $filter
+ * @return void
+ */
+ public function setFilter($filter)
+ {
+ $this->filter = $filter;
+ }
+
+ /**
+ * the ServiceLocator identifier of the EntityManager
+ *
+ * can be either a FQCN, or an alias;
+ * must be registered with ZF2's ServiceManager
+ *
+ * @param string $em
+ * @return void
+ */
+ public function setEm($em)
+ {
+ $this->em = $em;
+ }
+
+ /**
* if error occured, whether build should fail
*
* @param bool $value
@@ -80,7 +108,7 @@ public function main()
}
$application = Application::init(Yaml::parse('config/application.config.yml'));
- $em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
+ $em = $application->getServiceManager()->get($this->em);
chdir($wd);
@@ -90,6 +118,9 @@ public function main()
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadatas = $cmf->getAllMetadata();
+ if (!empty($this->filter)) {
+ $metadatas = MetadataFilter::filter($metadatas, $this->filter);
+ }
if (count($metadatas)) {
// Create EntityGenerator
View
33 src/task/DoctrineProxyTask.php
@@ -1,6 +1,7 @@
<?php
require_once __DIR__ . '/../../../../autoload.php';
+use Doctrine\ORM\Tools\Console\MetadataFilter;
use Symfony\Component\Yaml\Yaml;
use Zend\ServiceManager\ServiceManager;
use Zend\Mvc\Application;
@@ -8,6 +9,8 @@
class DoctrineProxyTask extends Task
{
protected $output;
+ protected $filter;
+ protected $em;
protected $failonerror;
/**
@@ -34,6 +37,31 @@ public function setOutput($output)
}
/**
+ * metadata filter
+ *
+ * @param string $filter
+ * @return void
+ */
+ public function setFilter($filter)
+ {
+ $this->filter = $filter;
+ }
+
+ /**
+ * the ServiceLocator identifier of the EntityManager
+ *
+ * can be either a FQCN, or an alias;
+ * must be registered with ZF2's ServiceManager
+ *
+ * @param string $em
+ * @return void
+ */
+ public function setEm($em)
+ {
+ $this->em = $em;
+ }
+
+ /**
* if error occured, whether build should fail
*
* @param bool $value
@@ -78,7 +106,7 @@ public function main()
}
$application = Application::init(Yaml::parse('config/application.config.yml'));
- $em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
+ $em = $application->getServiceManager()->get($this->em);
chdir($wd);
@@ -86,6 +114,9 @@ public function main()
}
$metadatas = $em->getMetadataFactory()->getAllMetadata();
+ if (!empty($this->filter)) {
+ $metadatas = MetadataFilter::filter($metadatas, $this->filter);
+ }
if (count($metadatas)) {
foreach ($metadatas as $metadata) {
View
33 src/task/DoctrineRepoTask.php
@@ -1,6 +1,7 @@
<?php
require_once __DIR__ . '/../../../../autoload.php';
+use Doctrine\ORM\Tools\Console\MetadataFilter;
use Doctrine\ORM\Tools\EntityRepositoryGenerator;
use Symfony\Component\Yaml\Yaml;
use Zend\ServiceManager\ServiceManager;
@@ -9,6 +10,8 @@
class DoctrineRepoTask extends Task
{
protected $output;
+ protected $filter;
+ protected $em;
protected $failonerror;
/**
@@ -35,6 +38,31 @@ public function setOutput($output)
}
/**
+ * metadata filter
+ *
+ * @param string $filter
+ * @return void
+ */
+ public function setFilter($filter)
+ {
+ $this->filter = $filter;
+ }
+
+ /**
+ * the ServiceLocator identifier of the EntityManager
+ *
+ * can be either a FQCN, or an alias;
+ * must be registered with ZF2's ServiceManager
+ *
+ * @param string $em
+ * @return void
+ */
+ public function setEm($em)
+ {
+ $this->em = $em;
+ }
+
+ /**
* if error occured, whether build should fail
*
* @param bool $value
@@ -79,7 +107,7 @@ public function main()
}
$application = Application::init(Yaml::parse('config/application.config.yml'));
- $em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
+ $em = $application->getServiceManager()->get($this->em);
chdir($wd);
@@ -87,6 +115,9 @@ public function main()
}
$metadatas = $em->getMetadataFactory()->getAllMetadata();
+ if (!empty($this->filter)) {
+ $metadatas = MetadataFilter::filter($metadatas, $this->filter);
+ }
if (count($metadatas)) {
$numRepositories = 0;
View
17 src/task/DoctrineUpdateTask.php
@@ -8,9 +8,24 @@
class DoctrineUpdateTask extends Task
{
+ protected $em;
protected $failonerror;
/**
+ * the ServiceLocator identifier of the EntityManager
+ *
+ * can be either a FQCN, or an alias;
+ * must be registered with ZF2's ServiceManager
+ *
+ * @param string $em
+ * @return void
+ */
+ public function setEm($em)
+ {
+ $this->em = $em;
+ }
+
+ /**
* if error occured, whether build should fail
*
* @param bool $value
@@ -55,7 +70,7 @@ public function main()
}
$application = Application::init(Yaml::parse('config/application.config.yml'));
- $em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
+ $em = $application->getServiceManager()->get($this->em);
chdir($wd);
Please sign in to comment.
Something went wrong with that request. Please try again.