private function validate($key, $data)
    {
        // validates key
        if (in_array($key, $this->unauthorizedKeys)) {
            throw new \RuntimeException(
                'Injected key `'.$key.'` is not authorized. (Unauthorized keys: '.implode(', ', $this->unauthorizedKeys).')'
            );
        }

        if (in_array($key, array_keys($this->injectedData))) {
            throw new \RuntimeException(
                'Injected key `'.$key.'` is already used.'
            );
        }

        // validates data (must be serializable)
        if (false !== $data && false === json_encode($data)) {
            throw new \RuntimeException(
                'Injected data is not serializable.'
            );
        }
    }