Browse files

changes to backport project to PHP < 5.3

  • Loading branch information...
1 parent 720c1c1 commit 99cab2ad3cdc692b6e0e04e1130a788c6a5c8096 Timo Michna committed Aug 24, 2010
Showing with 997 additions and 254 deletions.
  1. +3 −3 examples/Cafe/config/config.xml
  2. +10 −3 examples/Cafe/example.php
  3. +2 −2 examples/Cafe/lib/model/Barista.php
  4. +2 −2 examples/Cafe/misc/bootstrap.php
  5. +1 −1 examples/HelloWorld/hello_world_configured.php
  6. +11 −2 examples/HelloWorld/hello_world_scripted.php
  7. +1 −1 misc/bootstrap.php
  8. +3 −3 src/ABS/channel/PEIP_ABS_Interceptable_Message_Channel.php
  9. +23 −26 src/ABS/handler/PEIP_ABS_Message_Handler.php
  10. +49 −0 src/ABS/transformer/PEIP_ABS_Content_Transformer
  11. +49 −0 src/ABS/transformer/PEIP_ABS_Content_Transformer.php
  12. +75 −0 src/ABS/transformer/PEIP_ABS_Transformer.php
  13. +24 −0 src/INF/transformer/PEIP_INF_Transformer.php
  14. +1 −1 src/PEIP.php
  15. +20 −5 src/autoload/PEIP_Autoload.php
  16. +4 −0 src/autoload/PEIP_Autoload_Paths.php
  17. +1 −1 src/autoload/PEIP_Simple_Autoload.php
  18. +108 −0 src/base/PEIP_Object_Storage.php
  19. +2 −2 src/base/PEIP_Sealer.php
  20. +37 −0 src/channel/PEIP_Channel_Adapter.php
  21. +1 −1 src/channel/PEIP_Channel_Registry.php
  22. +1 −1 src/channel/PEIP_Pollable_Channel.php
  23. +33 −19 src/context/PEIP_XML_Context.php
  24. +48 −30 src/dispatcher/PEIP_Object_Map_Dispatcher.php
  25. +7 −0 src/pipe/PEIP_Event_Pipe.php
  26. +28 −0 src/service/PEIP_String_Service_Activator.php
  27. +57 −0 test.txt
  28. +9 −9 tests/AllTests.php
  29. +37 −0 tests/_files/CallableObject.php
  30. +1 −1 tests/_files/HelloService.php
  31. +22 −0 tests/_files/PublishSubscribeHandler.php
  32. +21 −0 tests/_files/PublishSubscribeHandlerEvent.php
  33. +22 −0 tests/_files/PublishSubscribeHandlerFail.php
  34. +4 −4 tests/base/AllTests.php
  35. +2 −2 tests/base/DynamicAdapterTest.php
  36. +3 −3 tests/base/GenericBuilderTest.php
  37. +53 −0 tests/base/ObjectStorageTest.php
  38. +1 −1 tests/base/ReflectionClassBuilderTest.php
  39. +2 −2 tests/base/SealerTest.php
  40. +1 −1 tests/channel/AllTests.php
  41. +8 −7 tests/channel/InterceptableMessageChannelTest.php
  42. +76 −0 tests/channel/PublishSubscribeChanelTest.php
  43. +1 −1 tests/command/AllTests.php
  44. +2 −2 tests/command/CommandTest.php
  45. +1 −1 tests/data/AllTests.php
  46. +1 −1 tests/data/ParameterHolderTest.php
  47. +3 −3 tests/dispatcher/AllTests.php
  48. +14 −18 tests/dispatcher/DispatcherTest.php
  49. +3 −5 tests/dispatcher/ObjectEventDispatcherTest.php
  50. +21 −24 tests/dispatcher/ObjectMapDispatcherTest.php
  51. +2 −2 tests/event/AllTests.php
  52. +14 −13 tests/event/EventBuilderTest.php
  53. +2 −2 tests/event/EventTest.php
  54. +12 −0 tests/handler/AllTests.php
  55. +13 −10 tests/handler/CallableHandlerTest.php
  56. +4 −4 tests/message/AllTests.php
  57. +12 −14 tests/message/CallableMessageHandlerTest.php
  58. +2 −2 tests/message/GenericMessageTest.php
  59. +1 −1 tests/message/MessageBuilderTest.php
  60. +3 −3 tests/message/StringMessageTest.php
  61. +1 −1 tests/service/AllTests.php
  62. +22 −14 tests/service/ServiceActivatorTest.php
View
6 examples/Cafe/config/config.xml
@@ -41,7 +41,7 @@
<service_activator
input_channel="hotDrinks"
ref="barista"
- method="prepareHotDrink"
+ method="prepareHotDrink"
output_channel="preparedDrinks"/>
<aggregator
@@ -56,12 +56,12 @@
<service_activator
input_channel="DrinkAggregator"
ref="waiter"
- method="prepareDelivery"
+ method="prepareDelivery"
output_channel="deliveries"/>
<service_activator
input_channel="acceptedOrders"
ref="DrinkAggregator"
- method="receiveOrder"/>
+ method="receiveOrder"/>
</config>
View
13 examples/Cafe/example.php
@@ -1,7 +1,7 @@
<?php
// please, change "<br>" to "\n" in the follwing line, when you run this file in the CLI
-define('PEIP_LINE_SEPARATOR', "<br>");
+define('PEIP_LINE_SEPARATOR', "\n");
// This is PEIP´s (basic) way of the famous starbucks example from
// Gregor Hohpe http://www.eaipatterns.com/ramblings/18_starbucks.html
@@ -13,9 +13,10 @@
// requiring autoloader
-require_once(__DIR__.'/misc/bootstrap.php');
+require_once(dirname(__FILE__).'/misc/bootstrap.php');
-$context = PEIP_XML_Context::createFromFile(__DIR__.'/config/config.xml');
+
+$context = PEIP_XML_Context::createFromFile(dirname(__FILE__).'/config/config.xml');
$cafe = $context->getGateway('CafeGateway');
// this would be the same done by scripting.
@@ -59,6 +60,12 @@
throw new RuntimeException('Could not get CafeGateway');
}
+function convert($size)
+ {
+ $unit=array('b','kb','mb','gb','tb','pb');
+ return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
+ }
+echo PHP_EOL.PHP_EOL.'memory usage: '.convert(memory_get_usage(true)).PHP_EOL.PHP_EOL;
View
4 examples/Cafe/lib/model/Barista.php
@@ -3,7 +3,7 @@
class Barista {
- private $hotDrinkDelay = 1;
+ private $hotDrinkDelay = 0;
private $coldDrinkDelay = 0;
private $hotDrinkCounter = 0;
private $coldDrinkCounter = 0;
@@ -48,4 +48,4 @@ protected function printAction($cold, $orderNr){
flush();
}
-}
+}
View
4 examples/Cafe/misc/bootstrap.php
@@ -1,6 +1,6 @@
<?php
-require_once(__DIR__.'/../../misc/bootstrap.php');
+require_once(dirname(__FILE__).'/../../../misc/bootstrap.php');
$autoloader = PEIP_Autoload::getInstance();
-$autoloader->scanDirectory(__DIR__.'/../lib/');
+$autoloader->scanDirectory(dirname(__FILE__).'/../lib/');
View
2 examples/HelloWorld/hello_world_configured.php
@@ -6,7 +6,7 @@
// requiring autoloader
-require_once(__DIR__.'/../misc/bootstrap.php');
+require_once(dirname(__FILE__).'/../misc/bootstrap.php');
// simple service class
class HelloService {
View
13 examples/HelloWorld/hello_world_scripted.php
@@ -4,7 +4,7 @@
// requiring autoloader
-require_once(__DIR__.'/../misc/bootstrap.php');
+require_once(dirname(__FILE__).'/../../misc/bootstrap.php');
// simple service class
class HelloService {
@@ -29,4 +29,13 @@ public function greet($name){
$input->send($message);
// receive reply message
-echo $res = $output->receive();
+$res = $output->receive();
+echo "\nReply Message: '$res'\n\n";
+
+function convert($size)
+ {
+ $unit=array('b','kb','mb','gb','tb','pb');
+ return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
+ }
+
+echo convert(memory_get_usage(true));
View
2 misc/bootstrap.php
@@ -1,4 +1,4 @@
<?php
-require_once(__DIR__.'/../src/autoload/PEIP_Autoload.php');
+require_once(dirname(__FILE__).'/../src/autoload/PEIP_Autoload.php');
PEIP_Autoload::getInstance();
View
6 src/ABS/channel/PEIP_ABS_Interceptable_Message_Channel.php
@@ -43,7 +43,7 @@ public function __construct($name){
/**
* @access public
- * @return string the channel´s name
+ * @return string the channels name
*/
public function getName(){
return $this->name;
@@ -183,7 +183,7 @@ public function clearInterceptors(){
* @return
*/
public function connect($name, PEIP_INF_Handler $listener){
- $this->getEventDispatcher()->connect($name, $this, $listener);
+ return $this->getEventDispatcher()->connect($name, $this, $listener);
}
/**
@@ -193,7 +193,7 @@ public function connect($name, PEIP_INF_Handler $listener){
* @return
*/
public function disconnect($name, PEIP_INF_Handler $listener){
- $this->getEventDispatcher()->disconnect($name, $this, $listener);
+ return $this->getEventDispatcher()->disconnect($name, $this, $listener);
}
/**
View
49 src/ABS/handler/PEIP_ABS_Message_Handler.php
@@ -35,7 +35,13 @@
* @return
*/
public function handle($message){
- return $this->doHandle($message);
+ $message = $this->getMessageFromObject($message);
+ if(!is_object($message)){
+ throw new Exception('Could not get Message from Channel');
+ }else{
+ return $this->doHandle($message);
+ }
+
}
/**
@@ -67,33 +73,24 @@ public function setInputChannel(PEIP_INF_Channel $inputChannel){
*/
protected function doSetInputChannel(PEIP_INF_Channel $inputChannel){
$this->inputChannel = $inputChannel;
- $messageHandler = $this;
- if($inputChannel instanceof PEIP_INF_Subscribable_Channel){
- $getMessage = function ($object){
- return $object;
- };
- $linkChannel = function($handler) use ($messageHandler){
- $messageHandler->getInputChannel()->subscribe($handler);
- };
+ if($this->inputChannel instanceof PEIP_INF_Subscribable_Channel){
+ $this->inputChannel->subscribe($this);
}else{
- $getMessage = function ($object){
- return $object->getContent()->receive();
- };
- $linkChannel = function($handler) use ($messageHandler){
- $messageHandler->getInputChannel()->connect('postSend', $handler);
- };
- }
- $handling = function($object) use ($messageHandler, $getMessage){
- $message = $getMessage($object);
- if(!is_object($message)){
- throw new Exception('Could not get Message from Channel');
- }
- $messageHandler->handle($message);
- };
- $handler = new PEIP_Callable_Message_Handler($handling);
- $linkChannel($handler);
+ $this->inputChannel->connect('postSend', $this);
+ }
}
-
+
+ protected function getMessageFromObject($object){
+ $message = NULL;
+ if($object instanceof PEIP_INF_Event){
+ $message = $object->getContent()->receive();
+ }elseif ($object instanceof PEIP_INF_Message) {
+ $message = $object;
+ }
+ return $message;
+ }
+
+
/**
* Returns the input-channel for this handler.
*
View
49 src/ABS/transformer/PEIP_ABS_Content_Transformer
@@ -0,0 +1,49 @@
+<?php
+
+/*
+ * This file is part of the PEIP package.
+ * (c) 2010 Timo Michna <timomichna/yahoo.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * PEIP_ABS_Content_Transformer
+ * Abstract base class for content-transformers.
+ *
+ * @author Timo Michna <timomichna/yahoo.de>
+ * @package PEIP
+ * @subpackage transformer
+ * @extends PEIP_Pipe
+ * @implements PEIP_INF_Transformer, PEIP_INF_Connectable, PEIP_INF_Subscribable_Channel, PEIP_INF_Channel, PEIP_INF_Handler, PEIP_INF_Message_Builder
+ */
+
+
+abstract class PEIP_ABS_Content_Transformer
+ extends PEIP_ABS_Transformer {
+
+ /**
+ * Transforms a message
+ *
+ * @abstract
+ * @access protected
+ * @param PEIP_INF_Message $message
+ * @return mixed result of transforming the message payload/content
+ */
+ protected function doTransform(PEIP_INF_Message $message){
+ return $this->transformContent($message->getContent());
+ }
+
+ /**
+ * Transforms message-content
+ *
+ * @abstract
+ * @access protected
+ * @param mixed $content content/payload of message
+ * @return mixed result of transforming the message payload/content
+ */
+ abstract protected function transformContent($content);
+
+}
+
View
49 src/ABS/transformer/PEIP_ABS_Content_Transformer.php
@@ -0,0 +1,49 @@
+<?php
+
+/*
+ * This file is part of the PEIP package.
+ * (c) 2010 Timo Michna <timomichna/yahoo.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * PEIP_ABS_Content_Transformer
+ * Abstract base class for content-transformers.
+ *
+ * @author Timo Michna <timomichna/yahoo.de>
+ * @package PEIP
+ * @subpackage transformer
+ * @extends PEIP_Pipe
+ * @implements PEIP_INF_Transformer, PEIP_INF_Connectable, PEIP_INF_Subscribable_Channel, PEIP_INF_Channel, PEIP_INF_Handler, PEIP_INF_Message_Builder
+ */
+
+
+abstract class PEIP_ABS_Content_Transformer
+ extends PEIP_ABS_Transformer {
+
+ /**
+ * Transforms a message
+ *
+ * @abstract
+ * @access protected
+ * @param PEIP_INF_Message $message
+ * @return mixed result of transforming the message payload/content
+ */
+ protected function doTransform(PEIP_INF_Message $message){
+ return $this->transformContent($message->getContent());
+ }
+
+ /**
+ * Transforms message-content
+ *
+ * @abstract
+ * @access protected
+ * @param mixed $content content/payload of message
+ * @return mixed result of transforming the message payload/content
+ */
+ abstract protected function transformContent($content);
+
+}
+
View
75 src/ABS/transformer/PEIP_ABS_Transformer.php
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the PEIP package.
+ * (c) 2010 Timo Michna <timomichna/yahoo.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * PEIP_ABS_Transformer
+ * Abstract base class for transformers.
+ *
+ * @author Timo Michna <timomichna/yahoo.de>
+ * @package PEIP
+ * @subpackage transformer
+ * @extends PEIP_Pipe
+ * @implements PEIP_INF_Transformer, PEIP_INF_Connectable, PEIP_INF_Subscribable_Channel, PEIP_INF_Channel, PEIP_INF_Handler, PEIP_INF_Message_Builder
+ */
+
+
+abstract class PEIP_ABS_Transformer
+ extends PEIP_Pipe {
+
+ /**
+ * constructor
+ *
+ * @access public
+ * @param PEIP_INF_Channel $inputChannel the input-channel
+ * @param PEIP_INF_Channel $outputChannel the outputs-channel
+ * @return
+ */
+ public function __construct(PEIP_INF_Channel $inputChannel, PEIP_INF_Channel $outputChannel = NULL){
+ $this->setInputChannel($inputChannel);
+ if(is_object($outputChannel)){
+ $this->setOutputChannel($outputChannel);
+ }
+ }
+
+ /**
+ * Sends transformed message on output-channel
+ *
+ * @access public
+ * @param PEIP_INF_Message $message message to transform content
+ * @return
+ */
+ public function doReply(PEIP_INF_Message $message){
+ $this->replyMessage($this->transform($message));
+ }
+
+ /**
+ * Transforms a message
+ *
+ * @access public
+ * @param PEIP_INF_Message $message
+ * @return mixed result of transforming the message
+ */
+ public function transform(PEIP_INF_Message $message){
+ return $this->doTransform($message);
+ }
+
+
+ /**
+ * Transforms a message
+ *
+ * @abstract
+ * @access protected
+ * @param PEIP_INF_Message $message
+ * @return mixed result of transforming the message
+ */
+ abstract protected function doTransform(PEIP_INF_Message $message);
+
+}
+
View
24 src/INF/transformer/PEIP_INF_Transformer.php
@@ -0,0 +1,24 @@
+<?php
+
+/*
+ * This file is part of the PEIP package.
+ * (c) 2010 Timo Michna <timomichna/yahoo.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * PEIP_INF_Message_Transformer
+ *
+ * @author Timo Michna <timomichna/yahoo.de>
+ * @package PEIP
+ * @subpackage transformer
+ */
+
+
+interface PEIP_INF_Transformer {
+
+ public function transform(PEIP_INF_Message $message);
+
+}
View
2 src/PEIP.php
@@ -13,6 +13,6 @@
* @author Timo Michna <timomichna/yahoo.de>
* @package PEIP
*/
-require_once(__DIR__.'/autoload/PEIP_Autoload.php');
+require_once(dirname(__FILE__).'/autoload/PEIP_Autoload.php');
PEIP_Autoload::getInstance();
View
25 src/autoload/PEIP_Autoload.php
@@ -1,5 +1,5 @@
<?php
-require_once(__DIR__.'/PEIP_Simple_Autoload.php');
+require_once(dirname(__FILE__).'/PEIP_Simple_Autoload.php');
/*
* This file is part of the PEIP package.
@@ -31,9 +31,24 @@ class PEIP_Autoload extends PEIP_Simple_Autoload {
*/
protected function __construct(){
$this->init();
- require_once(__DIR__.'/PEIP_Autoload_Paths.php');
+ require_once(dirname(__FILE__).'/PEIP_Autoload_Paths.php');
$this->setClassPaths(PEIP_Autoload_Paths::$paths);
}
+
+ /**
+ * Retrieves Singleton instance
+ *
+ * @access public
+ * @static
+ * @return PEIP_Autoload
+ */
+ static public function getInstance(){
+ if (!isset(self::$instance)){
+ self::$instance = new PEIP_Autoload();
+ }
+ return self::$instance;
+ }
+
/**
* @access protected
@@ -67,7 +82,7 @@ public static function make(){
$baseDir = self::getBaseDirectory();
$iterator = new RecursiveDirectoryIterator($baseDir);
$paths = self::findPaths($baseDir, $iterator);
- $pathsFile = __DIR__.'/PEIP_Autoload_Paths.php';
+ $pathsFile = dirname(__FILE__).'/PEIP_Autoload_Paths.php';
$content = file_get_contents($pathsFile);
$content = preg_replace('/public static \$paths = array *\(.*?\);/s', sprintf("public static \$paths = %s;", var_export($paths, true)), $content);
file_put_contents($pathsFile, $content);
@@ -107,9 +122,9 @@ protected static function findPaths($baseDir, RecursiveDirectoryIterator $iterat
*/
public function autoload($class){
if(!$this->getClassPath($class)){
- $this->scanDirectory(realpath(__DIR__.'/../extensions'));
+ $this->scanDirectory(realpath(dirname(__FILE__).'/../extensions'));
}
parent::autoload($class);
}
-}
+}
View
4 src/autoload/PEIP_Autoload_Paths.php
@@ -169,6 +169,10 @@ class PEIP_Autoload_Paths {
'PEIP_Service_Container_Builder' => '/service/PEIP_Service_Container_Builder.php',
'PEIP_Splitting_Service_Activator' => '/service/PEIP_Splitting_Service_Activator.php',
'PEIP_String_Service_Activator' => '/service/PEIP_String_Service_Activator.php',
+'PEIP_Object_Storage' => '/base/PEIP_Object_Storage.php',
+'PEIP_INF_Transformer' => '/INF/transformer/PEIP_INF_Transformer.php',
+'PEIP_ABS_Transformer' => '/ABS/transformer/PEIP_ABS_Transformer.php',
+'PEIP_ABS_Content_Transformer' => '/ABS/transformer/PEIP_ABS_Content_Transformer.php',
'PEIP' => '/PEIP.php',
);
View
2 src/autoload/PEIP_Simple_Autoload.php
@@ -68,7 +68,7 @@ protected static function getBaseDirectory(){
*/
static public function getInstance(){
if (!isset(self::$instance)){
- static::doGetInstance();
+ self::$instance = new PEIP_Simple_Autoload();
}
return self::$instance;
}
View
108 src/base/PEIP_Object_Storage.php
@@ -0,0 +1,108 @@
+<?php
+
+
+if(phpversion() < '5.3.0'){
+// providing api compatibility with SplObjectStorage > php 5.3.0
+
+class PEIP_Object_Storage extends SplObjectStorage implements Countable, Iterator, Traversable, Serializable, ArrayAccess {
+
+ protected
+ $objects = array(),
+ $values = array(),
+ $objectsNr = 0,
+ $arrayIterator = NULL;
+
+ public function attach($object, $data = NULL){
+ return $this->offsetSet($object, $data);
+ }
+
+
+ public function offsetSet($offset, $value){
+ $this->objects[$this->objectsNr] = $offset;
+ $this->values[$this->objectsNr] = $value;
+ $this->objectsNr++;
+ }
+
+ public function offsetGet($offset){
+ if(in_array($offset, $this->objects)){
+ $key = array_search($offset, $this->objects);
+ return $this->values[$key];
+ }
+ }
+
+ public function offsetUnset($offset){
+ if(in_array($offset, $this->objects)){
+ $key = array_search($offset, $this->objects);
+ unset($this->values[$key]);
+ unset($this->objects[$key]);
+ }
+ }
+
+ public function offsetExists($offset){
+ return in_array($offset, $this->objects);
+ }
+
+ public function count(){
+ return count($this->objects);
+ }
+
+ public function rewind(){
+ return $this->arrayIterator->rewind();
+ }
+
+ public function next(){
+ return $this->arrayIterator->next();
+ }
+
+ public function current(){
+ return $this->arrayIterator->current();
+ }
+
+ public function valid(){
+ return $this->arrayIterator->valid();
+ }
+
+ public function key(){
+ return $this->arrayIterator->key();
+ }
+
+ public function getInfo(){
+
+ }
+
+ public function addAll (SplObjectStorage $storage){
+ $storage->rewind();
+ while($storage->valid()){
+ $this->offsetSet($storage->current());
+
+ if($this->offsetExists($storage->current())){
+ $this->offsetUnset($storage->current());
+ }
+ $storage->next();
+ }
+ }
+ public function removeAll (SplObjectStorage $storage){
+ $storage->rewind();
+ while($storage->valid()){
+ if($this->offsetExists($storage->current())){
+ $this->offsetUnset($storage->current());
+ }
+ $storage->next();
+ }
+ }
+
+ public function contains($object){
+ return $this->offsetExists($object);
+ }
+ protected function getArrayIterator(){
+ return is_object($this->arrayIterator)
+ ? $this->arrayIterator
+ : $this->arrayIterator = new ArrayIterator($this->objects);
+ }
+
+
+}
+
+}else{
+ class PEIP_Object_Storage extends SplObjectStorage{}
+}
View
4 src/base/PEIP_Sealer.php
@@ -32,11 +32,11 @@ class PEIP_Sealer implements PEIP_INF_Sealer, PEIP_INF_Unsealer{
* constructor
*
* @access public
- * @param SplObjectStorage $store an instane of SplObjectStorage to act as the internal object-store
+ * @param PEIP_Object_Storage $store an instane of PEIP_Object_Storage to act as the internal object-store
* @return
*/
public function __construct(SplObjectStorage $store = NULL){
- $this->store = (bool)$store ? $store : new SplObjectStorage;
+ $this->store = (bool)$store ? $store : new PEIP_Object_Storage;
}
/**
View
37 src/channel/PEIP_Channel_Adapter.php
@@ -0,0 +1,37 @@
+<?php
+
+
+class PEIP_Channel_Adapter {
+
+ protected $channel;
+ protected $handler;
+
+ public function __construct(PEIP_ABS_Message_Handler $handler, PEIP_INF_CHANNEL $channel){
+ $this->channel = $channel;
+ $this->handler = $handler;
+ }
+
+ protected function getMessage($object){
+ if($this->channel instanceof PEIP_INF_Subscribable_Channel){
+ return $object;
+ }else{
+ return $object->getContent()->receive();
+ }
+ }
+
+ public function handle($object){
+ $message = $this->getMessage($object);
+ if(!is_object($message)){
+ throw new Exception('Could not get Message from Channel');
+ }
+ $this->handler->handle($message);
+ }
+
+
+
+
+
+
+
+}
+
View
2 src/channel/PEIP_Channel_Registry.php
@@ -30,7 +30,7 @@ class PEIP_Channel_Registry
* @param $name
* @return
*/
- public function getInstance(){
+ public static function getInstance(){
return self::$instance ? self::$instance : self::$instance = new PEIP_Channel_Registry;
}
View
2 src/channel/PEIP_Pollable_Channel.php
@@ -46,7 +46,7 @@ protected function doSend(PEIP_INF_Message $message){
* @param integer $timeout timout for receiving a message
* @return
*/
- public function receive($timeout = -1){
+ public function receive($timeout = 1){
$this->getInterceptorDispatcher()->notify('preReceive', array($this));
$this->doFireEvent('preReceive');
$message = NULL;
View
52 src/context/PEIP_XML_Context.php
@@ -204,6 +204,7 @@ protected function initNodeBuilders(){
'service_activator' => 'createServiceActivator',
'gateway' => 'createGateway',
'splitter' => 'createSplitter',
+ 'transformer' => 'createTransformer',
'router' => 'createRouter',
'aggregator' => 'createAggregator',
'wiretap' => 'createWiretap'
@@ -331,7 +332,7 @@ public function createService($config){
foreach($config->constructor_arg as $arg){
$args[] = $this->buildArg($arg);
}
- }
+ }
return $this->buildAndModify($config, $args);
}
@@ -348,24 +349,17 @@ public function createService($config){
* @param object $config configuration to get the modification instructions from.
* @return object the modificated service
*/
- protected function modifyService($service, $config){
+ protected function modifyService($service, $config){
$reflection = PEIP_Generic_Builder::getInstance(get_class($service))->getReflectionClass();
- // helper function
- $hasPublic = function($type, $name)use($reflection){
- if($reflection->{'has'.$type}($name) && $reflection->{'get'.$type}($name)->isPublic()){
- return true;
- }
- return false;
- };
// set instance properties
if($config->property){
foreach($config->property as $property){
$arg = $this->buildArg($property);
if($arg){
$setter = self::getSetter($property);
- if($setter && $hasPublic('Method', $setter)){
+ if($setter && self::hasPublicProperty($service, 'Method', $setter)){
$service->{$setter}($arg);
- }elseif(in_array($property, $hasPublic('Property', $setter))){
+ }elseif(in_array($property, self::hasPublicProperty($service, 'Property', $setter))){
$service->$setter = $arg;
}
}
@@ -375,11 +369,11 @@ protected function modifyService($service, $config){
if($config->action){
foreach($config->action as $action){
$method = (string)$action['method'] != '' ? (string)$action['method'] : NULL;
- if($method && $hasPublic('Method', $method)){
- $args = array();
+ if($method && self::hasPublicProperty($service, 'Method', $method)){
+ $args = array();
foreach($action->children() as $argument){
$args[] = $this->buildArg($argument);
- }
+ }
call_user_func_array(array($service, (string)$action['method']), $args);
}
}
@@ -506,7 +500,20 @@ public function createRouter($config, $defaultClass = false){
public function createSplitter($config){
return $this->createReplyMessageHandler($config);
}
-
+
+ /**
+ * Creates and registers transformer from a configuration object.
+ *
+ * @see PEIP_XML_Context::initNodeBuilders
+ * @see PEIP_XML_Context::createReplyMessageHandler
+ * @access public
+ * @param object $config configuration object for the transformer.
+ * @return object the transformer instance
+ */
+ public function createTransformer($config){
+ return $this->createReplyMessageHandler($config);
+ }
+
/**
* Creates aggregator from a configuration object.
*
@@ -618,7 +625,7 @@ protected static function getSetter($config){
* @param object $config configuration object to create argument from.
* @return mixed build argument
*/
- protected function buildArg($config){
+ protected function buildArg($config){
if(trim((string)$config['value']) != ''){
$arg = (string)$config['value'];
}elseif($config->getName() == 'value'){
@@ -642,8 +649,8 @@ protected function buildArg($config){
$arg = $this->buildArg($config->list);
}elseif($config->service){
$arg = $this->buildArg($config->service);
- }
- return $arg;
+ }
+ return $arg;
}
@@ -799,5 +806,12 @@ protected static function build($className, $arguments){
return PEIP_Generic_Builder::getInstance($className)->build($arguments);
}
+ protected static function hasPublicProperty($service, $type, $name){
+ $reflection = PEIP_Generic_Builder::getInstance(get_class($service))->getReflectionClass();
+ if($reflection->{'has'.$type}($name) && $reflection->{'get'.$type}($name)->isPublic()){
+ return true;
+ }
+ return false;
+ }
-}
+}
View
78 src/dispatcher/PEIP_Object_Map_Dispatcher.php
@@ -37,13 +37,14 @@ class PEIP_Object_Map_Dispatcher
*/
public function connect($name, $object, PEIP_INF_Handler $listener){
$listners = $this->doGetListeners();
- if (!isset($listners[$object])){
- $listners[$object] = new ArrayObject;
+ if (!$listners->contains($object)){
+ $listners->attach($object, new ArrayObject);
}
if (!array_key_exists($name, $listners[$object])){
$listners[$object][$name] = array();
- }
- $this->listeners[$object][$name][spl_object_hash($listener)] = $listener;
+ }
+ $hash = spl_object_hash($listener);
+ $this->listeners[$object][$name][$hash] = $listener;
return true;
}
@@ -58,19 +59,25 @@ public function connect($name, $object, PEIP_INF_Handler $listener){
*/
public function disconnect($name, $object, PEIP_INF_Handler $listener){
$listners = $this->doGetListeners();
- if (!isset($listners[$object]) || !isset($listners[$object][$name])){
+ if (!$listners->contains($object) || !isset($listners[$object][$name])){
return false;
}
$eventListeners = $listners[$object][$name];
- $hash = spl_object_hash($listener);
+ $hash = spl_object_hash($listener);
if(isset($eventListeners[$hash])){
- unset($eventListeners[$hash]);
+ unset($eventListeners[$hash]);
+
$listners[$object][$name] = $eventListeners;
return true;
}
return false;
}
-
+
+ public function disconnectAll($name, $object){
+ $listners = $this->doGetListeners();
+ $listners[$object][$name] = array();
+ }
+
/**
* Checks wether an object has a listener for an event
*
@@ -82,12 +89,13 @@ public function disconnect($name, $object, PEIP_INF_Handler $listener){
public function hasListeners($name, $object){
$listners = $this->doGetListeners();
if (!$this->hadListeners($name, $object)){
- $res = false;
+ $res = false;
}else{
- $res = (boolean) count($this->getListeners($name, $object));
+ $listners = $this->doGetListeners();
+ $res = (boolean) count($listners[$object][$name]);
}
- return $res;
- }
+ return $res;
+ }
/**
* Checks wether an object has or had a listener for an event
@@ -98,9 +106,9 @@ public function hasListeners($name, $object){
* @return boolean
*/
public function hadListeners($name, $object){
- $listners = $this->doGetListeners();
- return (isset($listners[$object]) && isset($listners[$object][$name])) ? true : false;
- }
+ $listners = $this->doGetListeners();
+ return ($listners->contains($object) && isset($listners[$object][$name])) ? true : false;
+ }
/**
* Returns all event-names an object has registered listeners for
@@ -111,7 +119,7 @@ public function hadListeners($name, $object){
*/
public function getEventNames($object){
$listeners = $this->doGetListeners();
- if (!isset($listeners[$object])){
+ if (!$listeners->contains($object)){
return array();
}
return array_keys($listeners[$object]->getArrayCopy());
@@ -127,7 +135,8 @@ public function getEventNames($object){
*/
public function notify($name, $object){
if($this->hasListeners($name, $object)){
- self::doNotify($this->getListeners($name, $object), $object);
+ $listners = $this->doGetListeners();
+ self::doNotify($listners[$object][$name], $object);
}
return true;
}
@@ -146,7 +155,7 @@ public function notifyUntil($name, $subject){
$res = self::doNotifyUntil($this->getListeners($name, $subject), $subject);
}
return $res;
- }
+ }
/**
* Returns all listeners of a given event on an object
@@ -160,18 +169,23 @@ public function getListeners($name, $object){
if (!$this->hadListeners($name, $object)){
return array();
}
- return array_values($this->listeners[$object][$name]);
+ $listeners = $this->listeners[$object];
+ if($listeners instanceof ArrayObject){
+ $ar = $listeners->getArrayCopy();
+ return array_values($ar[$name]);
+ }
+ return array();
}
/**
- * Returns SplObjectStorage object to store objects to lositen to in.
- * creates SplObjectStorage if not exists.
+ * Returns PEIP_Object_Storage object to store objects to lositen to in.
+ * creates PEIP_Object_Storage if not exists.
*
* @access protected
- * @return SplObjectStorage
+ * @return PEIP_Object_Storage
*/
protected function doGetListeners(){
- return isset($this->listeners) ? $this->listeners : $this->listeners = new SplObjectStorage();
+ return isset($this->listeners) ? $this->listeners : $this->listeners = new PEIP_Object_Storage();
}
/**
@@ -185,7 +199,9 @@ protected function doGetListeners(){
*/
protected static function doNotify(array $listeners, $subject){
foreach($listeners as $listener){
- $listener->handle($subject);
+ if($listener instanceof PEIP_INF_Handler){
+ $listener->handle($subject);
+ }
}
}
@@ -199,12 +215,14 @@ protected static function doNotify(array $listeners, $subject){
* @return PEIP_INF_Handler the listener which returned a boolean true value
*/
protected static function doNotifyUntil(array $listeners, $subject){
- $res = NULL;
- foreach ($listeners as $listener){
- $res = $listener->handle($subject);
- if ($res){
- return $listener;
- }
+ $res = NULL;
+ foreach ($listeners as $listener){
+ if($listener instanceof PEIP_INF_Handler){
+ $res = $listener->handle($subject);
+ if ($res){
+ return $listener;
+ }
+ }
}
return $res;
}
View
7 src/pipe/PEIP_Event_Pipe.php
@@ -26,6 +26,13 @@ class PEIP_Event_Pipe
protected
$eventName;
+ public function connectChannel(PEIP_INF_Channel $inputChannel){
+ $this->inputChannel = $inputChannel;
+
+ }
+
+
+
/**
* Sets the input channel for this event-pipe. Contrary to PEIP_Pipe event-pipes
* listen to a given event on the input-channel and hanle resulting event-objects.
View
28 src/service/PEIP_String_Service_Activator.php
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the PEIP package.
+ * (c) 2010 Timo Michna <timomichna/yahoo.de>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * PEIP_Service_Activator
+ *
+ * @author Timo Michna <timomichna/yahoo.de>
+ * @package PEIP
+ * @subpackage service
+ * @extends PEIP_ABS_Service_Activator
+ * @implements PEIP_INF_Message_Builder, PEIP_INF_Handler, PEIP_INF_Channel, PEIP_INF_Subscribable_Channel, PEIP_INF_Connectable
+ */
+
+
+class PEIP_String_Service_Activator
+ extends PEIP_Service_Activator {
+
+ protected
+ $messageClass = 'PEIP_String_Message';
+
+}
View
57 test.txt
@@ -0,0 +1,57 @@
+PHPUnit 3.4.14 by Sebastian Bergmann.
+
+...........................F..........................F..... 60 / 127
+............................................................ 120 / 127
+..FF.FF
+
+Time: 2 seconds, Memory: 13.50Mb
+
+There were 6 failures:
+
+1) InterceptableMessageChannelTest::testDisconnect
+Failed asserting that <null> is true.
+
+/var/www/PEIP/PEIP/tests/channel/InterceptableMessageChannelTest.php:88
+
+2) EventBuilderTest::testBuildAndDispatch
+Failed asserting that two variables reference the same object.
+
+/var/www/PEIP/PEIP/tests/_files/CallableObject.php:19
+/var/www/PEIP/PEIP/src/handler/PEIP_Callable_Handler.php:46
+/var/www/PEIP/PEIP/src/dispatcher/PEIP_Object_Map_Dispatcher.php:188
+/var/www/PEIP/PEIP/src/dispatcher/PEIP_Object_Event_Dispatcher.php:41
+/var/www/PEIP/PEIP/src/event/PEIP_Event_Builder.php:80
+/var/www/PEIP/PEIP/tests/event/EventBuilderTest.php:23
+
+3) ServiceActivatorTest::testSend
+Failed asserting that two strings are equal.
+--- Expected
++++ Actual
+@@ @@
+-Good Morning
++Hello
+
+/var/www/PEIP/PEIP/tests/service/ServiceActivatorTest.php:60
+
+4) ServiceActivatorTest::testReplyServiceActivator
+Failed asserting that <boolean:false> is true.
+
+/var/www/PEIP/PEIP/tests/service/ServiceActivatorTest.php:72
+
+5) ServiceActivatorTest::testHandle
+Failed asserting that two strings are equal.
+--- Expected
++++ Actual
+@@ @@
+-Good Evening
++Hello
+
+/var/www/PEIP/PEIP/tests/service/ServiceActivatorTest.php:101
+
+6) ServiceActivatorTest::testChannelReceiveException
+An expected exception has not been raised.
+
+/var/www/PEIP/PEIP/tests/service/ServiceActivatorTest.php:117
+
+FAILURES!
+Tests: 127, Assertions: 537, Failures: 6.
View
18 tests/AllTests.php
@@ -1,14 +1,14 @@
<?php
-require_once __DIR__.'/base/AllTests.php';
-require_once __DIR__.'/channel/AllTests.php';
-require_once __DIR__.'/command/AllTests.php';
-require_once __DIR__.'/data/AllTests.php';
-require_once __DIR__.'/dispatcher/AllTests.php';
-require_once __DIR__.'/event/AllTests.php';
-require_once __DIR__.'/handler/AllTests.php';
-require_once __DIR__.'/message/AllTests.php';
-require_once __DIR__.'/service/AllTests.php';
+require_once dirname(__FILE__).'/base/AllTests.php';
+require_once dirname(__FILE__).'/channel/AllTests.php';
+require_once dirname(__FILE__).'/command/AllTests.php';
+require_once dirname(__FILE__).'/data/AllTests.php';
+require_once dirname(__FILE__).'/dispatcher/AllTests.php';
+require_once dirname(__FILE__).'/event/AllTests.php';
+require_once dirname(__FILE__).'/handler/AllTests.php';
+require_once dirname(__FILE__).'/message/AllTests.php';
+require_once dirname(__FILE__).'/service/AllTests.php';
class AllTests extends PHPUnit_Framework_TestSuite {
public static function suite(){
View
37 tests/_files/CallableObject.php
@@ -0,0 +1,37 @@
+<?php
+
+
+class CallableObject {
+
+ protected $testCase;
+ protected $object;
+
+ public function __construct(PHPUnit_Framework_TestCase $testCase){
+ $this->testCase = $testCase;
+ }
+
+ public function setObject($object){
+ $this->object = $object;
+ }
+
+ public function callNotify($subject){
+ if(isset($this->object)){
+ $this->testCase->assertSame($this->object, $subject);
+ }else{
+ throw new RuntimeException('Asserted Object must be set first');
+ }
+ }
+
+ public function callUntil(){
+ return true;
+ }
+
+ public function callNoMore(){
+ $this->testCase->fail('Dispatcher should have stopped on last listener');
+ }
+
+ public function returnParam($param){
+ return $param;
+ }
+
+}
View
2 tests/_files/HelloService.php
@@ -9,7 +9,7 @@ public function greet($name){
return $this->salutation.' '.$name;
}
- public function setSalutation($salutation){
+ public function setSalutation($salutation){
$this->salutation = $salutation;
}
View
22 tests/_files/PublishSubscribeHandler.php
@@ -0,0 +1,22 @@
+<?php
+
+class PublishSubscribeHandler implements PEIP_INF_Handler {
+
+ protected $testCase;
+ protected $assertSubject;
+
+ public function __construct($testCase){
+ $this->testCase = $testCase;
+ }
+
+ public function setAssertSubject($subject){
+ $this->assertSubject = $subject;
+ }
+
+ public function handle($subject){
+ $this->testCase->assertSame($this->assertSubject, $subject);
+ }
+
+
+
+}
View
21 tests/_files/PublishSubscribeHandlerEvent.php
@@ -0,0 +1,21 @@
+<?php
+
+class PublishSubscribeHandlerEvent implements PEIP_INF_Handler {
+
+ protected $testCase;
+ protected $assertSubject;
+ protected $headerName = 'MESSAGE';
+
+ public function __construct($testCase){
+ $this->testCase = $testCase;
+ }
+
+ public function setAssertSubject($subject){
+ $this->assertSubject = $subject;
+ }
+
+ public function handle($subject){
+ $this->testCase->assertSame($this->assertSubject, $subject->getHeader($this->headerName));
+ }
+
+}
View
22 tests/_files/PublishSubscribeHandlerFail.php
@@ -0,0 +1,22 @@
+<?php
+
+class PublishSubscribeHandlerFail implements PEIP_INF_Handler {
+
+ protected $testCase;
+ protected $assertSubject;
+
+ public function __construct($testCase){
+ $this->testCase = $testCase;
+ }
+
+ public function setAssertSubject($subject){
+ $this->assertSubject = $subject;
+ }
+
+ public function handle($subject){
+ $this->testCase->fail("Handle should not be called");
+ }
+
+
+
+}
View
8 tests/base/AllTests.php
@@ -1,9 +1,9 @@
<?php
-require_once __DIR__.'/DynamicAdapterTest.php';
-require_once __DIR__.'/GenericBuilderTest.php';
-require_once __DIR__.'/ReflectionClassBuilderTest.php';
-require_once __DIR__.'/SealerTest.php';
+require_once dirname(__FILE__).'/DynamicAdapterTest.php';
+require_once dirname(__FILE__).'/GenericBuilderTest.php';
+require_once dirname(__FILE__).'/ReflectionClassBuilderTest.php';
+require_once dirname(__FILE__).'/SealerTest.php';
class Base_AllTests extends PHPUnit_Framework_TestSuite {
public static function suite(){
View
4 tests/base/DynamicAdapterTest.php
@@ -1,7 +1,7 @@
<?php
-require_once __DIR__.'/../../misc/bootstrap.php';
-PHPUnit_Util_Fileloader::checkAndLoad(__DIR__.'/../_files/DynamicAdapterMock.php');
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/DynamicAdapterMock.php');
class DynamicAdapterTest extends PHPUnit_Framework_TestCase {
View
6 tests/base/GenericBuilderTest.php
@@ -1,9 +1,9 @@
<?php
-require_once __DIR__.'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
-PHPUnit_Util_Fileloader::checkAndLoad(__DIR__.'/../_files/BuilderObjectMock.php');
-PHPUnit_Util_Fileloader::checkAndLoad(__DIR__.'/../_files/BuilderObjectMockConstructor.php');
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/BuilderObjectMock.php');
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/BuilderObjectMockConstructor.php');
class GenericBuilderTest extends PHPUnit_Framework_TestCase {
View
53 tests/base/ObjectStorageTest.php
@@ -0,0 +1,53 @@
+<?php
+
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
+
+
+class ObjectStorageTest extends PHPUnit_Framework_TestCase {
+
+ protected $storage;
+
+ public function setup(){
+ $this->storage = new PEIP_Object_Storage();
+ }
+
+ public function testCount(){
+ for($x = 1; $x < 5; $x++){
+ $object = new stdClass();
+ $this->storage->attach($object);
+ $this->assertEquals($x, $this->storage->count());
+ }
+ }
+
+ public function testAttachObject(){
+ $object1 = new stdClass();
+ $object1->val = 321;
+ $object2 = new stdClass();
+ $object2->val = 456;
+ $this->storage->attach($object1);
+ $this->assertTrue($this->storage->offsetExists($object1));
+ $this->storage->attach($object2);
+ $this->assertTrue($this->storage->offsetExists($object2));
+ }
+
+ public function testAttachSingleValue(){
+ $object1 = new stdClass();
+ $this->storage->attach($object1, 'foo');
+ $this->assertEquals('foo', $this->storage->offsetGet($object1));
+ }
+
+ public function testAttachMultiValues(){
+ $object1 = new stdClass();
+ $object1->val = 321;
+ $object2 = new stdClass();
+ $object2->val = 456;
+ $this->storage->attach($object1, 'foo');
+ $this->assertEquals('foo', $this->storage->offsetGet($object1));
+ $this->storage->attach($object2, 123);
+ $this->assertEquals(123, $this->storage->offsetGet($object2));
+ }
+
+
+
+
+}
View
2 tests/base/ReflectionClassBuilderTest.php
@@ -1,7 +1,7 @@
<?php
-require_once __DIR__.'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
class ReflectionClassBuilderTest extends PHPUnit_Framework_TestCase {
View
4 tests/base/SealerTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
-PHPUnit_Util_Fileloader::checkAndLoad(__DIR__.'/../_files/SealerBoxMock.php');
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/SealerBoxMock.php');
View
2 tests/channel/AllTests.php
@@ -1,6 +1,6 @@
<?php
-require_once __DIR__.'/InterceptableMessageChannelTest.php';
+require_once dirname(__FILE__).'/InterceptableMessageChannelTest.php';
class Channel_AllTests extends PHPUnit_Framework_TestSuite {
public static function suite(){
View
15 tests/channel/InterceptableMessageChannelTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
-PHPUnit_Util_Fileloader::checkAndLoad(__DIR__.'/../_files/InterceptableMessageChannel.php');
-PHPUnit_Util_Fileloader::checkAndLoad(__DIR__.'/../_files/MessageChannelInterceptor.php');
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/InterceptableMessageChannel.php');
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/MessageChannelInterceptor.php');
class InterceptableMessageChannelTest extends PHPUnit_Framework_TestCase {
@@ -75,13 +75,14 @@ public function testSend(){
public function testConnect(){
$this->assertFalse($this->channel->hasListeners('preSend'));
- $handler = new PEIP_Callable_Handler(function(){});
+ $handler = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
$this->channel->connect('preSend', $handler);
- $this->assertTrue($this->channel->hasListeners('preSend'));
+ $this->assertTrue($this->channel->hasListeners('preSend'));
+ $this->channel->disconnect('preSend', $handler);
}
public function testDisconnect(){
- $handler = new PEIP_Callable_Handler(function(){});
+ $handler = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
$this->channel->connect('preSend', $handler);
$this->assertTrue($this->channel->hasListeners('preSend'));
$this->channel->disconnect('preSend', $handler);
@@ -90,4 +91,4 @@ public function testDisconnect(){
-}
+}
View
76 tests/channel/PublishSubscribeChanelTest.php
@@ -0,0 +1,76 @@
+<?php
+
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/InterceptableMessageChannelTest.php';
+require_once dirname(__FILE__).'/../_files/PublishSubscribeHandler.php';
+require_once dirname(__FILE__).'/../_files/PublishSubscribeHandlerFail.php';
+require_once dirname(__FILE__).'/../_files/PublishSubscribeHandlerEvent.php';
+
+class PublishSubscribeChanelTest
+ extends InterceptableMessageChannelTest {
+
+ public function setUp(){
+ $this->channel = new PEIP_Publish_Subscribe_Channel('TestChannel');
+ }
+
+ public function testSubscribe(){
+ $handler = new PublishSubscribeHandler($this);
+ $this->channel->subscribe($handler);
+ $message = new PEIP_Generic_Message('Hallo');
+ $handler->setAssertSubject($message);
+ $this->channel->send($message);
+ }
+
+ public function testUnsubscribe(){
+ $handler = new PublishSubscribeHandlerFail($this);
+ $this->channel->subscribe($handler);
+ $this->channel->unsubscribe($handler);
+ $message = new PEIP_Generic_Message('Hallo');
+ $handler->setAssertSubject($message);
+ $this->channel->send($message);
+ }
+
+ public function testSetMessageDispatcher(){
+ $dispatcher = new PEIP_Dispatcher();
+ $this->channel->setMessageDispatcher($dispatcher);
+ $this->assertSame($dispatcher, $this->channel->getMessageDispatcher());
+ }
+
+ public function testSetMessageDispatcherTransfer(){
+ $handler = new PublishSubscribeHandler($this);
+ $this->channel->subscribe($handler);
+ $dispatcher = new PEIP_Dispatcher();
+ $this->channel->setMessageDispatcher($dispatcher);
+ $this->assertSame($dispatcher, $this->channel->getMessageDispatcher());
+ $message = new PEIP_Generic_Message('Hallo');
+ $handler->setAssertSubject($message);
+ $this->channel->send($message);
+ }
+
+ public function testSetMessageDispatcherTransferFalse(){
+ $handler = new PublishSubscribeHandlerFail($this);
+ $this->channel->subscribe($handler);
+ $dispatcher = new PEIP_Dispatcher();
+ $this->channel->setMessageDispatcher($dispatcher, false);
+ $this->assertSame($dispatcher, $this->channel->getMessageDispatcher());
+ $message = new PEIP_Generic_Message('Hallo');
+ $handler->setAssertSubject($message);
+ $this->channel->send($message);
+ }
+
+ public function testEventPrePublish(){
+ $handler = new PublishSubscribeHandlerEvent($this);
+ $this->channel->connect('prePublish',$handler);
+ $message = new PEIP_Generic_Message('Hallo');
+ $handler->setAssertSubject($message);
+ $this->channel->send($message);
+ }
+ public function testEventPostPublish(){
+ $handler = new PublishSubscribeHandlerEvent($this);
+ $this->channel->connect('postPublish',$handler);
+ $message = new PEIP_Generic_Message('Hallo');
+ $handler->setAssertSubject($message);
+ $this->channel->send($message);
+ }
+
+}
View
2 tests/command/AllTests.php
@@ -1,6 +1,6 @@
<?php
-require_once __DIR__.'/CommandTest.php';
+require_once dirname(__FILE__).'/CommandTest.php';
class Command_AllTests extends PHPUnit_Framework_TestSuite {
public static function suite(){
View
4 tests/command/CommandTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
-PHPUnit_Util_Fileloader::checkAndLoad(__DIR__.'/../_files/CallableMock.php');
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/CallableMock.php');
class CommandTest extends PHPUnit_Framework_TestCase {
View
2 tests/data/AllTests.php
@@ -1,6 +1,6 @@
<?php
-require_once __DIR__.'/ParameterHolderTest.php';
+require_once dirname(__FILE__).'/ParameterHolderTest.php';
class Data_AllTests extends PHPUnit_Framework_TestSuite {
public static function suite(){
View
2 tests/data/ParameterHolderTest.php
@@ -1,6 +1,6 @@
<?php
-require_once __DIR__.'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
class ParameterHolderTest extends PHPUnit_Framework_TestCase {
View
6 tests/dispatcher/AllTests.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/DispatcherTest.php';
-require_once __DIR__.'/ObjectEventDispatcherTest.php';
-require_once __DIR__.'/ObjectMapDispatcherTest.php';
+require_once dirname(__FILE__).'/DispatcherTest.php';
+require_once dirname(__FILE__).'/ObjectEventDispatcherTest.php';
+require_once dirname(__FILE__).'/ObjectMapDispatcherTest.php';
class Dispatcher_AllTests extends PHPUnit_Framework_TestSuite {
public static function suite(){
View
32 tests/dispatcher/DispatcherTest.php
@@ -1,6 +1,8 @@
<?php
-require_once __DIR__.'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../_files/CallableObject.php';
+
class DispatcherTest
extends PHPUnit_Framework_TestCase {
@@ -12,15 +14,15 @@ public function setup(){
}
public function testConnect(){
- $listener = new PEIP_Callable_Handler(function(){});
+ $listener = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
$this->assertFalse($this->dispatcher->hasListeners());
$this->dispatcher->connect($listener);
$this->assertTrue($this->dispatcher->hasListeners());
}
public function testDisconnect(){
- $listener = new PEIP_Callable_Handler(function(){});
+ $listener = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
$this->dispatcher->connect($listener);
$this->assertTrue($this->dispatcher->hasListeners());
$this->dispatcher->disconnect($listener);
@@ -29,36 +31,30 @@ public function testDisconnect(){
public function testNotify(){
$object = new stdClass;
- $test = $this;
$this->assertFalse($this->dispatcher->hasListeners());
- $listener = new PEIP_Callable_Handler(function($subject) use ($test, $object){
- $test->assertSame($object, $subject);
- });
+ $callable = new CallableObject($this);
+ $callable->setObject($object);
+ $listener = new PEIP_Callable_Handler(array($callable, 'callNotify'));
$this->dispatcher->connect($listener);
$this->dispatcher->notify($object);
}
public function testNotifyUntil(){
$object = new stdClass;
- $test = $this;
+ $callable = new CallableObject($this);
+ $callable->setObject($object);
$listeners = array();
- $listener1 = new PEIP_Callable_Handler(function($subject) use ($test, $object){
- $test->assertSame($object, $subject);
- });
+ $listener1 = new PEIP_Callable_Handler(array($callable, 'callNotify'));
$this->dispatcher->connect($listener1);
$breaker = $this->dispatcher->notifyUntil($object);
- $listener2 = new PEIP_Callable_Handler(function($subject){
- return true;
- });
+ $listener2 = new PEIP_Callable_Handler(array($callable, 'callUntil'));
$this->dispatcher->connect($listener2);
$breaker = $this->dispatcher->notifyUntil($object);
- $listener3 = new PEIP_Callable_Handler(function($subject){
- $test->fail('Dispatcher should have stopped on last listener');
- });
+ $listener3 = new PEIP_Callable_Handler(array($callable, 'callNoMore'));
$this->dispatcher->connect($listener3);
$breaker = $this->dispatcher->notifyUntil($object);
$this->assertSame($listener2, $breaker);
}
-}
+}
View
8 tests/dispatcher/ObjectEventDispatcherTest.php
@@ -1,6 +1,6 @@
<?php
-require_once __DIR__.'/ObjectMapDispatcherTest.php';
+require_once dirname(__FILE__).'/ObjectMapDispatcherTest.php';
class ObjectEventDispatcherTest
extends ObjectMapDispatcherTest {
@@ -12,11 +12,9 @@ public function setup(){
public function testNotify(){
$object = new stdClass;
$event = new PEIP_Event($object, 'foo');
- $test = $this;
+ $callable = new CallableObject($this);
$this->assertFalse($this->dispatcher->hasListeners('foo', $object));
- $listener = new PEIP_Callable_Handler(function($subject) use ($test, $object){
- $test->assertSame($object, $subject);
- });
+ $listener = new PEIP_Callable_Handler(array($callable, 'callNotify'));
$this->dispatcher->connect('foo', $event, $listener);
$this->dispatcher->notify('foo', $event);
}
View
45 tests/dispatcher/ObjectMapDispatcherTest.php
@@ -1,6 +1,7 @@
<?php
-require_once __DIR__.'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
+require_once dirname(__FILE__).'/../_files/CallableObject.php';
class ObjectMapDispatcherTest
extends PHPUnit_Framework_TestCase {
@@ -14,14 +15,14 @@ public function setup(){
public function testConnect(){
$object = new stdClass;
$this->assertFalse($this->dispatcher->hasListeners('foo', $object));
- $handler = new PEIP_Callable_Handler(function(){});
+ $handler = new PEIP_Callable_Handler(array('TestClass', 'TestMethod'));
$this->dispatcher->connect('foo', $object, $handler);
$this->assertTrue($this->dispatcher->hasListeners('foo', $object));
}
public function testDisconnect(){
$object = new stdClass;
- $handler = new PEIP_Callable_Handler(function(){});
+ $handler = new PEIP_Callable_Handler('TestClass', 'TestMethod');
$this->assertFalse($this->dispatcher->disconnect('foo', $object, $handler));
$this->dispatcher->connect('foo', $object, $handler);
$this->assertTrue($this->dispatcher->hasListeners('foo', $object));
@@ -32,7 +33,7 @@ public function testDisconnect(){
public function testHadListener(){
$object = new stdClass;
- $handler = new PEIP_Callable_Handler(function(){});
+ $handler = new PEIP_Callable_Handler('TestClass', 'TestMethod');
$this->assertFalse($this->dispatcher->hadListeners('foo', $object));
$this->dispatcher->connect('foo', $object, $handler);
$this->assertTrue($this->dispatcher->hadListeners('foo', $object));
@@ -42,7 +43,7 @@ public function testHadListener(){
public function testGetEventNames(){
$object = new stdClass;
- $handler = new PEIP_Callable_Handler(function(){});
+ $handler = new PEIP_Callable_Handler('TestClass', 'TestMethod');
$this->assertEquals(array(), $this->dispatcher->getEventNames($object));
$events = array('foo', 'bar', 'test');
foreach($events as $event){
@@ -52,12 +53,14 @@ public function testGetEventNames(){
}
public function testGetListeners(){
+
$object = new stdClass;
- $this->assertEquals(array(), $this->dispatcher->getListeners('foo', $object));
+ $this->dispatcher->disconnectAll('foo', $object);
+ $this->assertEquals(array(), $this->dispatcher->getListeners('foo', $object));
$listeners = array(
- new PEIP_Callable_Handler(function(){echo 'foo';}),
- new PEIP_Callable_Handler(function(){echo 'bar';}),
- new PEIP_Callable_Handler(function(){echo 'bar';})
+ new PEIP_Callable_Handler('TestClass', 'TestMethod'),
+ new PEIP_Callable_Handler('TestClass', 'TestMethod'),
+ new PEIP_Callable_Handler('TestClass', 'TestMethod')
);
foreach($listeners as $listener){
$this->dispatcher->connect('foo', $object, $listener);
@@ -67,37 +70,31 @@ public function testGetListeners(){
public function testNotify(){
$object = new stdClass;
- $test = $this;
+ $callable = new CallableObject($this);
+ $callable->setObject($object);
$this->assertFalse($this->dispatcher->hasListeners('foo', $object));
- $listener = new PEIP_Callable_Handler(function($subject) use ($test, $object){
- $test->assertSame($object, $subject);
- });
+ $listener = new PEIP_Callable_Handler(array($callable, 'callNotify'));
$this->dispatcher->connect('foo', $object, $listener);
$this->dispatcher->notify('foo', $object);
}
public function testNotifyUntil(){
$object = new stdClass;
- $test = $this;
+ $callable = new CallableObject($this);
+ $callable->setObject($object);
$listeners = array();
- $listener1 = new PEIP_Callable_Handler(function($subject) use ($test, $object){
- $test->assertSame($object, $subject);
- });
+ $listener1 = new PEIP_Callable_Handler(array($callable, 'callNotify'));
$this->dispatcher->connect('foo', $object, $listener1);
$breaker = $this->dispatcher->notifyUntil('foo', $object);
- $listener2 = new PEIP_Callable_Handler(function($subject){
- return true;
- });
+ $listener2 = new PEIP_Callable_Handler(array($callable, 'callUntil'));
$this->dispatcher->connect('foo', $object, $listener2);
$breaker = $this->dispatcher->notifyUntil('foo', $object);
- $listener3 = new PEIP_Callable_Handler(function($subject){
- $test->fail('Dispatcher should have stopped on last listener');
- });
+ $listener3 = new PEIP_Callable_Handler(array($callable, 'callNoMore'));
$this->dispatcher->connect('foo', $object, $listener3);