Adds middleware

@param *callable $callback The middleware handler

@return ErrorProcessorTrait
167270
public function error(callable $callback)
    {
        if ($callback instanceof Closure) {
            $callback = $callback->bindTo($this, get_class($this));
        }

        $this->getErrorProcessor()->register($callback);
        return $this;
    }
1366777
public function addStack(iterable $middlewareStack):QueueRequestHandler{

		foreach($middlewareStack as $middleware){

			if(!$middleware instanceof MiddlewareInterface){
				throw new MiddlewareException('invalid middleware');
			}

			$this->middlewareStack[] = $middleware;
		}

		return $this;
	}
1004981
public function setCallback($callback)
    {
        if ($callback instanceof \OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface) {
            $callback = array($callback, 'execute');
        }
        $this->callback = $callback;

        return $this;
    }
1250096
protected function prepareDestination(Closure $callback)
    {
        return function ($passable) use ($callback)
        {
            try {
                return call_user_func($callback, $passable);
            }
            catch (Exception $e) {
                return $this->handleException($passable, $e);
            }
            catch (Throwable $e) {
                return $this->handleException($passable, new FatalThrowableError($e));
            }
        };
    }
765471
public function control(callable $callback, $context = null)
    {
        $this->control = $callback;
        $this->controlContext = $context;

        return $this;
    }
580643
public function setCallback($callback)
    {
        if (!$callback instanceof Closure) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid parameter for callback: must be %s',
                Closure::class
            ));
        }

        return parent::setCallback($callback);
    }
1327765
public function before($callback)
    {
        $callbacks = $this->getOption('_before_middlewares');
        $callbacks[] = $callback;
        $this->setOption('_before_middlewares', $callbacks);

        return $this;
    }
610886
public function addProcessor($callback, $processBufferRecord = false)
    {
        if (!is_callable($callback) && !$this->isInstanceOf($callback, ProcessorInterface::class)) {
            throw new \InvalidArgumentException('Processor must be valid callable or an instance of ' . ProcessorInterface::class);
        }

        if ($processBufferRecord) {
            $this->bufferProcessors->prepend($callback);
        } else {
            $this->processors->prepend($callback);
        }


        return $this;
    }
1031139
protected function withErrorHandling($callback)
    {
        try {
            return $callback();
        } catch (OAuthServerException $e) {
            $this->exceptionHandler()->report($e);

            return $this->convertResponse(
                $e->generateHttpResponse(new Psr7Response)
            );
        } catch (Exception $e) {
            $this->exceptionHandler()->report($e);

            return new Response($e->getMessage(), 500);
        } catch (Throwable $e) {
            $this->exceptionHandler()->report(new FatalThrowableError($e));

            return new Response($e->getMessage(), 500);
        }
    }
728590
private function createResource(callable $callback)
    {
        $errors = null;
        set_error_handler(function ($_, $msg, $file, $line) use (&$errors) {
            $errors[] = [
                'message' => $msg,
                'file'    => $file,
                'line'    => $line
            ];
            return true;
        });

        $resource = $callback();
        restore_error_handler();

        if (!$resource) {
            $message = 'Error creating resource: ';
            foreach ($errors as $err) {
                foreach ($err as $key => $value) {
                    $message .= "[$key] $value" . PHP_EOL;
                }
            }
            throw new \RuntimeException(trim($message));
        }

        return $resource;
    }
51783
public function setMessageHandler($callback = null)
    {
        if (!is_callable($callback)) {
            throw new InvalidArgumentException('Argument #2 is not callable.');
        }

        $this->messageHandler = $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;
    }
77640
public function createFromCallback($callback): SpyVerifier
    {
        return new SpyVerifier(
            $this->spyFactory->create($callback),
            $this->matcherFactory,
            $this->matcherVerifier,
            $this->generatorVerifierFactory,
            $this->iterableVerifierFactory,
            $this->callVerifierFactory,
            $this->assertionRecorder,
            $this->assertionRenderer
        );
    }
694109
public function addMiddleware(callable $middleware)
    {
        if (!is_callable($middleware)) {
            throw new \InvalidArgumentException(sprintf(
                'Expected callable, received %s',
                gettype($middleware)
            ));
        }

        $this->middleware[] = $middleware;

        return $this;
    }
1159432
public function writeCallback($callback)
    {
        if (is_callable($callback)) {
            $debugs = debug_backtrace(version_compare(PHP_VERSION, '5.3.6', '>=') ? DEBUG_BACKTRACE_PROVIDE_OBJECT : true);
            // this is current function debug backtrace
            $current = array_shift($debugs);
            // this is the current function caller debug backtrace
            $caller = array_shift($debugs);
            call_user_func($callback, $this, isset($caller['object']) ? $caller['object'] : $this);
        }

        return $this;
    }
258621
public function addAfter($key, callable $callback)
    {
        if ($this->addItem($key, $callback, true)) {
            return $this;
        }

        throw new \Exception(htmlspecialchars("The item $key was not found."));
    }
1007445
public function connect(callable $callback)
    {
        $this->connection->connect(function ($connection) use ($callback) {
            call_user_func($callback, $this, $connection);
        });
    }