public function setPlugins($plugins)
    {
        $this->plugins = array();
        foreach ($plugins as $key => $plugin) {
            $pluginClass = $plugin;
            if (is_array($plugin)) {
                if (!isset($plugin[Config::KEY_CLASS])) {
                    throw new PluginException('Invalid or missing class for plugin '.$key);
                } elseif (!class_exists($plugin[Config::KEY_CLASS])) {
                    throw new PluginException('Invalid or missing class for plugin '.$key);
                }
                $pluginClass = $plugin[Config::KEY_CLASS];
            }
            $options = array();
            if (isset($plugin[Config::KEY_OPTIONS])) {
                $options = (array)$plugin[Config::KEY_OPTIONS];
            }
            $this->plugins[] = new $pluginClass($options);
        }
        $this->plugins = $this->sortPlugins($this->plugins);
        return $this;
    }