diff --git a/README.md b/README.md index 126d497..ebb1113 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ EventDispatcherBehavior [![Build Status](https://secure.travis-ci.org/willdurand/EventDispatcherBehavior.png?branch=master)](http://travis-ci.org/willdurand/EventDispatcherBehavior) -Integrate the Symfony2 [EventDispatcher](https://github.com/symfony/EventDispatcher) component in your Model classes. +Integrate the Symfony2 [EventDispatcher](https://github.com/symfony/EventDispatcher) component in your Model classes for Propel 2 alpha 3. +Final Propel 2 release will have this integrated into core. This is only for guys using Propel 2 already till alpha 3 and need those behavior. ### Installation ### diff --git a/composer.json b/composer.json index 902e589..5bdc396 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,10 @@ { - "name": "willdurand/propel-eventdispatcher-behavior", - "description": "Integrates the Symfony2 EventDispatcher component in your Model classes. ", - "keywords": [ "propel", "behavior", "event dispatcher", "event" ], + "name": "marcj/propel-eventdispatcher-behavior", + "description": "Integrates the Symfony2 EventDispatcher component in your Model classes for Propel2 alpha 3. ", + "keywords": [ "propel2", "behavior", "event dispatcher", "event" ], "license": "MIT", "require": { - "symfony/event-dispatcher": "~2.1", - "propel/propel1": "~1.6" + "symfony/event-dispatcher": "~2.1" }, "authors": [ { diff --git a/src/EventDispatcherBehavior.php b/src/EventDispatcherBehavior.php index be767d3..678c324 100644 --- a/src/EventDispatcherBehavior.php +++ b/src/EventDispatcherBehavior.php @@ -3,7 +3,7 @@ /** * @author William Durand */ -class EventDispatcherBehavior extends Behavior +class EventDispatcherBehavior extends \Propel\Generator\Model\Behavior { /** * @var EventDispatcherObjectBuilderModifier diff --git a/src/EventDispatcherObjectBuilderModifier.php b/src/EventDispatcherObjectBuilderModifier.php index 3203bfe..8bc65db 100644 --- a/src/EventDispatcherObjectBuilderModifier.php +++ b/src/EventDispatcherObjectBuilderModifier.php @@ -7,7 +7,7 @@ class EventDispatcherObjectBuilderModifier { private $behavior; - public function __construct(Behavior $behavior) + public function __construct(\Propel\Generator\Model\Behavior $behavior) { $this->behavior = $behavior; } @@ -73,14 +73,6 @@ public function addConstructHook() )) . ' '; } - public function postHydrate() - { - return $this->behavior->renderTemplate('objectHook', array( - 'eventName' => $this->getEventName('post_hydrate'), - 'withConnection' => false, - )); - } - public function preSave() { return $this->behavior->renderTemplate('objectHook', array( @@ -147,14 +139,14 @@ public function postDelete() public function objectFilter(&$script) { - $script = preg_replace('#(implements Persistent)#', '$1, EventDispatcherAwareModelInterface', $script); + $script = preg_replace('#(implements ActiveRecordInterface)#', '$1, \EventDispatcherAwareModelInterface', $script); // rename the dummy_construct to __construct if __construct does not exists if (strpos($script, 'function __construct') === false) { $script = str_replace('function dummy_construct', 'function __construct', $script); } - $parser = new PropelPHPParser($script, true); + $parser = new \Propel\Generator\Util\PhpParser($script, true); $parser->removeMethod('dummy_construct'); $oldCode = $parser->findMethod('__construct'); $newCode = substr_replace($oldCode, $this->addConstructHook() . '}', strrpos($oldCode, '}')); diff --git a/tests/EventDispatcherBehaviorTest.php b/tests/EventDispatcherBehaviorTest.php index fce1aec..d259772 100644 --- a/tests/EventDispatcherBehaviorTest.php +++ b/tests/EventDispatcherBehaviorTest.php @@ -16,7 +16,7 @@ public function setUp() - + EOF @@ -28,7 +28,7 @@ public function setUp() - + EOF @@ -36,9 +36,8 @@ public function setUp() foreach ($tables as $className => $schema) { if (!class_exists($className)) { - $builder = new PropelQuickBuilder(); + $builder = new \Propel\Generator\Util\QuickBuilder(); $config = $builder->getConfig(); - $config->setBuildProperty('behavior.event_dispatcher.class', '../src/EventDispatcherBehavior'); $builder->setConfig($config); $builder->setSchema($schema); @@ -77,19 +76,10 @@ public function testFireEvent() $preSaveFired = false; $postSaveFired = false; $postConstructFired = false; - $postHydrateFired = false; $threadConstructFired = false; $that = $this; - Post::getEventDispatcher()->addListener(Post::EVENT_POST_HYDRATE, function (Event $event) use (& $postHydrateFired, $that) { - $postHydrateFired = true; - - $that->assertInstanceOf('Symfony\Component\EventDispatcher\GenericEvent', $event); - $that->assertInstanceOf('Post', $event->getSubject()); - $that->assertFalse($event->hasArgument('connection')); - }); - Post::getEventDispatcher()->addListener(Post::EVENT_CONSTRUCT, function (Event $event) use (& $postConstructFired, $that) { $postConstructFired = true; @@ -111,7 +101,7 @@ public function testFireEvent() $that->assertInstanceOf('Symfony\Component\EventDispatcher\GenericEvent', $event); $that->assertInstanceOf('Post', $event->getSubject()); - $that->assertInstanceOf('PropelPDO', $event->getArgument('connection')); + $that->assertInstanceOf('Propel\Runtime\Connection\ConnectionInterface', $event->getArgument('connection')); }); Post::getEventDispatcher()->addListener(Post::EVENT_POST_SAVE, function (Event $event) use (& $postSaveFired, $that) { @@ -119,13 +109,12 @@ public function testFireEvent() $that->assertInstanceOf('Symfony\Component\EventDispatcher\GenericEvent', $event); $that->assertInstanceOf('Post', $event->getSubject()); - $that->assertInstanceOf('PropelPDO', $event->getArgument('connection')); + $that->assertInstanceOf('Propel\Runtime\Connection\ConnectionInterface', $event->getArgument('connection')); }); new Thread(); $this->assertTrue($threadConstructFired); - $post = new Post(); $this->assertTrue($postConstructFired); @@ -133,7 +122,6 @@ public function testFireEvent() $post->save(); $post->reload(); - $this->assertTrue($postHydrateFired); $this->assertTrue($preSaveFired); $this->assertTrue($postSaveFired); } diff --git a/tests/EventDispatcherBehaviorWithNamespacesTest.php b/tests/EventDispatcherBehaviorWithNamespacesTest.php index 6d05e72..5471b13 100644 --- a/tests/EventDispatcherBehaviorWithNamespacesTest.php +++ b/tests/EventDispatcherBehaviorWithNamespacesTest.php @@ -17,14 +17,13 @@ public function setUp() - + EOF; - $builder = new PropelQuickBuilder(); + $builder = new \Propel\Generator\Util\QuickBuilder(); $config = $builder->getConfig(); - $config->setBuildProperty('behavior.event_dispatcher.class', '../src/EventDispatcherBehavior'); $builder->setConfig($config); $builder->setSchema($schema); @@ -66,7 +65,7 @@ public function testFireEvent() $that->assertInstanceOf('Symfony\Component\EventDispatcher\GenericEvent', $event); $that->assertInstanceOf('My\Post', $event->getSubject()); - $that->assertInstanceOf('PropelPDO', $event->getArgument('connection')); + $that->assertInstanceOf('Propel\Runtime\Connection\ConnectionInterface', $event->getArgument('connection')); }); Post::getEventDispatcher()->addListener(Post::EVENT_POST_SAVE, function (Event $event) use (& $postSaveFired, $that) { @@ -74,7 +73,7 @@ public function testFireEvent() $that->assertInstanceOf('Symfony\Component\EventDispatcher\GenericEvent', $event); $that->assertInstanceOf('My\Post', $event->getSubject()); - $that->assertInstanceOf('PropelPDO', $event->getArgument('connection')); + $that->assertInstanceOf('Propel\Runtime\Connection\ConnectionInterface', $event->getArgument('connection')); }); $post = new Post(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9013322..6c8c4f5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,6 +1,3 @@