mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 23:08:46 +02:00
* refactor
* Add event AFTER_DISPLAY_PAGE
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Service\Event;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Application\Branding;
|
||||
use Combodo\iTop\Application\Helper\Session;
|
||||
@@ -488,13 +488,13 @@ class LoginWebPage extends NiceWebPage
|
||||
{
|
||||
if ($bFireEvent)
|
||||
{
|
||||
Event::FireEvent(EventName::LOGIN, null, array('code' => $iErrorCode, 'state' => $sLoginState));
|
||||
EventService::FireEvent(EventName::LOGIN, null, array('code' => $iErrorCode, 'state' => $sLoginState));
|
||||
}
|
||||
return $iErrorCode; // Asked to exit FSM, generally login OK
|
||||
}
|
||||
if ($iResponse == self::LOGIN_FSM_ERROR)
|
||||
{
|
||||
Event::FireEvent(EventName::LOGIN, null, array('code' => $iErrorCode, 'state' => $sLoginState));
|
||||
EventService::FireEvent(EventName::LOGIN, null, array('code' => $iErrorCode, 'state' => $sLoginState));
|
||||
$sLoginState = self::LOGIN_STATE_SET_ERROR; // Next state will be error
|
||||
// An error was detected, skip the other plugins turn
|
||||
break;
|
||||
@@ -508,7 +508,7 @@ class LoginWebPage extends NiceWebPage
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
Event::FireEvent(EventName::LOGIN, null, array('state' => $_SESSION['login_state']));
|
||||
EventService::FireEvent(EventName::LOGIN, null, array('state' => $_SESSION['login_state']));
|
||||
IssueLog::Error($e->getTraceAsString());
|
||||
static::ResetSession();
|
||||
die($e->getMessage());
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Service\Event;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Core\MetaModel\FriendlyNameType;
|
||||
|
||||
@@ -5740,7 +5740,7 @@ abstract class DBObject implements iDisplay
|
||||
{
|
||||
$aEventSources[] = $sClass;
|
||||
}
|
||||
Event::FireEvent($sEvent, $aEventSources, $aEventData);
|
||||
EventService::FireEvent($sEvent, $aEventSources, $aEventData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\Event;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -220,7 +220,7 @@ class ormDocument
|
||||
'object' => $oObj,
|
||||
'document' => $oDocument,
|
||||
);
|
||||
Event::FireEvent(EventName::DOWNLOAD_DOCUMENT, $sClass, $aEventData);
|
||||
EventService::FireEvent(EventName::DOWNLOAD_DOCUMENT, $sClass, $aEventData);
|
||||
$oPage->TrashUnexpectedOutput();
|
||||
$oPage->SetContentType($oDocument->GetMimeType());
|
||||
$oPage->SetContentDisposition($sContentDisposition,$oDocument->GetFileName());
|
||||
|
||||
@@ -29,7 +29,7 @@ use BinaryExpression;
|
||||
use Combodo\iTop\Portal\Brick\CreateBrick;
|
||||
use Combodo\iTop\Portal\Helper\ApplicationHelper;
|
||||
use Combodo\iTop\Portal\Helper\ContextManipulatorHelper;
|
||||
use Combodo\iTop\Service\Event;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use DBObject;
|
||||
use DBObjectSearch;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -356,9 +356,9 @@ return array(
|
||||
'Combodo\\iTop\\Renderer\\FieldRenderer' => $baseDir . '/sources/renderer/FieldRenderer.php',
|
||||
'Combodo\\iTop\\Renderer\\FormRenderer' => $baseDir . '/sources/renderer/FormRenderer.php',
|
||||
'Combodo\\iTop\\Renderer\\RenderingOutput' => $baseDir . '/sources/renderer/RenderingOutput.php',
|
||||
'Combodo\\iTop\\Service\\Event' => $baseDir . '/sources/application/Service/Event.php',
|
||||
'Combodo\\iTop\\Service\\EventData' => $baseDir . '/sources/application/Service/EventData.php',
|
||||
'Combodo\\iTop\\Service\\EventName' => $baseDir . '/sources/application/Service/EventName.php',
|
||||
'Combodo\\iTop\\Service\\EventService' => $baseDir . '/sources/application/Service/EventService.php',
|
||||
'Combodo\\iTop\\TwigExtension' => $baseDir . '/application/twigextension.class.inc.php',
|
||||
'CompileCSSService' => $baseDir . '/application/compilecssservice.class.inc.php',
|
||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||
|
||||
@@ -586,9 +586,9 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
|
||||
'Combodo\\iTop\\Renderer\\FieldRenderer' => __DIR__ . '/../..' . '/sources/renderer/FieldRenderer.php',
|
||||
'Combodo\\iTop\\Renderer\\FormRenderer' => __DIR__ . '/../..' . '/sources/renderer/FormRenderer.php',
|
||||
'Combodo\\iTop\\Renderer\\RenderingOutput' => __DIR__ . '/../..' . '/sources/renderer/RenderingOutput.php',
|
||||
'Combodo\\iTop\\Service\\Event' => __DIR__ . '/../..' . '/sources/application/Service/Event.php',
|
||||
'Combodo\\iTop\\Service\\EventData' => __DIR__ . '/../..' . '/sources/application/Service/EventData.php',
|
||||
'Combodo\\iTop\\Service\\EventName' => __DIR__ . '/../..' . '/sources/application/Service/EventName.php',
|
||||
'Combodo\\iTop\\Service\\EventService' => __DIR__ . '/../..' . '/sources/application/Service/EventService.php',
|
||||
'Combodo\\iTop\\TwigExtension' => __DIR__ . '/../..' . '/application/twigextension.class.inc.php',
|
||||
'CompileCSSService' => __DIR__ . '/../..' . '/application/compilecssservice.class.inc.php',
|
||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||
|
||||
@@ -35,4 +35,7 @@ class EventName
|
||||
// Application
|
||||
//
|
||||
const LOGIN = 'OnLogin';
|
||||
|
||||
// Web Pages
|
||||
const AFTER_DISPLAY_PAGE = 'AfterDisplayPage';
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use IssueLog;
|
||||
|
||||
define('LOG_EVENT_SERVICE_CHANNEL', 'EventService');
|
||||
|
||||
class Event
|
||||
class EventService
|
||||
{
|
||||
private static $aEvents = array();
|
||||
private static $iEventIdCounter = 0;
|
||||
@@ -10,6 +10,8 @@ use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
class AjaxPage extends WebPage implements iTabbedPage
|
||||
{
|
||||
@@ -209,6 +211,7 @@ class AjaxPage extends WebPage implements iTabbedPage
|
||||
// Echo global HTML
|
||||
echo $sHtml;
|
||||
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sHtml) / 1024).' Kb)');
|
||||
$this->FireAfterDisplayEvent();
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
/**
|
||||
* CLI page
|
||||
@@ -37,6 +39,7 @@ class CLIPage implements Page
|
||||
|
||||
public function output()
|
||||
{
|
||||
$this->FireAfterDisplayEvent();
|
||||
if (class_exists('DBSearch')) {
|
||||
DBSearch::RecordQueryTrace();
|
||||
}
|
||||
@@ -45,6 +48,13 @@ class CLIPage implements Page
|
||||
}
|
||||
}
|
||||
|
||||
protected function FireAfterDisplayEvent()
|
||||
{
|
||||
$aData['debug_info'] = 'from: '.get_class($this).":[$this->s_title]";
|
||||
$aData['object'] = $this;
|
||||
EventService::FireEvent(EventName::AFTER_DISPLAY_PAGE, get_class($this), $aData);
|
||||
}
|
||||
|
||||
public function add($sText)
|
||||
{
|
||||
echo $sText;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
/**
|
||||
* Simple web page with no includes or fancy formatting, useful to generateXML documents
|
||||
@@ -52,6 +54,7 @@ class CSVPage extends WebPage
|
||||
echo trim($this->s_content);
|
||||
echo "\n";
|
||||
$oKpi->ComputeAndReport('Echoing ('.round(strlen($this->s_content) / 1024).' Kb)');
|
||||
$this->FireAfterDisplayEvent();
|
||||
|
||||
if (class_exists('DBSearch')) {
|
||||
DBSearch::RecordQueryTrace();
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
|
||||
/**
|
||||
* Class DownloadPage
|
||||
@@ -52,6 +55,7 @@ class DownloadPage extends AjaxPage
|
||||
$oKpi->ComputeAndReport(get_class($this).' output');
|
||||
echo $sContent;
|
||||
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sContent) / 1024).' Kb)');
|
||||
$this->FireAfterDisplayEvent();
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
/**
|
||||
* Class JsonPage
|
||||
*
|
||||
@@ -99,6 +102,7 @@ class JsonPage extends WebPage
|
||||
|
||||
echo $sJSON;
|
||||
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sJSON) / 1024).' Kb)');
|
||||
$this->FireAfterDisplayEvent();
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -142,7 +144,6 @@ EOF
|
||||
/**
|
||||
* Generates the PDF document and returns the PDF content as a string
|
||||
*
|
||||
* @return string
|
||||
* @see WebPage::output()
|
||||
*/
|
||||
public function output()
|
||||
@@ -158,6 +159,7 @@ EOF
|
||||
}
|
||||
$this->flush();
|
||||
echo $this->oPdf->Output($this->s_title.'.pdf', 'S');
|
||||
$this->FireAfterDisplayEvent();
|
||||
}
|
||||
|
||||
public function get_pdf()
|
||||
|
||||
@@ -22,6 +22,8 @@ use Combodo\iTop\Application\Branding;
|
||||
use Combodo\iTop\Application\TwigBase\Twig\TwigHelper;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
$sPortalBaseFolderRelPath = 'env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/';
|
||||
$sPortalSourcesFolderRelPath = $sPortalBaseFolderRelPath . 'src/';
|
||||
@@ -174,6 +176,8 @@ class UnauthenticatedWebPage extends NiceWebPage
|
||||
$oKpi->ComputeAndReport(get_class($this).' output');
|
||||
echo $sHtml;
|
||||
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sHtml) / 1024).' Kb)');
|
||||
$this->FireAfterDisplayEvent();
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,8 @@ use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1344,9 +1346,17 @@ JS;
|
||||
if (class_exists('DBSearch')) {
|
||||
DBSearch::RecordQueryTrace();
|
||||
}
|
||||
$this->FireAfterDisplayEvent();
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
|
||||
protected function FireAfterDisplayEvent()
|
||||
{
|
||||
$aData['debug_info'] = 'from: '.get_class($this).":[$this->s_title]";
|
||||
$aData['object'] = $this;
|
||||
EventService::FireEvent(EventName::AFTER_DISPLAY_PAGE, get_class($this), $aData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a series of hidden field[s] from an array
|
||||
*
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
/**
|
||||
* Simple web page with no includes or fancy formatting, useful to generateXML documents
|
||||
* The page adds the content-type text/XML and the encoding into the headers
|
||||
@@ -71,6 +74,7 @@ class XMLPage extends WebPage
|
||||
if (class_exists('DBSearch')) {
|
||||
DBSearch::RecordQueryTrace();
|
||||
}
|
||||
$this->FireAfterDisplayEvent();
|
||||
ExecutionKPI::ReportStats();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ use Combodo\iTop\Application\UI\Base\UIBlock;
|
||||
use Combodo\iTop\Application\UI\Printable\BlockPrintHeader\BlockPrintHeader;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
|
||||
use Combodo\iTop\Service\EventName;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
|
||||
/**
|
||||
* Web page with some associated CSS and scripts (jquery) for a fancier display
|
||||
@@ -950,6 +952,7 @@ HTML;
|
||||
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sHtml) / 1024).' Kb)');
|
||||
|
||||
DBSearch::RecordQueryTrace();
|
||||
$this->FireAfterDisplayEvent();
|
||||
ExecutionKPI::ReportStats();
|
||||
|
||||
return;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Service;
|
||||
|
||||
use Combodo\iTop\Service\Event;
|
||||
use Combodo\iTop\Service\EventService;
|
||||
use Combodo\iTop\Service\EventData;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use ContextTag;
|
||||
@@ -40,7 +40,7 @@ class EventTest extends ItopTestCase
|
||||
public function testRegisterBadCallback($callback)
|
||||
{
|
||||
$this->expectException(TypeError::class);
|
||||
Event::Register('event', $callback);
|
||||
EventService::Register('event', $callback);
|
||||
}
|
||||
|
||||
public function BadCallbackProvider()
|
||||
@@ -55,9 +55,9 @@ class EventTest extends ItopTestCase
|
||||
|
||||
public function testNoParameterCallbackFunction()
|
||||
{
|
||||
$sId = Event::Register('event', function () { $this->debug("Closure: event received !!!"); self::IncrementCallCount(); });
|
||||
$sId = EventService::Register('event', function () { $this->debug("Closure: event received !!!"); self::IncrementCallCount(); });
|
||||
$this->debug("Registered $sId");
|
||||
Event::FireEvent('event');
|
||||
EventService::FireEvent('event');
|
||||
$this->assertEquals(1, self::$iEventCalls);
|
||||
}
|
||||
|
||||
@@ -70,11 +70,11 @@ class EventTest extends ItopTestCase
|
||||
*/
|
||||
public function testMethodCallbackFunction(callable $callback)
|
||||
{
|
||||
$sId = Event::Register('event', $callback);
|
||||
$sId = EventService::Register('event', $callback);
|
||||
$this->debug("Registered $sId");
|
||||
Event::FireEvent('event');
|
||||
EventService::FireEvent('event');
|
||||
$this->assertEquals(1, self::$iEventCalls);
|
||||
Event::FireEvent('event');
|
||||
EventService::FireEvent('event');
|
||||
$this->assertEquals(2, self::$iEventCalls);
|
||||
}
|
||||
|
||||
@@ -91,115 +91,115 @@ class EventTest extends ItopTestCase
|
||||
public function testBrokenCallback()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
Event::Register('event_a', array($oReceiver, 'BrokenCallback'));
|
||||
EventService::Register('event_a', array($oReceiver, 'BrokenCallback'));
|
||||
|
||||
$this->expectException(TypeError::class);
|
||||
Event::FireEvent('event_a');
|
||||
EventService::FireEvent('event_a');
|
||||
}
|
||||
|
||||
public function testRemovedCallback()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
Event::Register('event_a', array($oReceiver, 'OnEvent1'));
|
||||
EventService::Register('event_a', array($oReceiver, 'OnEvent1'));
|
||||
|
||||
$oReceiver = null;
|
||||
gc_collect_cycles();
|
||||
|
||||
Event::FireEvent('event_a');
|
||||
EventService::FireEvent('event_a');
|
||||
$this->assertEquals(1, self::$iEventCalls);
|
||||
}
|
||||
|
||||
public function testMultiEvent()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
Event::Register('event_a', array($oReceiver, 'OnEvent1'));
|
||||
Event::Register('event_a', array($oReceiver, 'OnEvent2'));
|
||||
Event::Register('event_a', array('Combodo\iTop\Test\UnitTest\Service\TestEventReceiver', 'OnStaticEvent1'));
|
||||
Event::Register('event_a', 'Combodo\iTop\Test\UnitTest\Service\TestEventReceiver::OnStaticEvent2');
|
||||
EventService::Register('event_a', array($oReceiver, 'OnEvent1'));
|
||||
EventService::Register('event_a', array($oReceiver, 'OnEvent2'));
|
||||
EventService::Register('event_a', array('Combodo\iTop\Test\UnitTest\Service\TestEventReceiver', 'OnStaticEvent1'));
|
||||
EventService::Register('event_a', 'Combodo\iTop\Test\UnitTest\Service\TestEventReceiver::OnStaticEvent2');
|
||||
|
||||
Event::Register('event_b', array($oReceiver, 'OnEvent1'));
|
||||
Event::Register('event_b', array($oReceiver, 'OnEvent2'));
|
||||
Event::Register('event_b', array('Combodo\iTop\Test\UnitTest\Service\TestEventReceiver', 'OnStaticEvent1'));
|
||||
Event::Register('event_b', 'Combodo\iTop\Test\UnitTest\Service\TestEventReceiver::OnStaticEvent2');
|
||||
EventService::Register('event_b', array($oReceiver, 'OnEvent1'));
|
||||
EventService::Register('event_b', array($oReceiver, 'OnEvent2'));
|
||||
EventService::Register('event_b', array('Combodo\iTop\Test\UnitTest\Service\TestEventReceiver', 'OnStaticEvent1'));
|
||||
EventService::Register('event_b', 'Combodo\iTop\Test\UnitTest\Service\TestEventReceiver::OnStaticEvent2');
|
||||
|
||||
Event::FireEvent('event_a');
|
||||
EventService::FireEvent('event_a');
|
||||
$this->assertEquals(4, self::$iEventCalls);
|
||||
Event::FireEvent('event_b');
|
||||
EventService::FireEvent('event_b');
|
||||
$this->assertEquals(8, self::$iEventCalls);
|
||||
}
|
||||
|
||||
public function testMultiSameEvent()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(4, self::$iEventCalls);
|
||||
}
|
||||
|
||||
public function testData()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
Event::Register('event1', array($oReceiver, 'OnEventWithData'), '');
|
||||
Event::Register('event1', array($oReceiver, 'OnEventWithData'), '');
|
||||
Event::FireEvent('event1', '', array('text' => 'Event Data 1'));
|
||||
EventService::Register('event1', array($oReceiver, 'OnEventWithData'), '');
|
||||
EventService::Register('event1', array($oReceiver, 'OnEventWithData'), '');
|
||||
EventService::FireEvent('event1', '', array('text' => 'Event Data 1'));
|
||||
$this->assertEquals(2, self::$iEventCalls);
|
||||
}
|
||||
|
||||
public function testPriority()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
Event::Register('event1', array($oReceiver, 'OnEvent1'), '', null, null, 0);
|
||||
Event::Register('event1', array($oReceiver, 'OnEvent2'), '', null, null, 1);
|
||||
EventService::Register('event1', array($oReceiver, 'OnEvent1'), '', null, null, 0);
|
||||
EventService::Register('event1', array($oReceiver, 'OnEvent2'), '', null, null, 1);
|
||||
|
||||
Event::Register('event2', array($oReceiver, 'OnEvent1'), '', null, null, 1);
|
||||
Event::Register('event2', array($oReceiver, 'OnEvent2'), '', null, null, 0);
|
||||
EventService::Register('event2', array($oReceiver, 'OnEvent1'), '', null, null, 1);
|
||||
EventService::Register('event2', array($oReceiver, 'OnEvent2'), '', null, null, 0);
|
||||
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(2, self::$iEventCalls);
|
||||
Event::FireEvent('event2');
|
||||
EventService::FireEvent('event2');
|
||||
$this->assertEquals(4, self::$iEventCalls);
|
||||
}
|
||||
|
||||
public function testContext()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
Event::Register('event1', array($oReceiver, 'OnEvent1'), '', null, null, 0);
|
||||
Event::Register('event1', array($oReceiver, 'OnEvent2'), '', null, 'test_context', 1);
|
||||
Event::FireEvent('event1');
|
||||
EventService::Register('event1', array($oReceiver, 'OnEvent1'), '', null, null, 0);
|
||||
EventService::Register('event1', array($oReceiver, 'OnEvent2'), '', null, 'test_context', 1);
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(1, self::$iEventCalls);
|
||||
ContextTag::AddContext('test_context');
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(3, self::$iEventCalls);
|
||||
}
|
||||
|
||||
public function testEventSource()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
Event::Register('event1', array($oReceiver, 'OnEvent1'), 'A', null, null, 0);
|
||||
Event::Register('event1', array($oReceiver, 'OnEvent2'), 'A', null, null, 1);
|
||||
Event::Register('event1', 'Combodo\iTop\Test\UnitTest\Service\TestEventReceiver::OnStaticEvent1', null, null, null, 2);
|
||||
EventService::Register('event1', array($oReceiver, 'OnEvent1'), 'A', null, null, 0);
|
||||
EventService::Register('event1', array($oReceiver, 'OnEvent2'), 'A', null, null, 1);
|
||||
EventService::Register('event1', 'Combodo\iTop\Test\UnitTest\Service\TestEventReceiver::OnStaticEvent1', null, null, null, 2);
|
||||
|
||||
Event::Register('event2', array($oReceiver, 'OnEvent1'), 'A', null, null, 1);
|
||||
Event::Register('event2', 'Combodo\iTop\Test\UnitTest\Service\TestEventReceiver::OnStaticEvent1', null, null, null, 2);
|
||||
Event::Register('event2', array($oReceiver, 'OnEvent2'), 'B', null, null, 0);
|
||||
EventService::Register('event2', array($oReceiver, 'OnEvent1'), 'A', null, null, 1);
|
||||
EventService::Register('event2', 'Combodo\iTop\Test\UnitTest\Service\TestEventReceiver::OnStaticEvent1', null, null, null, 2);
|
||||
EventService::Register('event2', array($oReceiver, 'OnEvent2'), 'B', null, null, 0);
|
||||
|
||||
Event::FireEvent('event1', 'A');
|
||||
EventService::FireEvent('event1', 'A');
|
||||
$this->assertEquals(3, self::$iEventCalls);
|
||||
Event::FireEvent('event2', 'A');
|
||||
EventService::FireEvent('event2', 'A');
|
||||
$this->assertEquals(5, self::$iEventCalls);
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(6, self::$iEventCalls);
|
||||
Event::FireEvent('event2');
|
||||
EventService::FireEvent('event2');
|
||||
$this->assertEquals(7, self::$iEventCalls);
|
||||
Event::FireEvent('event2', array('A', 'B'));
|
||||
EventService::FireEvent('event2', array('A', 'B'));
|
||||
$this->assertEquals(10, self::$iEventCalls);
|
||||
|
||||
}
|
||||
@@ -208,81 +208,81 @@ class EventTest extends ItopTestCase
|
||||
public function testUnRegisterEvent()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event2', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event2', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(3, self::$iEventCalls);
|
||||
|
||||
Event::FireEvent('event2');
|
||||
EventService::FireEvent('event2');
|
||||
$this->assertEquals(4, self::$iEventCalls);
|
||||
|
||||
Event::UnRegisterEvent('event1');
|
||||
EventService::UnRegisterEvent('event1');
|
||||
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(4, self::$iEventCalls);
|
||||
|
||||
Event::FireEvent('event2');
|
||||
EventService::FireEvent('event2');
|
||||
$this->assertEquals(5, self::$iEventCalls);
|
||||
}
|
||||
|
||||
public function testUnRegisterAll()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event2', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event2', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(3, self::$iEventCalls);
|
||||
|
||||
Event::FireEvent('event2');
|
||||
EventService::FireEvent('event2');
|
||||
$this->assertEquals(4, self::$iEventCalls);
|
||||
|
||||
Event::UnRegisterAll();
|
||||
EventService::UnRegisterAll();
|
||||
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(4, self::$iEventCalls);
|
||||
|
||||
Event::FireEvent('event2');
|
||||
EventService::FireEvent('event2');
|
||||
$this->assertEquals(4, self::$iEventCalls);
|
||||
}
|
||||
|
||||
public function testUnRegisterCallback()
|
||||
{
|
||||
$oReceiver = new TestEventReceiver();
|
||||
$sIdToRemove = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sIdToRemove = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sIdToRemove");
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event1', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
$sId = Event::Register('event2', array($oReceiver, 'OnEvent1'));
|
||||
$sId = EventService::Register('event2', array($oReceiver, 'OnEvent1'));
|
||||
$this->debug("Registered $sId");
|
||||
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(3, self::$iEventCalls);
|
||||
|
||||
Event::FireEvent('event2');
|
||||
EventService::FireEvent('event2');
|
||||
$this->assertEquals(4, self::$iEventCalls);
|
||||
|
||||
Event::UnRegisterCallback($sIdToRemove);
|
||||
EventService::UnRegisterCallback($sIdToRemove);
|
||||
|
||||
Event::FireEvent('event1');
|
||||
EventService::FireEvent('event1');
|
||||
$this->assertEquals(6, self::$iEventCalls);
|
||||
|
||||
Event::FireEvent('event2');
|
||||
EventService::FireEvent('event2');
|
||||
$this->assertEquals(7, self::$iEventCalls);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user