Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F10813306
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/includes/Events.php b/includes/Events.php
index 56335a2..82715c0 100644
--- a/includes/Events.php
+++ b/includes/Events.php
@@ -1,102 +1,77 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Events helper methods class
*
* @package ObsidianWorkspaces
* @subpackage Keruald
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
/**
* Events
*/
class Events {
- /**
- * Determines whether the specified variable is callable.
- *
- * @return boolean If the specified variable is callable, true ; otherwise, false.
- */
- public static function isCallableType ($callable) {
- if (is_string($callable)) {
- return true;
- }
-
- if ($callable instanceof Closure) {
- return true;
- }
-
- if (is_array($callable)) {
- return
- count($callable) == 2
- &&
- (is_array($callable[0]) || is_object($callable[0]))
- &&
- is_string($callable[1])
- ;
- }
- }
-
/**
* Grabs the first exception among specified items.
*
* @param Travesable $items The items to check
* @return Exception|null If an exception has been found, the first encountered : otherwise, null.
*/
public static function grabException (Traversable $items) {
foreach ($items as $item) {
if ($item instanceof Exception) {
return $item;
}
}
return null;
}
/**
* Calls a set of functions with the specified parameters.
* This is intended for callback purpose.
*
* @param array The functions to call, each item a callable
* @param array The parameters to pass to the functions [optional]
*/
public static function call ($callables, $parameters = []) {
foreach ($callables as $callable) {
- if (!isCallableType($callable)) {
+ if (!is_callable($callable)) {
$ex = static::grabException($parameters);
throw new InvalidArgumentException("Callback for this method.", 0, $previousEx);
}
call_user_func_array($callable, $parameters);
}
}
/**
* Calls a set of functions with the specified parameters.
* If no function is present, throws an exception.
*
* @param array The functions to call, each item a callable
* @param array The parameters to pass to the functions [optional]
* @param Exception The exception to throw if no callback is provided
*/
public static function callOrThrow ($callables, $parameters = [], $exception = null) {
if (!count($callables)) {
//Throws an exception
if ($exception === null) {
$exception = static::grabException($parameters);
}
if ($exception === null) {
$exception = new RuntimeException();
}
throw $exception;
}
static::call($callables, $parameters);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jul 29, 13:50 (19 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2853004
Default Alt Text
(3 KB)
Attached To
Mode
rOBSIDIAN Obsidian Workspaces
Attached
Detach File
Event Timeline
Log In to Comment