public function setHistoryContext(string $type, $dataObject = null, $slug = null): void
    {
        if (!in_array($type, array_keys(ModelHistory::getContextTypes()))) {
            throw new InvalidArgumentException("$type is not allowed as context type. Allowed types are: " . implode(', ', ModelHistory::getContextTypes()));
        }

        switch ($type) {
            case ModelHistory::CONTEXT_TYPE_SHELL:
                if (!$dataObject instanceof Shell) {
                    throw new InvalidArgumentException('You have to specify a Shell data object for this context type.');
                }
                $context = [
                    'OptionParser' => $dataObject->OptionParser,
                    'interactive' => $dataObject->interactive,
                    'params' => $dataObject->params,
                    'command' => $dataObject->command,
                    'args' => $dataObject->args,
                    'name' => $dataObject->name,
                    'plugin' => $dataObject->plugin,
                    'tasks' => $dataObject->tasks,
                    'taskNames' => $dataObject->taskNames
                ];
                $contextSlug = null;
                if ($slug !== null) {
                    $contextSlug = $slug;
                }
                break;
            case ModelHistory::CONTEXT_TYPE_CONTROLLER:
                if (!$dataObject instanceof Request) {
                    throw new InvalidArgumentException('You have to specify a Request data object for this context type.');
                }
                $context = [
                    'params' => $dataObject->params,
                    'method' => $dataObject->method()
                ];
                if ($slug !== null) {
                    $contextSlug = $slug;
                } else {
                    $contextSlug = Text::insert(':plugin/:controller/:action', [
                        'plugin' => $context['params']['plugin'],
                        'controller' => $context['params']['controller'],
                        'action' => $context['params']['action']
                    ]);
                }
                break;
            case ModelHistory::CONTEXT_TYPE_SLUG:
            default:
                $context = [];
                if ($slug === null) {
                    throw new InvalidArgumentException('You have to specify a slug for this context type.');
                }
                $contextSlug = $slug;
                break;
        }

        $this->_context = Hash::merge([
            'type' => $type,
            'namespace' => get_class($this)
        ], $context);
        $this->_contextSlug = $contextSlug;
        $this->_contextType = $type;
    }