1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-29 02:27:52 +01:00

Added e107::getEvent()->triggered() for manually checking if an event has already been triggered.

This commit is contained in:
Cameron 2022-06-07 12:33:50 -07:00
parent 08eb2a37d9
commit 8bf3481eaf
3 changed files with 103 additions and 4 deletions

View File

@ -55,6 +55,7 @@ if (isset($_POST['submit_cache']))
if (isset($_POST['trigger_empty_cache']))
{
e107::getLog()->addSuccess(CACLAN_6);
$triggerName = $_POST['option_clear_cache'];
switch ($_POST['option_clear_cache'])
{
case 'empty_contentcache':
@ -101,8 +102,11 @@ if (isset($_POST['trigger_empty_cache']))
e107::getCache()->clearAll('css');
e107::getSession()->clear('addons-update-status');
e107::getLog()->flushMessages(CACLAN_26);
$triggerName = 'default';
break;
}
e107::getEvent()->trigger('admin_after_clear_cache', $triggerName);
}
$syscache_files = glob(e_CACHE_CONTENT.'S_*.*');

View File

@ -21,6 +21,7 @@ class e107_event
var $includes = array();
protected $coreEvents;
private $triggered = array();
protected $oldCoreEvents = array(
@ -181,13 +182,13 @@ class e107_event
/**
* Trigger event
* Triggers an event
*
* @param string $eventname
* @param mixed $data
* @return mixed
*/
function trigger($eventname, $data='')
function trigger($eventname, $data=null)
{
/*if (isset($this->includes[$eventname]))
{
@ -201,10 +202,12 @@ class e107_event
}*/
// echo ($this->debug());
$this->triggered[$eventname] = true;
if (isset($this->functions[$eventname]))
{
foreach($this->functions[$eventname] as $i => $evt_func)
{
$location = '';
@ -257,7 +260,15 @@ class e107_event
return (isset($ret) ? $ret : false);
}
/**
* Returns true if an event has been triggered.
* @param $eventname
* @return bool
*/
public function triggered($eventname)
{
return !empty($this->triggered[$eventname]);
}
/**

View File

@ -0,0 +1,84 @@
<?php
class e107_eventTest extends \Codeception\Test\Unit
{
/** @var e107_event */
protected $ev;
protected function _before()
{
try
{
$this->ev = $this->make('e107_event');
}
catch(Exception $e)
{
$this->fail($e->getMessage());
}
}
public function testTriggered()
{
e107::getEvent()->trigger('user_profile_display', ['foo'=>'bar']);
$result = e107::getEvent()->triggered('user_profile_display');
$this->assertTrue($result);
$result = e107::getEvent()->triggered('non_event');
$this->assertFalse($result);
}
/*
public function testTrigger()
{
}
public function testOldCoreList()
{
}
public function testDebug()
{
}
public function testInit()
{
}
public function testTriggerAdminEvent()
{
}
public function testCoreList()
{
}
public function test__construct()
{
}
public function testRegister()
{
}
public function testTriggerHook()
{
}
*/
}