[limb-svn] r6810 - in 3.x/trunk/limb/core: src tests/cases
svn at limb-project.com
svn at limb-project.com
Wed Feb 27 15:19:01 MSK 2008
Author: cmz
Date: 2008-02-27 15:19:01 +0300 (Wed, 27 Feb 2008)
New Revision: 6810
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6810
Added:
3.x/trunk/limb/core/src/lmbDelegatesChain.class.php
3.x/trunk/limb/core/tests/cases/lmbDelegatesChainTest.class.php
Removed:
3.x/trunk/limb/core/src/lmbEvent.class.php
3.x/trunk/limb/core/tests/cases/lmbEventTest.class.php
Log:
-- renamed lmbEvent to lmbDelegatesChain
-- removed method lmbDelegatesChain::invokeAll()
-- renamed method lmbDelegatesChain::invokeChain() to invoke()
Copied: 3.x/trunk/limb/core/src/lmbDelegatesChain.class.php (from rev 6806, 3.x/trunk/limb/core/src/lmbEvent.class.php)
===================================================================
--- 3.x/trunk/limb/core/src/lmbDelegatesChain.class.php (rev 0)
+++ 3.x/trunk/limb/core/src/lmbDelegatesChain.class.php 2008-02-27 12:19:01 UTC (rev 6810)
@@ -0,0 +1,89 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2008 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+lmb_require('limb/core/src/lmbDelegate.class.php');
+
+/**
+ * Delegates chain
+ *
+ * @package core
+ * @version $Id$
+ */
+class lmbDelegatesChain
+{
+
+ /**
+ * Array of delegates
+ *
+ * @var array
+ */
+ protected $delegates = array();
+
+ /**
+ * Find a delegate added to chain
+ *
+ * @param mixed $delegate finding delegate
+ * @return mixed number of delegate or false if delegate is not found
+ */
+ function find($delegate)
+ {
+ $delegate = lmbDelegate::objectify($delegate);
+ foreach($this->delegates as $n => $dlg)
+ {
+ if($delegate->equal($dlg))
+ return $n;
+ }
+ return false;
+ }
+
+ /**
+ * Return true if delegate was added to the chain already
+ *
+ * @param mixed $delegete
+ * @return boolean
+ */
+ function exists($delegete)
+ {
+ return $this->find($delegete) !== false;
+ }
+
+ /**
+ * Add a delegate to be invoked
+ *
+ * @param mixed $delegete
+ */
+ function add($delegete)
+ {
+ $this->delegates[] = lmbDelegate::objectify($delegete);
+ }
+
+ /**
+ * Remove delegate from the chain
+ *
+ * @param mixed $delegete
+ */
+ function remove($delegete)
+ {
+ if(($num = $this->find($delegete)) !== false)
+ unset($this->delegates[$num]);
+ }
+
+ /**
+ * Invoke all delegates containing in the chain.
+ * Stops invoking if delegate return a not null result
+ *
+ */
+ function invoke()
+ {
+ $args = func_get_args();
+ return lmbDelegate::invokeChain($this->delegates, $args);
+ }
+
+}
+?>
\ No newline at end of file
Deleted: 3.x/trunk/limb/core/src/lmbEvent.class.php
===================================================================
--- 3.x/trunk/limb/core/src/lmbEvent.class.php 2008-02-27 11:45:36 UTC (rev 6809)
+++ 3.x/trunk/limb/core/src/lmbEvent.class.php 2008-02-27 12:19:01 UTC (rev 6810)
@@ -1,99 +0,0 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2008 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-lmb_require('limb/core/src/lmbDelegate.class.php');
-
-/**
- * Event object. In fact it's a collection of delegates
- *
- * @package core
- * @version $Id$
- */
-class lmbEvent
-{
-
- /**
- * Array of delegates
- *
- * @var array
- */
- protected $delegates = array();
-
- /**
- * Find a delegate added to event
- *
- * @param mixed $delegate finding delegate
- * @return mixed number of delegate or false if delegate is not found
- */
- function find($delegate)
- {
- $delegate = lmbDelegate::objectify($delegate);
- foreach($this->delegates as $n => $dlg)
- {
- if($delegate->equal($dlg))
- return $n;
- }
- return false;
- }
-
- /**
- * Return true if delegate was added to the event already
- *
- * @param mixed $delegete
- * @return boolean
- */
- function exists($delegete)
- {
- return $this->find($delegete) !== false;
- }
-
- /**
- * Add a delegate to be invoked
- *
- * @param mixed $delegete
- */
- function add($delegete)
- {
- $this->delegates[] = lmbDelegate::objectify($delegete);
- }
-
- /**
- * Remove delegate from the event object
- *
- * @param mixed $delegete
- */
- function remove($delegete)
- {
- if(($num = $this->find($delegete)) !== false)
- unset($this->delegates[$num]);
- }
-
- /**
- * Invoke all delegates containing in the event object.
- *
- */
- function invokeAll()
- {
- $args = func_get_args();
- lmbDelegate::invokeAll($this->delegates, $args);
- }
-
- /**
- * Invoke all delegates containing in the event object.
- * Stops invoking if delegate return a not null result
- *
- */
- function invokeChain()
- {
- $args = func_get_args();
- return lmbDelegate::invokeChain($this->delegates, $args);
- }
-
-}
-?>
\ No newline at end of file
Copied: 3.x/trunk/limb/core/tests/cases/lmbDelegatesChainTest.class.php (from rev 6805, 3.x/trunk/limb/core/tests/cases/lmbEventTest.class.php)
===================================================================
--- 3.x/trunk/limb/core/tests/cases/lmbDelegatesChainTest.class.php (rev 0)
+++ 3.x/trunk/limb/core/tests/cases/lmbDelegatesChainTest.class.php 2008-02-27 12:19:01 UTC (rev 6810)
@@ -0,0 +1,119 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2008 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+lmb_require('limb/core/src/lmbDelegatesChain.class.php');
+
+class DelegatesChainTestingStubObject
+{
+
+ public $invoked = 0;
+ public $last_arg = null;
+ public $last_arg2 = null;
+
+ protected $return;
+
+ function __construct($return = 'invoked')
+ {
+ $this->return = $return;
+ }
+
+ function invokable($arg = null, $arg2 = null)
+ {
+ $this->invoked ++;
+ $this->last_arg = $arg;
+ $this->last_arg2 = $arg2;
+ return $this->return;
+ }
+
+}
+
+class lmbDelegatesChainTest extends UnitTestCase {
+
+ function testInvoke()
+ {
+ $obj1 = new DelegatesChainTestingStubObject(null);
+ $obj2 = new DelegatesChainTestingStubObject('result');
+ $obj3 = new DelegatesChainTestingStubObject();
+
+ $chain = new lmbDelegatesChain();
+ $chain->add(new lmbDelegate($obj1, 'invokable'));
+ $chain->add(new lmbDelegate($obj2, 'invokable'));
+ $chain->add(new lmbDelegate($obj3, 'invokable'));
+
+ $result = $chain->invoke('invoked');
+ $this->assertEqual($result, 'result');
+ $this->assertEqual($obj1->invoked, 1);
+ $this->assertEqual($obj2->invoked, 1);
+ $this->assertEqual($obj3->invoked, 0);
+ $this->assertEqual($obj1->last_arg, 'invoked');
+ $this->assertEqual($obj2->last_arg, 'invoked');
+ }
+
+ function testFind()
+ {
+ $obj1 = new DelegatesChainTestingStubObject();
+ $obj2 = new DelegatesChainTestingStubObject();
+
+ $chain = new lmbDelegatesChain();
+ $chain->add(new lmbDelegate($obj1, 'invokable'));
+ $chain->add(new lmbDelegate($obj2, 'invokable'));
+
+ $num = $chain->find(array($obj2, 'invokable'));
+ $this->assertEqual($num, 1);
+
+ $num = $chain->find(array(new DelegatesChainTestingStubObject(), 'invokable'));
+ $this->assertFalse($num);
+ }
+
+ function testExists()
+ {
+ $obj1 = new DelegatesChainTestingStubObject();
+ $obj2 = new DelegatesChainTestingStubObject();
+
+ $chain = new lmbDelegatesChain();
+ $chain->add(new lmbDelegate($obj1, 'invokable'));
+ $chain->add(new lmbDelegate($obj2, 'invokable'));
+
+ $result = $chain->exists(array($obj2, 'invokable'));
+ $this->assertTrue($result);
+
+ $result = $chain->exists(array(new DelegatesChainTestingStubObject(), 'invokable'));
+ $this->assertFalse($result);
+ }
+
+ function testRemove()
+ {
+ $obj1 = new DelegatesChainTestingStubObject(null);
+ $obj2 = new DelegatesChainTestingStubObject(null);
+
+ $chain = new lmbDelegatesChain();
+ $chain->add(new lmbDelegate($obj1, 'invokable'));
+ $chain->add(new lmbDelegate($obj2, 'invokable'));
+
+ $chain->invoke();
+ $chain->remove(new lmbDelegate($obj2, 'invokable'));
+ $chain->invoke();
+ $this->assertEqual($obj1->invoked, 2);
+ $this->assertEqual($obj2->invoked, 1);
+ }
+
+ function testPassingInvokeArgs()
+ {
+ $obj = new DelegatesChainTestingStubObject();
+
+ $chain = new lmbDelegatesChain();
+ $chain->add(new lmbDelegate($obj, 'invokable'));
+
+ $chain->invoke('arg1', 'arg2');
+ $this->assertEqual($obj->last_arg, 'arg1');
+ $this->assertEqual($obj->last_arg2, 'arg2');
+ }
+
+}
+?>
\ No newline at end of file
Deleted: 3.x/trunk/limb/core/tests/cases/lmbEventTest.class.php
===================================================================
--- 3.x/trunk/limb/core/tests/cases/lmbEventTest.class.php 2008-02-27 11:45:36 UTC (rev 6809)
+++ 3.x/trunk/limb/core/tests/cases/lmbEventTest.class.php 2008-02-27 12:19:01 UTC (rev 6810)
@@ -1,135 +0,0 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2008 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
-lmb_require('limb/core/src/lmbEvent.class.php');
-
-class EventTestingStubObject
-{
-
- public $invoked = 0;
- public $last_arg = null;
- public $last_arg2 = null;
-
- protected $return;
-
- function __construct($return = 'invoked')
- {
- $this->return = $return;
- }
-
- function invokable($arg = null, $arg2 = null)
- {
- $this->invoked ++;
- $this->last_arg = $arg;
- $this->last_arg2 = $arg2;
- return $this->return;
- }
-
-}
-
-class lmbEventTest extends UnitTestCase {
-
- function testInvokeAll()
- {
- $obj1 = new EventTestingStubObject();
- $obj2 = new EventTestingStubObject();
-
- $event = new lmbEvent();
- $event->add(new lmbDelegate($obj1, 'invokable'));
- $event->add(new lmbDelegate($obj2, 'invokable'));
-
- $event->invokeAll('invoked');
- $this->assertEqual($obj1->invoked, 1);
- $this->assertEqual($obj2->invoked, 1);
- $this->assertEqual($obj1->last_arg, 'invoked');
- $this->assertEqual($obj2->last_arg, 'invoked');
- }
-
- function testInvokeChain()
- {
- $obj1 = new EventTestingStubObject(null);
- $obj2 = new EventTestingStubObject('result');
- $obj3 = new EventTestingStubObject();
-
- $event = new lmbEvent();
- $event->add(new lmbDelegate($obj1, 'invokable'));
- $event->add(new lmbDelegate($obj2, 'invokable'));
- $event->add(new lmbDelegate($obj3, 'invokable'));
-
- $result = $event->invokeChain('invoked');
- $this->assertEqual($result, 'result');
- $this->assertEqual($obj1->invoked, 1);
- $this->assertEqual($obj2->invoked, 1);
- $this->assertEqual($obj3->invoked, 0);
- $this->assertEqual($obj1->last_arg, 'invoked');
- $this->assertEqual($obj2->last_arg, 'invoked');
- }
-
- function testFind()
- {
- $obj1 = new EventTestingStubObject();
- $obj2 = new EventTestingStubObject();
-
- $event = new lmbEvent();
- $event->add(new lmbDelegate($obj1, 'invokable'));
- $event->add(new lmbDelegate($obj2, 'invokable'));
-
- $num = $event->find(array($obj2, 'invokable'));
- $this->assertEqual($num, 1);
-
- $num = $event->find(array(new EventTestingStubObject(), 'invokable'));
- $this->assertFalse($num);
- }
-
- function testExists()
- {
- $obj1 = new EventTestingStubObject();
- $obj2 = new EventTestingStubObject();
-
- $event = new lmbEvent();
- $event->add(new lmbDelegate($obj1, 'invokable'));
- $event->add(new lmbDelegate($obj2, 'invokable'));
-
- $result = $event->exists(array($obj2, 'invokable'));
- $this->assertTrue($result);
-
- $result = $event->exists(array(new EventTestingStubObject(), 'invokable'));
- $this->assertFalse($result);
- }
-
- function testRemove()
- {
- $obj1 = new EventTestingStubObject();
- $obj2 = new EventTestingStubObject();
-
- $event = new lmbEvent();
- $event->add(new lmbDelegate($obj1, 'invokable'));
- $event->add(new lmbDelegate($obj2, 'invokable'));
-
- $event->invokeAll();
- $event->remove(new lmbDelegate($obj2, 'invokable'));
- $event->invokeAll();
- $this->assertEqual($obj1->invoked, 2);
- $this->assertEqual($obj2->invoked, 1);
- }
-
- function testPassingInvokeArgs()
- {
- $obj = new EventTestingStubObject();
-
- $event = new lmbEvent();
- $event->add(new lmbDelegate($obj, 'invokable'));
-
- $event->invokeAll('arg1', 'arg2');
- $this->assertEqual($obj->last_arg, 'arg1');
- $this->assertEqual($obj->last_arg2, 'arg2');
- }
-
-}
-?>
\ No newline at end of file
More information about the limb-svn
mailing list