Elgg\Debug\Inspector::describeCallable PHP Method

describeCallable() public method

E.g. "function_name", "Static::method", "(ClassName)->method", "(Closure path/to/file.php:23)"
public describeCallable ( mixed $callable, string $file_root = '' ) : string
$callable mixed The callable value to describe
$file_root string if provided, it will be removed from the beginning of file names
return string
    public function describeCallable($callable, $file_root = '')
    {
        if (is_string($callable)) {
            return $callable;
        }
        if (is_array($callable) && array_keys($callable) === array(0, 1) && is_string($callable[1])) {
            if (is_string($callable[0])) {
                return "{$callable[0]}::{$callable[1]}";
            }
            return "(" . get_class($callable[0]) . ")->{$callable[1]}";
        }
        if ($callable instanceof \Closure) {
            $ref = new \ReflectionFunction($callable);
            $file = $ref->getFileName();
            $line = $ref->getStartLine();
            if ($file_root && 0 === strpos($file, $file_root)) {
                $file = substr($file, strlen($file_root));
            }
            return "(Closure {$file}:{$line})";
        }
        if (is_object($callable)) {
            return "(" . get_class($callable) . ")->__invoke()";
        }
        return print_r($callable, true);
    }

Usage Example

Beispiel #1
0
 /**
  * Triggers an Elgg event.
  * 
  * @see elgg_trigger_event
  * @see elgg_trigger_after_event
  * @access private
  */
 public function trigger($event, $type, $object = null, array $options = array())
 {
     $options = array_merge(array(self::OPTION_STOPPABLE => true, self::OPTION_DEPRECATION_MESSAGE => '', self::OPTION_DEPRECATION_VERSION => ''), $options);
     $events = $this->hasHandler($event, $type);
     if ($events && $options[self::OPTION_DEPRECATION_MESSAGE]) {
         elgg_deprecated_notice($options[self::OPTION_DEPRECATION_MESSAGE], $options[self::OPTION_DEPRECATION_VERSION], 2);
     }
     $events = $this->getOrderedHandlers($event, $type);
     $args = array($event, $type, $object);
     foreach ($events as $callback) {
         if (!is_callable($callback)) {
             if ($this->logger) {
                 $this->logger->warn("handler for event [{$event}, {$type}] is not callable: " . $this->inspector->describeCallable($callback));
             }
             continue;
         }
         if ($this->timer && $type === 'system' && $event !== 'shutdown') {
             $callback_as_string = $this->inspector->describeCallable($callback) . "()";
             $this->timer->begin(["[{$event},{$type}]", $callback_as_string]);
             $return = call_user_func_array($callback, $args);
             $this->timer->end(["[{$event},{$type}]", $callback_as_string]);
         } else {
             $return = call_user_func_array($callback, $args);
         }
         if (!empty($options[self::OPTION_STOPPABLE]) && $return === false) {
             return false;
         }
     }
     return true;
 }
All Usage Examples Of Elgg\Debug\Inspector::describeCallable