Permalink
Browse files

fixed zf2 application init bug - problem not with us

  • Loading branch information...
1 parent f4bd5b6 commit 778bb794c7959b650bf042deaabd49eadd5ca586 heartsentwined committed Sep 12, 2012
Showing with 19 additions and 29 deletions.
  1. +19 −29 src/task/DoctrineEntityTask.php
@@ -1,7 +1,6 @@
<?php
require_once __DIR__ . '/../../../../autoload.php';
-use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\ORM\Tools\EntityGenerator;
use Symfony\Component\Yaml\Yaml;
@@ -10,21 +9,9 @@
class DoctrineEntityTask extends Task
{
- protected $em;
protected $failonerror;
/**
- * EntityManager
- *
- * @param EntityManager $em
- * @return void
- */
- public function setEm(EntityManager $em)
- {
- $this->em = $em;
- }
-
- /**
* output directory for entity classes
*
* @param string $output
@@ -74,30 +61,33 @@ public function init()
*/
public function main()
{
- $wd = getcwd();
+ static $em;
- $previousDir = '.';
- while (!file_exists('config/application.config.yml')) {
- $dir = dirname(getcwd());
+ if ($em === null) {
+ $wd = getcwd();
- if ($previousDir === $dir) {
- throw new BuildException('Unable to locate "config/application.config.yml"');
- }
+ $previousDir = '.';
+ while (!file_exists('config/application.config.yml')) {
+ $dir = dirname(getcwd());
- $previousDir = $dir;
- chdir($dir);
- }
+ if ($previousDir === $dir) {
+ throw new BuildException('Unable to locate "config/application.config.yml"');
+ }
- $application = Application::init(Yaml::parse('config/application.config.yml'));
- $this->setEm(
- $application->getServiceManager()->get('doctrine.entitymanager.orm_default'));
+ $previousDir = $dir;
+ chdir($dir);
+ }
+
+ $application = Application::init(Yaml::parse('config/application.config.yml'));
+ $em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
- chdir($wd);
+ chdir($wd);
- /* finish bootstrapping zf2 */
+ /* finish bootstrapping zf2 */
+ }
$cmf = new DisconnectedClassMetadataFactory();
- $cmf->setEntityManager($this->em);
+ $cmf->setEntityManager($em);
$metadatas = $cmf->getAllMetadata();
if (count($metadatas)) {

0 comments on commit 778bb79

Please sign in to comment.