Registers a callback to be called on shutdown.

@param callable $callback
@param null|int $priority The priority of the callback. Lowest number means higher priority.

@throws \InvalidArgumentException
961561
public function register(callable $callback, $priority = null)
    {
        $priority = $this->getPriority($priority);
        if (!isset($this->callbacks[$priority])) {
            $this->callbacks[$priority] = [];
        }
        $this->callbacks[$priority][] = $callback;
        $this->lowestPriority = max($priority, $this->lowestPriority);
    }
295897
public static function error(callable $callback = null){
        $callback
          ? is_callable($callback) && static::$error = $callback
          : static::$error && call_user_func(static::$error);
    }
594327
public function attach($event, $callback, $priority = 0)
    {
        if (!isset($this->eventListeners[$event])) {
            $this->clearListeners($event);
        }

        $this->eventListeners[$event]->insert($callback, $priority);

        return true;
    }
614360
public static function parseRequest( $callback, $priority = null, $accepted_args = null ) {
		self::action( 'parse_request', $callback, $priority, $accepted_args );
	}
1304146
public function on($eventName, $callback, $priority = 0)
    {
        if ($this->booted) {
            $this->container['event_dispatcher']->addListener($eventName, $this->container['callback_resolver']->resolveCallback($callback), $priority);

            return;
        }

        $this->container->extend('event_dispatcher', function ($dispatcher, $c) use ($callback, $priority, $eventName) {
            $dispatcher->addListener($eventName, $c['callback_resolver']->resolveCallback($callback), $priority);

            return $dispatcher;
        });
    }
430335
public static function registrationErrors( $callback, $priority = null, $accepted_args = null ) {
		return self::filter( 'registration_errors', $callback, $priority, $accepted_args );
	}
1234278
public static function on($name, $callback, $priority = 0)
    {
        if (is_string($name) && is_callable($callback)) {
            if (isset(self::$events[$name]) === false) {
                self::$events[$name] = array();
            }

            self::$events[$name][] = array($callback, $priority);
        }
    }
603275
public function setCallback($callback)
    {
        if (!is_callable($callback)) {
            throw new Exception\InvalidArgumentException('Invalid callback provided');
        }

        $this->options['callback'] = $callback;
        return $this;
    }
167270
public function error(callable $callback)
    {
        if ($callback instanceof Closure) {
            $callback = $callback->bindTo($this, get_class($this));
        }

        $this->getErrorProcessor()->register($callback);
        return $this;
    }
232189
public function end(?callable $callback = null): void
    {
        $context =  \array_merge($this->context, [
            'name' => $this->name,
            'started' => $this->startedAt,
            'lapse' => $this->lapse(),
        ]);

        $message = $this->buildMessage($context);

        $this->getLogger()->info($message, $this->context);

        if (\is_callable($callback)) {
            \call_user_func($callback, $message, $context);
        }
    }
750076
public function setCallback($callback)
    {
        // If the provided $value is not a closure, make it one now for easy resolution.
        if (!is_callable($callback)) {
            $callback = function () use ($callback) {
                return $callback;
            };
        }

        if ($this->protected) {
            return $this;
        }

        $this->callback = $callback;

        return $this;
    }
569817
public function pushProcessor($callback)
    {
        if (!is_callable($callback)) {
            throw new \InvalidArgumentException('Processors must be valid callables (callback or object with an __invoke method), '.var_export($callback, true).' given');
        }
        array_unshift($this->processors, $callback);

        return $this;
    }
627809
protected function addEventListener($name, $callback, $priority = null)
    {
        if (is_null($priority)) {
            $this->events->listen($name, $callback);
        } else {
            $this->events->listen($name, $callback, $priority);
        }
    }
765296
public function register(
    /*string*/ $id,
    callable $callback,
    /*int*/ $priority = self::PRIO_EARLY
  ) {
    // Normalize priority.
    $priority = intval($priority);

    // The priority must be valid.
    if(self::PRIO_START <= $priority && self::PRIO_END >= $priority) {
      // Register new callback.
      $this->registerImpl($id, $callback, $priority);
    }
  }
250231
public function setUserCallback (callable $callback)
	{
		//$this->usercallback = $callback;

		if (count ($this->usercallback) > 0)
			throw new InvalidParameter ("A usercallback was already set. Use addUserCallback to add multiple callbacks");

		$this->addUserCallback ('default', $callback);

		return $this;
	}
304951
public function addCallback(string $name, $callback)
    {
        if (!is_object($callback)) {
            throw new \InvalidArgumentException('Given callback must be an object');
        }

        $this->callbacks[$name] = $callback;
    }
1002477
public function condition($callback = null)
        {
            if ($callback !== null) {
                if (!is_callable($callback)) {
                    throw new InvalidArgumentException(
                        sprintf(
                            "Condition provided is not a valid callback. Given (%s)",
                            gettype($callback)
                        )
                    );
                }

                $this->conditionCallback = $callback;

                return $this;
            }

            return $this->conditionCallback;
        }