public function addPlugin(Plugin $plugin, $key = null) {
        if ($key) {
            $this->plugins[$key] = $plugin;
        } else {
            $this->plugins[] = $plugin;
        }
        $plugin->configure($this);
        return $this;
    }