Deprecated: Assigning the return value of new by reference is deprecated in /home/bluestat/public_html/source/index.php on line 477
From ade558b8b9410380f451dcf6bfc12b5e24f47338 Mon Sep 17 00:00:00 2001
From: Robert Sesek
Date: Mon, 24 Aug 2009 12:02:30 -0400
Subject: [PATCH] Events should not generate any output.
---
events/event.php | 15 +++------------
events/event_pump.php | 24 ++++++++----------------
testing/tests/events/event_pump_test.php | 3 +--
testing/tests/events/event_test.php | 14 --------------
4 files changed, 12 insertions(+), 44 deletions(-)
diff --git a/events/event.php b/events/event.php
index 5ec5668..a089fb5 100644
--- a/events/event.php
+++ b/events/event.php
@@ -16,7 +16,9 @@
namespace phalanx\events;
-// A base representation of an event.
+// A base representation of an event. Events should not generate any output,
+// rather they should store data in member variables, which can then be used by
+// the view system.
abstract class Event
{
// The DateTime that the event occurred at.
@@ -28,13 +30,6 @@ abstract class Event
// Whether or not the event is cancelled.
protected $cancelled = false;
- // Any output that the Event generates. The EventPump will buffer all the
- // output that is generated when it is raised with the pump and store it
- // here. Implementations should either print()/echo() or store output in
- // this variable -- but choose only one! Using both methods could lead to
- // unexpected results.
- protected $output = '';
-
public function __construct(Context $context = null)
{
$this->time = new \DateTime();
@@ -68,8 +63,4 @@ abstract class Event
// cleanup in end().
public function cancel() { $this->cancelled = true; }
public function is_cancelled() { return $this->cancelled; }
-
- public function set_output($output) { $this->output = $output; }
- public function append_output($output) { $this->output .= $output; }
- public function output() { return $this->output; }
}
diff --git a/events/event_pump.php b/events/event_pump.php
index 6755fb0..ad1d6d8 100644
--- a/events/event_pump.php
+++ b/events/event_pump.php
@@ -17,8 +17,8 @@
namespace phalanx\events;
// User interaction and other functions produce events, which are raised and
-// registered with the EventPump. It buffers output and determines the final
-// output to render based on the event stack.
+// registered with the EventPump. The pump executes events as they come in, and
+// the last non-cancelled event is usually the one whose output is rendered.
class EventPump
{
// The shared event pump object.
@@ -53,27 +53,19 @@ class EventPump
$idx = array_push($this->events, $event);
- if (!ob_start())
- throw new EventPumpException('Could not start output buffer.');
-
$event->set_context($this->context);
$event->init();
// See if the event got cancelled during the init.
- if ($event->is_cancelled())
- goto cleanup;
+ if (!$event->is_cancelled())
+ {
+ $this->current_event = $idx - 1;
+ $event->handle();
+ $handled = true;
+ }
- $this->current_event = $idx - 1;
- $event->handle();
- $handled = true;
-
-cleanup:
$event->end();
- $event->set_output(ob_get_contents());
- if (!ob_end_clean())
- throw new EventPumpException('Could not end output buffer.');
-
if ($handled)
$this->context->onEventHandled($event);
}
diff --git a/testing/tests/events/event_pump_test.php b/testing/tests/events/event_pump_test.php
index 1a1769f..6914558 100644
--- a/testing/tests/events/event_pump_test.php
+++ b/testing/tests/events/event_pump_test.php
@@ -112,7 +112,6 @@ class EventPumpTest extends \PHPUnit_Framework_TestCase
$buffer = ob_get_contents();
ob_end_clean();
- $this->assertEquals('init().handle().end().', $event->output());
- $this->assertEquals('', $buffer);
+ $this->assertEquals('init().handle().end().', $buffer);
}
}
diff --git a/testing/tests/events/event_test.php b/testing/tests/events/event_test.php
index cbaa199..31b0191 100644
--- a/testing/tests/events/event_test.php
+++ b/testing/tests/events/event_test.php
@@ -74,18 +74,4 @@ class EventTest extends \PHPUnit_Framework_TestCase
$event->cancel();
$this->assertTrue($event->is_cancelled());
}
-
- public function testSetAndAppendOutput()
- {
- $this->assertEquals($this->event->output(), '');
-
- $this->event->append_output('Append.');
- $this->assertEquals('Append.', $this->event->output());
-
- $this->event->set_output('Reset.');
- $this->assertEquals('Reset.', $this->event->output());
-
- $this->event->append_output('Append.');
- $this->assertEquals('Reset.Append.', $this->event->output());
- }
}
--
1.7.11.3