Skip to content

Commit

Permalink
New event_is_declared() function
Browse files Browse the repository at this point in the history
Note: use isset() instead of array_key_exists() as discussed in PR
#1534 (comment)

Replace usage of isset( $g_event_cache[...] ) elsewhere in event API,
by calls to the new function.

Fixes #25953
  • Loading branch information
dregad committed Aug 4, 2019
1 parent fd98a50 commit a709897
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions core/event_api.php
Expand Up @@ -37,6 +37,17 @@
# @global array $g_event_cache
$g_event_cache = array();

/**
* Determine if a given event has been declared
* @param string $p_name Event name
* @return bool True if the even has been declared
*/
function event_is_declared( $p_name ) {
global $g_event_cache;

return isset( $g_event_cache[$p_name] );
}

/**
* Declare an event of a given type.
* Will do nothing if event already exists.
Expand All @@ -48,7 +59,7 @@
function event_declare( $p_name, $p_type = EVENT_TYPE_DEFAULT ) {
global $g_event_cache;

if( !isset( $g_event_cache[$p_name] ) ) {
if( !event_is_declared( $p_name ) ) {
$g_event_cache[$p_name] = array(
'type' => $p_type,
'callbacks' => array(),
Expand Down Expand Up @@ -80,7 +91,7 @@ function event_declare_many( array $p_events ) {
function event_hook( $p_name, $p_callback, $p_plugin = 0 ) {
global $g_event_cache;

if( !isset( $g_event_cache[$p_name] ) ) {
if( !event_is_declared( $p_name ) ) {
error_parameters( $p_name );
trigger_error( ERROR_EVENT_UNDECLARED, WARNING );
return null;
Expand Down Expand Up @@ -135,7 +146,7 @@ function event_clear_callbacks() {
function event_signal( $p_name, $p_params = null, $p_params_dynamic = null, $p_type = null ) {
global $g_event_cache;

if( !isset( $g_event_cache[$p_name] ) ) {
if( !event_is_declared( $p_name ) ) {
error_parameters( $p_name );
trigger_error( ERROR_EVENT_UNDECLARED, WARNING );
return null;
Expand Down

0 comments on commit a709897

Please sign in to comment.