Skip to content

Commit

Permalink
added opDoctrineEventNotifier for notify Doctrine_Event as sfEvent (r…
Browse files Browse the repository at this point in the history
…efs #933)
  • Loading branch information
fukamachi committed Apr 6, 2010
1 parent 4e1f266 commit 9447187
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
75 changes: 75 additions & 0 deletions lib/util/opDoctrineEventNotifier.class.php
@@ -0,0 +1,75 @@
<?php

/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/

/**
* opDoctrineEventNotifier
*
* @package OpenPNE
* @subpackage util
* @author Eitarow Fukamachi <fukamachi@tejimaya.com>
*/
class opDoctrineEventNotifier extends Doctrine_Record_Listener
{
private static function notify($when, $action, $doctrineEvent)
{
$dispatcher = sfContext::getInstance()->getEventDispatcher();
$dispatcher->notify(new sfEvent(null, sprintf('op_doctrine.%s_%s_%s', $when, $action, get_class($doctrineEvent->getInvoker()))));
}

public function preSave(Doctrine_Event $event)
{
self::notify('pre', 'save', $event);
}

public function postSave(Doctrine_Event $event)
{
self::notify('post', 'save', $event);
}

public function preUpdate(Doctrine_Event $event)
{
self::notify('pre', 'update', $event);
}

public function postUpdate(Doctrine_Event $event)
{
self::notify('post', 'update', $event);
}

public function preInsert(Doctrine_Event $event)
{
self::notify('pre', 'insert', $event);
}

public function postInsert(Doctrine_Event $event)
{
self::notify('post', 'insert', $event);
}

public function preDelete(Doctrine_Event $event)
{
self::notify('pre', 'delete', $event);
}

public function postDelete(Doctrine_Event $event)
{
self::notify('post', 'delete', $event);
}

public function preValidate(Doctrine_Event $event)
{
self::notify('pre', 'validate', $event);
}

public function postValidate(Doctrine_Event $event)
{
self::notify('post', 'validate', $event);
}
}
2 changes: 2 additions & 0 deletions lib/util/opDoctrineRecord.class.php
Expand Up @@ -181,5 +181,7 @@ public function setUp()
{
$this->addListener(new opApplicationLevelCascadingListener());
}

$this->addListener(new opDoctrineEventNotifier());
}
}

0 comments on commit 9447187

Please sign in to comment.