Author: Frederik Holljen Date: 2006-09-22 16:38:48 +0200 (Fri, 22 Sep 2006) New Revision: 3536
Log: - SignalObserver -> SignalSlot completed Added: trunk/SignalSlot/ trunk/SignalSlot/docs/tutorial.txt trunk/SignalSlot/docs/tutorial_multiple_slots_example.php trunk/SignalSlot/docs/tutorial_prioritized_slots_example.php trunk/SignalSlot/docs/tutorial_signals_in_class_example.php trunk/SignalSlot/docs/tutorial_signals_with_parameters_example.php trunk/SignalSlot/docs/tutorial_simple_signal_example.php trunk/SignalSlot/docs/tutorial_slot_types_example2.php trunk/SignalSlot/docs/tutorial_slot_types_example3.php trunk/SignalSlot/docs/tutorial_static_connections_example.php trunk/SignalSlot/src/internal/callback_comparer.php trunk/SignalSlot/src/signal_autoload.php trunk/SignalSlot/src/signal_collection.php trunk/SignalSlot/src/static_connections.php trunk/SignalSlot/tests/signal_collection_test.php trunk/SignalSlot/tests/static_connections_test.php trunk/SignalSlot/tests/suite.php trunk/SignalSlot/tests/test_classes.php Removed: trunk/SignalSlot/src/internal/callback_comparer.php trunk/SignalSlot/src/signal_autoload.php trunk/SignalSlot/src/signal_collection.php trunk/SignalSlot/src/static_connections.php trunk/SignalSlot/tests/signal_collection_test.php trunk/SignalSlot/tests/static_connections_test.php trunk/SignalSlot/tests/suite.php trunk/SignalSlot/tests/test_classes.php Copied: trunk/SignalSlot (from rev 3504, trunk/SignalObserver) Copied: trunk/SignalSlot/docs/tutorial.txt (from rev 3533, trunk/SignalObserver/docs/tutorial.txt) Copied: trunk/SignalSlot/docs/tutorial_multiple_slots_example.php (from rev 3533, trunk/SignalObserver/docs/tutorial_multiple_slots_example.php) Copied: trunk/SignalSlot/docs/tutorial_prioritized_slots_example.php (from rev 3533, trunk/SignalObserver/docs/tutorial_prioritized_slots_example.php) Copied: trunk/SignalSlot/docs/tutorial_signals_in_class_example.php (from rev 3533, trunk/SignalObserver/docs/tutorial_signals_in_class_example.php) Copied: trunk/SignalSlot/docs/tutorial_signals_with_parameters_example.php (from rev 3533, trunk/SignalObserver/docs/tutorial_signals_with_parameters_example.php) Copied: trunk/SignalSlot/docs/tutorial_simple_signal_example.php (from rev 3533, trunk/SignalObserver/docs/tutorial_simple_signal_example.php) Copied: trunk/SignalSlot/docs/tutorial_slot_types_example2.php (from rev 3533, trunk/SignalObserver/docs/tutorial_slot_types_example2.php) Copied: trunk/SignalSlot/docs/tutorial_slot_types_example3.php (from rev 3533, trunk/SignalObserver/docs/tutorial_slot_types_example3.php) Copied: trunk/SignalSlot/docs/tutorial_static_connections_example.php (from rev 3533, trunk/SignalObserver/docs/tutorial_static_connections_example.php) Deleted: trunk/SignalSlot/src/internal/callback_comparer.php =================================================================== --- trunk/SignalObserver/src/internal/callback_comparer.php 2006-09-20 09:59:56 UTC (rev 3504) +++ trunk/SignalSlot/src/internal/callback_comparer.php 2006-09-22 14:38:48 UTC (rev 3536) @@ -1,54 +0,0 @@ -<?php -/** - * @copyright Copyright (C) 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package SignalObserver - * @access private - */ - -/** - * Check if two callback are the same or not. - * - * @version //autogen// - * @mainclass - * @package SignalObserver - * @access private - */ -class ezcSignalCallbackComparer -{ - /** - * Returns true if the callbacks $a and $b are the same. - * - * @param callback $a - * @param callback $b - * @return bool - */ - public static function compareCallbacks( $a, $b ) - { - if( is_string( $a ) || is_string( $b ) ) - { - return $a === $b; - } - return ( count( array_udiff( $a, $b, array( 'ezcSignalCallbackComparer', 'comp_func') ) ) == 0 ); - } - - /** - * Checks if $a and $b are of the exact same. - * - * Note: This method does not support arrays as you may not have array's in callbacks. - * - * @param mixed $a - * @param mixed $b - * @return int 0 if same 1 or -1 if not. - */ - public static function comp_func( $a, $b ) - { - if( $a === $b ) return 0; - return 1; - - } -} - -?> Copied: trunk/SignalSlot/src/internal/callback_comparer.php (from rev 3535, trunk/SignalObserver/src/internal/callback_comparer.php) Deleted: trunk/SignalSlot/src/signal_autoload.php =================================================================== --- trunk/SignalObserver/src/signal_autoload.php 2006-09-20 09:59:56 UTC (rev 3504) +++ trunk/SignalSlot/src/signal_autoload.php 2006-09-22 14:38:48 UTC (rev 3536) @@ -1,16 +0,0 @@ -<?php -/** - * Autoload definition for classes in SignalObserver package. - * - * @package SignalObserver - * @version //autogen// - * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - */ -return array( - 'ezcSignalCollection' => 'SignalObserver/signal_collection.php', - 'ezcSignalStaticConnections' => 'SignalObserver/static_connections.php', - 'ezcSignalCallbackComparer' => 'SignalObserver/internal/callback_comparer.php' -); - -?> Copied: trunk/SignalSlot/src/signal_autoload.php (from rev 3535, trunk/SignalObserver/src/signal_autoload.php) Deleted: trunk/SignalSlot/src/signal_collection.php =================================================================== --- trunk/SignalObserver/src/signal_collection.php 2006-09-20 09:59:56 UTC (rev 3504) +++ trunk/SignalSlot/src/signal_collection.php 2006-09-22 14:38:48 UTC (rev 3536) @@ -1,327 +0,0 @@ -<?php -/** - * @copyright Copyright (C) 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package SignalObserver - */ - -/** - * ezcSignalCollection implements a mechanism for inter and intra object communication. - * TODO: order in which signals are called - * TODO: examples - * - * @property bool $signalsBlocked If set to true emits will not cause any slots to be called. - * - * @property-read string $identifier The identifier of this signal collection. - * Usually the class name of the object containing the collection. - * - * @version //autogen// - * @mainclass - * @package SignalObserver - */ -class ezcSignalCollection -{ - /** - * Holds the properties of this class. - * - * @var array(string=>mixed) - */ - private $properties = array(); - - /** - * Holds the connections for this object with the default priority. - * - * @var array(string=>array(callback)) - */ - private $defaultConnections = array(); - - /** - * Holds the connections for this object with the default priority. - * - * @var array(string=>array(int=>array(callback))) - */ - private $priorityConnections = array(); - - /** - * Constructs a new signal collection with the identifier $identifier. - * - * The identifier can be used to connect to signals statically using - * ezcSignalStaticConnections. - * - * @param string $identifier - */ - public function __construct( $identifier ) - { - $this->properties['identifier'] = $identifier; - $this->signalsBlocked = false; - } - - /** - * Sets the property $name to $value. - * - * @throws ezcBasePropertyNotFoundException if the property does not exist. - * @param string $name - * @param mixed $value - * @return void - */ - public function __set( $name, $value ) - { - switch ( $name ) - { - case 'signalsBlocked': - $this->properties[$name] = $value; - break; - case 'identifier': - throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ ); - break; - default: - throw new ezcBasePropertyNotFoundException( $name ); - break; - } - - } - - /** - * Returns the property $name. - * - * @throws ezcBasePropertyNotFoundException if the property does not exist. - * @param string $name - * @return mixed - */ - public function __get( $name ) - { - switch ( $name ) - { - case 'signalsBlocked': - case 'identifier': - return $this->properties[$name]; - break; - - default: - throw new ezcBasePropertyNotFoundException( $name ); - break; - } - } - - - /** - * Emits the signal with the name $signal - * - * Any additional parameters are sent as parameters to the slot. - * - * @param string $signal - * @param ... signal parameters - * @return void - */ - public function emit( $signal ) - { - if( $this->signalsBlocked ) - { - return; - } - - // prepare the parameters - $parameters = array_slice( func_get_args(), 1 ); - - // check if there are any static connections - $priStaticConnections = ezcSignalStaticConnections::getInstance()->getConnections( $this->identifier, $signal ); - $hasPriStaticConnections = false; - if( count( $priStaticConnections ) > (isset( $priStaticConnections[1000] ) ? 1 : 0) ) - { - $hasPriStaticConnections = true; - } - - // fast algorithm if there are no prioritized slots - if( isset( $this->priorityConnections[$signal] ) == 0 && !$hasPriStaticConnections ) - { - if( isset( $this->defaultConnections[$signal] ) ) - { - foreach( $this->defaultConnections[$signal] as $callback ) - { - call_user_func_array( $callback, $parameters ); - } - } - if( isset( $priStaticConnections[1000] ) ) - { - foreach( $priStaticConnections[1000] as $callback ) - { - call_user_func_array( $callback, $parameters); - } - } - } - else // default algorithm - { - // order slots - $defaultKeys = array(); - if( isset( $this->priorityConnections[$signal] ) ) - { - $defaultKeys = array_keys( $this->priorityConnections[$signal] ); - } - $staticKeys = array_keys( $priStaticConnections ); - - $allKeys = array_unique( array_merge( $defaultKeys, $staticKeys, array( 1000 ) /*default*/ ) ); - sort( $allKeys, SORT_NUMERIC ); - - foreach( $allKeys as $key ) // call all slots in the correct order - { - if( $key == 1000 && isset( $this->defaultConnections[$signal] ) ) - { - foreach( $this->defaultConnections[$signal] as $callback ) - { - call_user_func_array( $callback, $parameters ); - } - } - if( isset( $this->priorityConnections[$signal][$key] ) ) - { - foreach( $this->priorityConnections[$signal][$key] as $callback ) - { - call_user_func_array( $callback, $parameters ); - } - } - if( isset( $priStaticConnections[$key] ) ) - { - foreach( $priStaticConnections[$key] as $callback ) - { - call_user_func_array( $callback, $parameters ); - } - } - } - } - -} - - /** - * Connects the signal $signal to the slot $slot. - * - * To control the order in which slots are called you can set a priority - * from 1 - 65 536. The lower the number the higher the priority. The default - * priority is 1000. - * Slots with the same priority may be called with in any order. - * - * A slot will be called once for every time it is connected. It is possible - * to connect a slot more than once. - * - * See the PHP documentation for examples on the callback type. - * http://php.net/callback. - * - * We reccommend avoiding excessive usage of the $priority parameter - * since it makes it much harder to track how your program works. - * - * @param string $signal - * @param callback $slot - * @param int priority - * @return void - */ - public function connect( $signal, $slot, $priority = 1000 ) - { - if( $priority === 1000 ) // default - { - $this->defaultConnections[$signal][] = $slot; - } - else - { - $this->priorityConnections[$signal][$priority][] = $slot; - sort( $this->priorityConnections[$signal][$priority], SORT_NUMERIC ); - } - } - - /** - * Disconnects the $slot from the $signal. - * - * If the priority is given it will try to disconnect a slot with that priority. - * If no such slot is found no slot will be disconnected. - * - * If no priority is given it will disconnect the matching slot with the lowest priority. - * - * @param string $signal - * @param callback $slot - * @param int priority - * @return void - */ - public function disconnect( $signal, $slot, $priority = null ) - { - if( $priority === null ) // delete first found, searched from back - { - $priorityKeys = array(); - if( isset( $this->priorityConnections[$signal] ) ) - { - $priorityKeys = array_keys( $this->priorityConnections[$signal] ); - } - - $allPriorities = array_unique( array_merge( $priorityKeys, array( 1000 ) /*default*/ ) ); - rsort( $allPriorities, SORT_NUMERIC ); - foreach( $allPriorities as $priority ) - { - if( $priority === 1000 ) - { - if( isset( $this->defaultConnections[$signal] ) ) - { - foreach( $this->defaultConnections[$signal] as $key => $callback ) - { - if( ezcSignalCallbackComparer::compareCallbacks( $slot, $callback ) ) - { - unset( $this->defaultConnections[$signal][$key] ); - return; - } - } - } - } - else - { - if( isset( $this->priorityConnections[$signal] ) && - isset( $this->priorityConnections[$signal][$priority] ) ) - { - foreach( $this->priorityConnections[$signal][$priority] as $key => $callback) - { - if( ezcSignalCallbackComparer::compareCallbacks( $slot, $callback ) ) - { - unset( $this->priorityConnections[$signal][$priority][$key] ); - return; - } - } - } - } - } - - } - else if( $priority === 1000 ) // only delete from default - { - if( isset( $this->defaultConnections[$signal] ) ) - { - foreach( $this->defaultConnections[$signal] as $key => $callback ) - { - if( ezcSignalCallbackComparer::compareCallbacks( $slot, $callback ) ) - { - unset( $this->defaultConnections[$signal][$key] ); - return; - } - } - } - } - else // delete from priority connectinos - { - if( isset( $this->priorityConnections[$signal] ) && - isset( $this->priorityConnections[$signal][$priority] ) ) - { - foreach( $this->priorityConnections[$signal][$priority] as $key => $callback ) - { - if( ezcSignalCallbackComparer::compareCallbacks( $slot, $callback ) ) - { - unset( $this->priorityConnections[$signal][$priority][$key] ); - return; - } - } - } - } - } - - // move to private class - public function comp_func( $a, $b ) - { - if( $a === $b ) return 0; - return 1; - } -} -?> Copied: trunk/SignalSlot/src/signal_collection.php (from rev 3535, trunk/SignalObserver/src/signal_collection.php) Deleted: trunk/SignalSlot/src/static_connections.php =================================================================== --- trunk/SignalObserver/src/static_connections.php 2006-09-20 09:59:56 UTC (rev 3504) +++ trunk/SignalSlot/src/static_connections.php 2006-09-22 14:38:48 UTC (rev 3536) @@ -1,200 +0,0 @@ -<?php -/** - * @copyright Copyright (C) 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package SignalObserver - */ - -/** - * ezcSignalStaticConnections makes it possible to connect to signals through the signals identifier. - * - * The static connections allow you to: - * - connect to a signal sent by any object signal collection with the same identifier. Usually the - * identifier is set to the name of the class holding the collection. Using the static connections - * you can connect to a signal sent by any object of that class. - * - * - connect to a signal that does not yet exist. This allows you to delay initialization of the - * emitting object until it is needed. - * - * TODO: examples - * - * @property array $connections Holds the internal structure of signals. The format is - * array(priority=>array(slots)). It can be both read and set in order - * to provide easy setup of the static connections from disk. - * - * @version //autogen// - * @mainclass - * @package SignalObserver - */ -class ezcSignalStaticConnections -{ - /** - * Holds the properties of this class. - * - * @var array(string=>string) - */ - private $properties = array(); - - /** - * ezcSignalStaticConnections singleton instance - * - * @var ezcConfigurationManager - */ - private static $instance = null; - - public static function getInstance() - { - if( self::$instance === null ) - { - self::$instance = new ezcSignalStaticConnections(); - } - return self::$instance; - } - - private function __construct() - { - $this->properties['connections'] = array(); - } - - /** - * Sets the property $name to $value. - * - * @throws ezcBasePropertyNotFoundException if the property does not exist. - * @param string $name - * @param mixed $value - * @return void - */ - public function __set( $name, $value ) - { - switch ( $name ) - { - case 'connections': - $this->properties[$name] = $value; - break; - default: - throw new ezcBasePropertyNotFoundException( $name ); - break; - } - - } - - /** - * Returns the property $name. - * - * @throws ezcBasePropertyNotFoundException if the property does not exist. - * @param string $name - * @return mixed - */ - public function __get( $name ) - { - switch ( $name ) - { - case 'connections': - return (array) $this->properties[$name]; - break; - - default: - throw new ezcBasePropertyNotFoundException( $name ); - break; - } - } - - public function getConnections( $identifier, $signal ) - { - if( isset( $this->connections[$identifier] ) && - isset( $this->connections[$identifier][$signal] ) ) - { - return $this->connections[$identifier][$signal]; - } - return array(); - } - - /** - * Connects the signal $signal emited by any ezcSignalCollection with the identifier - * $identifier to the slot $slot. - * - * To control the order in which slots are called you can set a priority - * from 1 - 65 536. The lower the number the higher the priority. The default - * priority is 1000. - * Slots with the same priority may be called with in any order. - * - * A slot will be called once for every time it is connected. It is possible - * to connect a slot more than once. - * - * See the PHP documentation for examples on the callback type. - * http://php.net/callback - * - * We reccommend avoiding excessive usage of the $priority parameter - * since it makes it much harder to track how your program works. - * - * @param string $identifier - * @param string $signal - * @param callback $slot - * @param int priority - * @return void - */ - public function connect( $identifier, $signal, $slot, $priority = 1000 ) - { - $this->properties['connections'][$identifier][$signal][$priority][] = $slot; - sort( $this->properties['connections'][$identifier][$signal][$priority], SORT_NUMERIC ); - } - - /** - * Disconnects the $slot from the $signal with identifier $identifier.. - * - * If the priority is given it will try to disconnect a slot with that priority. - * If no such slot is found no slot will be disconnected. - * - * If no priority is given it will disconnect the matching slot with the lowest priority. - * - * @param string $identifier - * @param string $signal - * @param callback $slot - * @param int priority - * @return void - */ - public function disconnect( $identifier, $signal, $slot, $priority = null ) - { - if( !isset( $this->connections[$identifier] ) || - !isset( $this->connections[$identifier][$signal] ) ) - { - return; - } - - if( $priority === null ) // delete first found, searched from back - { - $allKeys = array_keys( $this->connections[$identifier][$signal] ); - rsort( $allKeys, SORT_NUMERIC ); - foreach( $allKeys as $priority ) - { - foreach( $this->connections[$identifier][$signal][$priority] as $key => $callback) - { - if( ezcSignalCallbackComparer::compareCallbacks( $slot, $callback ) ) - { - unset( $this->properties['connections'][$identifier][$signal][$priority][$key] ); - return; - } - } - } - - } - else // only delete from priority connections - { - if( isset( $this->connections[$identifier][$signal][$priority] ) ) - { - foreach( $this->connections[$identifier][$signal][$priority] as $key => $callback ) - { - if( ezcSignalCallbackComparer::compareCallbacks( $slot, $callback ) ) - { - unset( $this->properties['connections'][$identifier][$signal][$priority][$key] ); - return; - } - } - } - } - } -} - -?> Copied: trunk/SignalSlot/src/static_connections.php (from rev 3535, trunk/SignalObserver/src/static_connections.php) Deleted: trunk/SignalSlot/tests/signal_collection_test.php =================================================================== --- trunk/SignalObserver/tests/signal_collection_test.php 2006-09-20 09:59:56 UTC (rev 3504) +++ trunk/SignalSlot/tests/signal_collection_test.php 2006-09-22 14:38:48 UTC (rev 3536) @@ -1,210 +0,0 @@ -<?php -/** - * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package SignalObserver - * @subpackage Tests - */ - -require_once( "test_classes.php" ); - -/** - * @package PhpGenerator - * @subpackage Tests - * @TODO: test slots with params by reference - * @TODO: test with invalid priority input - */ -class ezcSignalCollectionTest extends ezcTestCase -{ - private $giver; - private $receiver; - - protected function setUp() - { - $this->giver = new TheGiver(); - $this->receiver = new TheReceiver(); - TheReceiver::$globalFunctionRun = false; - TheReceiver::$staticFunctionRun = false; - } - - public function testSignalsBlocked() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ) ); - $this->giver->signals->signalsBlocked = true; - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array(), $this->receiver->stack ); - } - - public function testSingleSignalNoParamsNoPri() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1" ), $this->receiver->stack ); - } - - public function testSingleSignalOneParamNoPri() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotSingleParam" ) ); - $this->giver->signals->emit( "signal", "on" ); - $this->assertEquals( array( "on" ), $this->receiver->stack ); - } - - public function testSingleSignalTwoParamsNoPri() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotDoubleParams" ) ); - $this->giver->signals->emit( "signal", "the", "turning" ); - $this->assertEquals( array( "theturning" ), $this->receiver->stack ); - } - - public function testSingleSignalsThreeParamsNoPri() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotTrippleParams" ) ); - $this->giver->signals->emit( "signal", "away", "sorrow", "money" ); - $this->assertEquals( array( "awaysorrowmoney" ), $this->receiver->stack ); - } - - public function testThreeSignalsNoParamNoPri() - { - $this->giver->signals->connect( "signal1", array( $this->receiver, "slotNoParams1" ) ); - $this->giver->signals->connect( "signal2", array( $this->receiver, "slotNoParams2" ) ); - $this->giver->signals->connect( "signal3", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->emit( "signal2" ); - $this->giver->signals->emit( "signal1" ); - $this->giver->signals->emit( "signal3" ); - $this->assertEquals( array( "slotNoParams2","slotNoParams1","slotNoParams3" ), $this->receiver->stack ); - } - - public function testThreeSlotsNoParamNoPri() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams2","slotNoParams3","slotNoParams1" ), $this->receiver->stack ); - } - - public function testPriorityFiveSlotsSingleSignal() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ), 1001 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams5" ), 9999 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ), 1 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams4" ), 999 ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1","slotNoParams4","slotNoParams3", "slotNoParams2", "slotNoParams5" ), - $this->receiver->stack ); - } - - public function testPriorityFiveSlotsMultiSignal() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ), 1001 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams5" ), 9999 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ), 1 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams4" ), 999 ); - - $this->giver->signals->connect( "signal2", array( $this->receiver, "slotNoParams1" ), 1001 ); - $this->giver->signals->connect( "signal2", array( $this->receiver, "slotNoParams2" ), 9999 ); - $this->giver->signals->connect( "signal2", array( $this->receiver, "slotNoParams4" ) ); - $this->giver->signals->connect( "signal2", array( $this->receiver, "slotNoParams3" ), 1 ); - $this->giver->signals->connect( "signal2", array( $this->receiver, "slotNoParams5" ), 999 ); - - $this->giver->signals->emit( "signal" ); - $this->giver->signals->emit( "signal2" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams4", "slotNoParams3", "slotNoParams2", "slotNoParams5", - "slotNoParams3", "slotNoParams5", "slotNoParams4", "slotNoParams1", "slotNoParams2"), - $this->receiver->stack ); - } - - public function testGlobalSlot() - { - $this->giver->signals->connect( "signal", "slotFunction" ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( "brain damage", TheReceiver::$globalFunctionRun ); - } - - public function testStaticSlot() - { - $this->giver->signals->connect( "signal", array( "TheReceiver", "slotStatic" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( "have a cigar", TheReceiver::$staticFunctionRun ); - } - - public function testDisconnect() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ) ); - - $this->giver->signals->disconnect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams2", "slotNoParams1" ), $this->receiver->stack ); - } - - public function testAdvancedDisconnectNoPriority() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - $this->giver->signals->disconnect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams2" ), $this->receiver->stack ); - } - - public function testAdvancedDisconnectNoPrioritySeveralConnections() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ), 1 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - $this->giver->signals->disconnect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams3", "slotNoParams1", "slotNoParams2" ), $this->receiver->stack ); - } - - public function testAdvancedDisconnectNoPrioritySeveralConnections2() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ), 5001 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - $this->giver->signals->disconnect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams3", "slotNoParams2" ), $this->receiver->stack ); - } - - - public function testAdvancedDisconnectPriority() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - $this->giver->signals->disconnect( "signal", array( $this->receiver, "slotNoParams3" ), 1000 ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams2" ), $this->receiver->stack ); - } - - public function testAdvancedDisconnectPrioritySeveralConnections() - { - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ), 1 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - $this->giver->signals->disconnect( "signal", array( $this->receiver, "slotNoParams3" ), 1 ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams3", "slotNoParams2" ), $this->receiver->stack ); - } - - public static function suite() - { - return new ezcTestSuite( "ezcSignalCollectionTest" ); - } -} -?> Copied: trunk/SignalSlot/tests/signal_collection_test.php (from rev 3535, trunk/SignalObserver/tests/signal_collection_test.php) Deleted: trunk/SignalSlot/tests/static_connections_test.php =================================================================== --- trunk/SignalObserver/tests/static_connections_test.php 2006-09-20 09:59:56 UTC (rev 3504) +++ trunk/SignalSlot/tests/static_connections_test.php 2006-09-22 14:38:48 UTC (rev 3536) @@ -1,209 +0,0 @@ -<?php -/** - * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package SignalObserver - * @subpackage Tests - */ - -require_once( "test_classes.php" ); - -/** - * @package PhpGenerator - * @subpackage Tests - */ -class ezcSignalStaticConnectionsTest extends ezcTestCase -{ - private $giver; - private $receiver; - - protected function setUp() - { - $this->giver = new TheGiver(); - $this->receiver = new TheReceiver(); - TheReceiver::$globalFunctionRun = false; - TheReceiver::$staticFunctionRun = false; - } - - public function testSingleConnectionGlobalFunction() - { - ezcSignalStaticConnections::getInstance()->connect( 'TheGiver', 'signal', 'slotFunction' ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( "brain damage", TheReceiver::$globalFunctionRun ); - } - - public function testSingleConnectionStaticFunction() - { - ezcSignalStaticConnections::getInstance()->connect( 'TheGiver', 'signal', array( "TheReceiver", "slotStatic" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( "have a cigar", TheReceiver::$staticFunctionRun ); - } - - public function testSingleConnectionMemberFunction() - { - ezcSignalStaticConnections::getInstance()->connect( 'TheGiver', 'signal', array( $this->receiver, "slotNoParams1" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1" ), $this->receiver->stack ); - } - - public function testTwoSameSignalsInDifferentClasses() - { - $giver2 = new TheGiver(); - ezcSignalStaticConnections::getInstance()->connect( 'TheGiver', 'signal', array( $this->receiver, "slotNoParams1" ) ); - $this->giver->signals->emit( "signal" ); - $giver2->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams1" ), $this->receiver->stack ); - } - - public function testTwoSameSignalNameButDifferentIdentifier() - { - $giver2 = new TheGiver( "TheGiver2" ); - ezcSignalStaticConnections::getInstance()->connect( 'TheGiver', 'signal', array( $this->receiver, "slotNoParams1" ) ); - $this->giver->signals->emit( "signal" ); - $giver2->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1" ), $this->receiver->stack ); - } - - public function testAdvancedPriorityStaticConnectionsOnly() - { - ezcSignalStaticConnections::getInstance()->connect( "TheGiver","signal", - array( $this->receiver, "slotNoParams2" ), 1001 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", - array( $this->receiver, "slotNoParams5" ), 9999 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", - array( $this->receiver, "slotNoParams3" ) ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", - array( $this->receiver, "slotNoParams1" ), 1 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", - array( $this->receiver, "slotNoParams4" ), 999 ); - - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams1" ), 1001 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams2" ), 9999 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams4" ) ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams3" ), 1 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams5" ), 999 ); - - $this->giver->signals->emit( "signal" ); - $this->giver->signals->emit( "signal2" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams4", "slotNoParams3", "slotNoParams2", "slotNoParams5", - "slotNoParams3", "slotNoParams5", "slotNoParams4", "slotNoParams1", "slotNoParams2"), - $this->receiver->stack ); - } - - /* - * Sort critirea: - * 1. Priority - * 2. Dynamic over static - * 3. Connection order - */ - public function testAdvancedPriorityStaticAndNormalConnectionsMixed() - { - $giver2 = new TheGiver(); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams2" ) ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams1" ), 998 ); - $this->giver->signals->connect( "signal", array( $this->receiver, "slotNoParams3" ), 999 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver","signal", - array( $this->receiver, "slotNoParams2" ), 1001 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", - array( $this->receiver, "slotNoParams5" ), 9999 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", - array( $this->receiver, "slotNoParams3" ) ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", - array( $this->receiver, "slotNoParams1" ), 1 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", - array( $this->receiver, "slotNoParams4" ), 999 ); - - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams1" ), 1001 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams2" ), 9999 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams4" ) ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams3" ), 1 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal2", - array( $this->receiver, "slotNoParams5" ), 999 ); - - $this->giver->signals->emit( "signal" ); - $giver2->signals->emit( "signal" ); - $this->giver->signals->emit( "signal2" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams1", "slotNoParams3" ,"slotNoParams4", "slotNoParams2", "slotNoParams3", "slotNoParams2", "slotNoParams5", - "slotNoParams1", "slotNoParams4", "slotNoParams3", "slotNoParams2", "slotNoParams5", - "slotNoParams3", "slotNoParams5", "slotNoParams4", "slotNoParams1", "slotNoParams2"), - $this->receiver->stack ); - } - - public function testAdvancedDisconnectNoPriority() - { - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ) ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - ezcSignalStaticConnections::getInstance()->disconnect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams2" ), $this->receiver->stack ); - } - - public function testAdvancedDisconnectNoPrioritySeveralConnections() - { - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ) ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ), 1 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - - ezcSignalStaticConnections::getInstance()->disconnect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams3", "slotNoParams1", "slotNoParams2" ), $this->receiver->stack ); - } - - public function testAdvancedDisconnectNoPrioritySeveralConnections2() - { - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ) ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ), 5001 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - ezcSignalStaticConnections::getInstance()->disconnect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams3", "slotNoParams2" ), $this->receiver->stack ); - } - - - public function testAdvancedDisconnectPriority() - { - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ) ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - ezcSignalStaticConnections::getInstance()->disconnect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ), 1000 ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams1", "slotNoParams2" ), $this->receiver->stack ); - } - - public function testAdvancedDisconnectPrioritySeveralConnections() - { - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams2" ), 5000 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ) ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ), 1 ); - ezcSignalStaticConnections::getInstance()->connect( "TheGiver", "signal", array( $this->receiver, "slotNoParams1" ), 10 ); - - - ezcSignalStaticConnections::getInstance()->disconnect( "TheGiver", "signal", array( $this->receiver, "slotNoParams3" ) ); - $this->giver->signals->emit( "signal" ); - $this->assertEquals( array( "slotNoParams3", "slotNoParams1", "slotNoParams2" ), $this->receiver->stack ); - } - - public static function suite() - { - return new ezcTestSuite( "ezcSignalStaticConnectionsTest" ); - } -} -?> Copied: trunk/SignalSlot/tests/static_connections_test.php (from rev 3535, trunk/SignalObserver/tests/static_connections_test.php) Deleted: trunk/SignalSlot/tests/suite.php =================================================================== --- trunk/SignalObserver/tests/suite.php 2006-09-20 09:59:56 UTC (rev 3504) +++ trunk/SignalSlot/tests/suite.php 2006-09-22 14:38:48 UTC (rev 3536) @@ -1,37 +0,0 @@ -<?php -/** - * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package SignalObserver - * @subpackage Tests - */ - -/** - * Including the tests - */ -require_once( "signal_collection_test.php" ); -require_once( "static_connections_test.php" ); - -/** - * @package PhpGenerator - * @subpackage Tests - */ -class ezcSignalObserverSuite extends ezcTestSuite -{ - public function __construct() - { - parent::__construct(); - $this->setName("SignalObserver"); - - $this->addTest( ezcSignalCollectionTest::suite() ); - $this->addTest( ezcSignalStaticConnectionsTest::suite() ); - } - - public static function suite() - { - return new ezcSignalObserverSuite(); - } -} -?> Copied: trunk/SignalSlot/tests/suite.php (from rev 3535, trunk/SignalObserver/tests/suite.php) Deleted: trunk/SignalSlot/tests/test_classes.php =================================================================== --- trunk/SignalObserver/tests/test_classes.php 2006-09-20 09:59:56 UTC (rev 3504) +++ trunk/SignalSlot/tests/test_classes.php 2006-09-22 14:38:48 UTC (rev 3536) @@ -1,87 +0,0 @@ -<?php -/** - * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package SignalObserver - * @subpackage Tests - */ - -class TheGiver -{ - public $signals; - - public function __construct( $signalID = null ) - { - if( $signalID === null ) - { - $this->signals = new ezcSignalCollection( __CLASS__ ); - } - else - { - $this->signals = new ezcSignalCollection( $signalID ); - } - } -} - - -class TheReceiver -{ - public static $globalFunctionRun = false; - public static $staticFunctionRun = false; - public $stack = array(); - - public function slotNoParams1() - { - array_push( $this->stack, "slotNoParams1" ); - } - - public function slotNoParams2() - { - array_push( $this->stack, "slotNoParams2" ); - } - - public function slotNoParams3() - { - array_push( $this->stack, "slotNoParams3" ); - } - - public function slotNoParams4() - { - array_push( $this->stack, "slotNoParams4" ); - } - - public function slotNoParams5() - { - array_push( $this->stack, "slotNoParams5" ); - } - - public function slotSingleParam( $param1 ) - { - array_push( $this->stack, $param1 ); - } - - public function slotDoubleParams( $param1, $param2 ) - { - array_push( $this->stack, "{$param1}{$param2}" ); - } - - public function slotTrippleParams( $param1, $param2, $param3 ) - { - array_push( $this->stack, "{$param1}{$param2}{$param3}" ); - } - - public static function slotStatic() - { - self::$staticFunctionRun = "have a cigar"; - } -} - -function slotFunction() -{ - TheReceiver::$globalFunctionRun = "brain damage"; -} - - -?> Copied: trunk/SignalSlot/tests/test_classes.php (from rev 3535, trunk/SignalObserver/tests/test_classes.php) -- svn-components mailing list [email protected] http://lists.ez.no/mailman/listinfo/svn-components
