src/Bot/Mainframe/Mainframe.php
public function getListener(BotInterface $bot, $matcher)
    {
        if (!$matcher instanceof MatcherInterface && !is_callable($matcher)) {
            throw new InvalidArgumentException(sprintf(
                'The matcher must be callable, or an instance of MatcherInterface. "%s" given.',
                is_object($matcher) ? get_class($matcher) : gettype($matcher)
            ));
        }

        return function (Packet $packet) use ($bot, $matcher) {
            if ($matcher instanceof MatcherInterface) {
                $isMatch = $matcher->matches($packet['command']);
            } else {
                $isMatch = call_user_func($matcher, $packet['command']);
            }

            if ($isMatch) {
                $packet->stopPropagation();
                $packet['output'] = $bot->execute($packet['command']);
            }
        };
    }
public function getListener(BotInterface $bot, $matcher)
    {
        if (!$matcher instanceof MatcherInterface && !is_callable($matcher)) {
            throw new InvalidArgumentException(sprintf(
                'The matcher must be callable, or an instance of MatcherInterface. "%s" given.',
                is_object($matcher) ? get_class($matcher) : gettype($matcher)
            ));
        }

        return function (Packet $packet) use ($bot, $matcher) {
            if ($matcher instanceof MatcherInterface) {
                $isMatch = $matcher->matches($packet['command']);
            } else {
                $isMatch = call_user_func($matcher, $packet['command']);
            }

            if ($isMatch) {
                $packet->stopPropagation();
                $packet['output'] = $bot->execute($packet['command']);
            }
        };
    }
@param BotInterface              $bot
@param MatcherInterface|callable $matcher If callable, it should accept a CommandInterface and return a boolean.

@throws \Crummy\Phlack\Common\Exception\InvalidArgumentException When given an invalid matcher.

@return \Closure An anonymous function to be attached to the internal cpu.