From 79527ef4c43e97060d2412037adcdcb03220a4fa Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 14 Oct 2010 10:52:56 +0000 Subject: Fixes #2403 - adds unregister_entity_type() git-svn-id: http://code.elgg.org/elgg/trunk@7077 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 534b61e19..e788018e0 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -2114,8 +2114,8 @@ function register_entity_type($type, $subtype) { global $CONFIG; $type = strtolower($type); - if (!in_array($type, array('object','site','group','user'))) { - return false; + if (!in_array($type, array('object', 'site', 'group', 'user'))) { + return FALSE; } if (!isset($CONFIG->registered_entities)) { @@ -2130,7 +2130,48 @@ function register_entity_type($type, $subtype) { $CONFIG->registered_entities[$type][] = $subtype; } - return true; + return TRUE; +} + +/** + * Unregisters an entity type and subtype as a public-facing entity. + * + * @warning With a blank subtype, it unregisters that entity type including + * all subtypes. This must be called after all subtypes have been registered. + * + * @param string $type The type of entity (object, site, user, group) + * @param string $subtype The subtype to register (may be blank) + * @return true|false Depending on success + * @see register_entity_type() + */ +function unregister_entity_type($type, $subtype) { + global $CONFIG; + + $type = strtolower($type); + if (!in_array($type, array('object', 'site', 'group', 'user'))) { + return FALSE; + } + + if (!isset($CONFIG->registered_entities)) { + return FALSE; + } + + if (!isset($CONFIG->registered_entities[$type])) { + return FALSE; + } + + if ($subtype) { + if (in_array($subtype, $CONFIG->registered_entities[$type])) { + $key = array_search($subtype, $CONFIG->registered_entities[$type]); + unset($CONFIG->registered_entities[$type][$key]); + } else { + return FALSE; + } + } else { + unset($CONFIG->registered_entities[$type]); + } + + return TRUE; } /** -- cgit v1.2.3