isCallable() public static method

public static isCallable ( $value, $message = '' )
Example #1
0
 /**
  * Handle the callback.
  *
  * @param array|callable $callback  Callback as Contao array notation or as PHP callable.
  * @param array          $arguments List of arguments being passed to the callback.
  *
  * @return mixed
  * @throws InvalidArgumentException On callback is not callable.
  */
 public function invoke($callback, array $arguments = [])
 {
     if (is_array($callback)) {
         $callback[0] = \System::importStatic($callback[0]);
     }
     Assert::isCallable($callback);
     return call_user_func_array($callback, $arguments);
 }
 /**
  * @param callable $listener
  */
 public function addListener($listener)
 {
     Assert::isCallable($listener, '$listener expected a callable in NativeEventDispatcher::addListener(). Got: %s');
     $this->listeners[] = $listener;
 }
Example #3
0
 /**
  * Creates the command handler.
  *
  * The passed callback receives three arguments:
  *
  *  * {@link Args} `$args`: The console arguments.
  *  * {@link IO} `$io`: The I/O.
  *  * {@link Command} `$command`: The executed command.
  *
  * The callable should return 0 on success and a positive integer on error.
  *
  * @param callable $callback The callback to execute when handling a
  *                           command.
  */
 public function __construct($callback)
 {
     Assert::isCallable($callback);
     $this->callback = $callback;
 }
Example #4
0
 /**
  * Registers a command handler for the given name.
  *
  * @param string          $name    The handler name.
  * @param object|callable $handler The handler or a factory callback that
  *                                 creates the handler.
  */
 public function register($name, $handler)
 {
     Assert::string($name, 'The handler name must be a string. Got: %s');
     Assert::notEmpty($name, 'The handler name must not be empty.');
     if (!is_object($handler)) {
         Assert::isCallable($handler, 'The handler must be a callable or an object. Got: %s');
     }
     $this->handlers[$name] = $handler;
     if (!$this->selectedHandler) {
         $this->selectedHandler = $name;
     }
 }