protected function getHandlersForContext($context = null)
    {
        $handlers = $this->config()->get('token_handlers');
        if (empty($handlers)) {
            throw new Exception('No token handlers were registered');
        }

        // If we've been given a context, limit to that context + global handlers.
        // Otherwise only allow global handlers (i.e. exclude named ones)
        $allowedContexts = ['*'];
        if ($context) {
            $allowedContexts[] = $context;
        }

        // Filter handlers by context
        $handlers = array_filter($handlers, function ($handler) use ($allowedContexts) {
            return in_array($handler['context'], $allowedContexts);
        });

        // Sort handlers by priority
        uasort($handlers, function ($a, $b) {
            if (!array_key_exists('priority', $a) || !array_key_exists('priority', $b)) {
                return 0;
            }

            return ($a['priority'] < $b['priority']) ? -1 : 1;
        });

        return $handlers;
    }