Author: Derick Rethans Date: 2006-09-25 10:21:55 +0200 (Mon, 25 Sep 2006) New Revision: 3571
Log: - Released SignalSlot version 1.0alpha1 Added: releases/SignalSlot/1.0alpha1/ releases/SignalSlot/1.0alpha1/src/internal/callback_comparer.php releases/SignalSlot/1.0alpha1/src/signal_collection.php releases/SignalSlot/1.0alpha1/src/static_connections.php Removed: releases/SignalSlot/1.0alpha1/src/internal/callback_comparer.php releases/SignalSlot/1.0alpha1/src/signal_collection.php releases/SignalSlot/1.0alpha1/src/static_connections.php Modified: release-info/latest releases/SignalSlot/1.0alpha1/src/signal_autoload.php releases/SignalSlot/1.0alpha1/tests/signal_collection_test.php releases/SignalSlot/1.0alpha1/tests/static_connections_test.php releases/SignalSlot/1.0alpha1/tests/suite.php releases/SignalSlot/1.0alpha1/tests/test_classes.php Modified: release-info/latest =================================================================== --- release-info/latest 2006-09-25 08:21:27 UTC (rev 3570) +++ release-info/latest 2006-09-25 08:21:55 UTC (rev 3571) @@ -12,12 +12,14 @@ EventLogDatabaseTiein: 1.0 Execution: 1.0.1 File: 1.0 +Graph: 1.0beta1 ImageAnalysis: 1.0.1 ImageConversion: 1.1.1 Mail: 1.1.2 PersistentObject: 1.1 PersistentObjectDatabaseSchemaTiein: 1.0 PhpGenerator: 1.0.1 +SignalSlot: 1.0alpha1 SystemInformation: 1.0.1 Template: 1.0 Translation: 1.1.1 Copied: releases/SignalSlot/1.0alpha1 (from rev 3565, trunk/SignalSlot) Deleted: releases/SignalSlot/1.0alpha1/src/internal/callback_comparer.php =================================================================== --- trunk/SignalSlot/src/internal/callback_comparer.php 2006-09-24 20:49:23 UTC (rev 3565) +++ releases/SignalSlot/1.0alpha1/src/internal/callback_comparer.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -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 SignalSlot - * @access private - */ - -/** - * Check if two callbacks are the same or not. - * - * @version //autogen// - * @mainclass - * @package SignalSlot - * @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: releases/SignalSlot/1.0alpha1/src/internal/callback_comparer.php (from rev 3570, trunk/SignalSlot/src/internal/callback_comparer.php) =================================================================== --- trunk/SignalSlot/src/internal/callback_comparer.php 2006-09-25 08:21:27 UTC (rev 3570) +++ releases/SignalSlot/1.0alpha1/src/internal/callback_comparer.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -0,0 +1,55 @@ +<?php +/** + * @copyright Copyright (C) 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version 1.0alpha1 + * @filesource + * @package SignalSlot + * @access private + */ + +/** + * Check if two callbacks are the same or not. + * + * @version 1.0alpha1 + * @mainclass + * @package SignalSlot + * @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; + } +} +?> Modified: releases/SignalSlot/1.0alpha1/src/signal_autoload.php =================================================================== --- trunk/SignalSlot/src/signal_autoload.php 2006-09-24 20:49:23 UTC (rev 3565) +++ releases/SignalSlot/1.0alpha1/src/signal_autoload.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -3,7 +3,7 @@ * Autoload definition for classes in SignalSlot package. * * @package SignalSlot - * @version //autogen// + * @version 1.0alpha1 * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. * @license http://ez.no/licenses/new_bsd New BSD License */ Deleted: releases/SignalSlot/1.0alpha1/src/signal_collection.php =================================================================== --- trunk/SignalSlot/src/signal_collection.php 2006-09-24 20:49:23 UTC (rev 3565) +++ releases/SignalSlot/1.0alpha1/src/signal_collection.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -1,319 +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 SignalSlot - */ - -/** - * ezcSignalCollection implements a mechanism for inter and intra object communication. - * 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 SignalSlot - */ -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 = "default" ) - { - $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; - } - } - } - } - } -} -?> Copied: releases/SignalSlot/1.0alpha1/src/signal_collection.php (from rev 3570, trunk/SignalSlot/src/signal_collection.php) =================================================================== --- trunk/SignalSlot/src/signal_collection.php 2006-09-25 08:21:27 UTC (rev 3570) +++ releases/SignalSlot/1.0alpha1/src/signal_collection.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -0,0 +1,319 @@ +<?php +/** + * @copyright Copyright (C) 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version 1.0alpha1 + * @filesource + * @package SignalSlot + */ + +/** + * ezcSignalCollection implements a mechanism for inter and intra object communication. + * 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 1.0alpha1 + * @mainclass + * @package SignalSlot + */ +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 = "default" ) + { + $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; + } + } + } + } + } +} +?> Deleted: releases/SignalSlot/1.0alpha1/src/static_connections.php =================================================================== --- trunk/SignalSlot/src/static_connections.php 2006-09-24 20:49:23 UTC (rev 3565) +++ releases/SignalSlot/1.0alpha1/src/static_connections.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -1,217 +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 SignalSlot - */ - -/** - * 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( identifier => array( signalName => 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 SignalSlot - */ -class ezcSignalStaticConnections -{ - /** - * Holds the properties of this class. - * - * @var array(string=>string) - */ - private $properties = array(); - - /** - * ezcSignalStaticConnections singleton instance. - * - * @var ezcConfigurationManager - */ - private static $instance = null; - - /** - * Returns the instance of the ezcSignalStaticConnections.. - * - * @return ezcConfigurationManager - */ - public static function getInstance() - { - if( self::$instance === null ) - { - self::$instance = new ezcSignalStaticConnections(); - } - return self::$instance; - } - - /** - * Constructs a new empty static connections class. - */ - 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; - } - } - - /** - * Returns all the connections for signals $signal in signal collections - * with the identifier $identifier. - * - * @param string $identifier - * @param string $signal - * @return array(int=>callback) - */ - 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: releases/SignalSlot/1.0alpha1/src/static_connections.php (from rev 3570, trunk/SignalSlot/src/static_connections.php) =================================================================== --- trunk/SignalSlot/src/static_connections.php 2006-09-25 08:21:27 UTC (rev 3570) +++ releases/SignalSlot/1.0alpha1/src/static_connections.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -0,0 +1,217 @@ +<?php +/** + * @copyright Copyright (C) 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version 1.0alpha1 + * @filesource + * @package SignalSlot + */ + +/** + * 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( identifier => array( signalName => array(priority=>array(slots)) ) ). + * It can be both read and set in order + * to provide easy setup of the static connections from disk. + * + * @version 1.0alpha1 + * @mainclass + * @package SignalSlot + */ +class ezcSignalStaticConnections +{ + /** + * Holds the properties of this class. + * + * @var array(string=>string) + */ + private $properties = array(); + + /** + * ezcSignalStaticConnections singleton instance. + * + * @var ezcConfigurationManager + */ + private static $instance = null; + + /** + * Returns the instance of the ezcSignalStaticConnections.. + * + * @return ezcConfigurationManager + */ + public static function getInstance() + { + if ( self::$instance === null ) + { + self::$instance = new ezcSignalStaticConnections(); + } + return self::$instance; + } + + /** + * Constructs a new empty static connections class. + */ + 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; + } + } + + /** + * Returns all the connections for signals $signal in signal collections + * with the identifier $identifier. + * + * @param string $identifier + * @param string $signal + * @return array(int=>callback) + */ + 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; + } + } + } + } + } +} + +?> Modified: releases/SignalSlot/1.0alpha1/tests/signal_collection_test.php =================================================================== --- trunk/SignalSlot/tests/signal_collection_test.php 2006-09-24 20:49:23 UTC (rev 3565) +++ releases/SignalSlot/1.0alpha1/tests/signal_collection_test.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -2,7 +2,7 @@ /** * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// + * @version 1.0alpha1 * @filesource * @package SignalSlot * @subpackage Tests Modified: releases/SignalSlot/1.0alpha1/tests/static_connections_test.php =================================================================== --- trunk/SignalSlot/tests/static_connections_test.php 2006-09-24 20:49:23 UTC (rev 3565) +++ releases/SignalSlot/1.0alpha1/tests/static_connections_test.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -2,7 +2,7 @@ /** * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// + * @version 1.0alpha1 * @filesource * @package SignalSlot * @subpackage Tests Modified: releases/SignalSlot/1.0alpha1/tests/suite.php =================================================================== --- trunk/SignalSlot/tests/suite.php 2006-09-24 20:49:23 UTC (rev 3565) +++ releases/SignalSlot/1.0alpha1/tests/suite.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -2,7 +2,7 @@ /** * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// + * @version 1.0alpha1 * @filesource * @package SignalSlot * @subpackage Tests Modified: releases/SignalSlot/1.0alpha1/tests/test_classes.php =================================================================== --- trunk/SignalSlot/tests/test_classes.php 2006-09-24 20:49:23 UTC (rev 3565) +++ releases/SignalSlot/1.0alpha1/tests/test_classes.php 2006-09-25 08:21:55 UTC (rev 3571) @@ -2,7 +2,7 @@ /** * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// + * @version 1.0alpha1 * @filesource * @package SignalSlot * @subpackage Tests -- svn-components mailing list [email protected] http://lists.ez.no/mailman/listinfo/svn-components
