protected function cast($element) {
        if ($element instanceof Permission) {
            return $element;
        }

        if (!is_array($element)) {
            throw new InvalidArgumentException('Element is not an array.');
        }

        foreach (['attributes', 'type', 'value', 'title'] as $key) {
            if (!array_key_exists($key, $element)) {
                throw new InvalidArgumentException('Element is missing key "'.$key.'".');
            }
        }

        $permission = new Permission($element['key'], $element['attributes'], $element['type'], $element['value'], $element['title']);

        return $permission;
    }