public function registerTheme($id, $name, $path = '', $targets = array(), $templates = array() )
    {
        if (preg_match('/^[a-zA-Z0-9]*$/', $id) === 0) {
            throw new \common_Exception('Invalid id "'.$id.'"');
        }
        if (!is_array($targets) || count($targets) === 0){
            throw new \common_Exception('No targets were provided for theme '.$id);
        }

        foreach ($targets as $target) {
            if(!$this->isRegistered($target)){
                throw new \common_Exception('Target '.$target.' does not exist');
            } else {

                $array = $this->get($target);

                foreach ($array['available'] as $theme) {
                    if ($theme['id'] == $id) {
                        throw new \common_Exception('Theme '.$id.' already exists for target '.$target);
                    }
                }

                $theme = array(
                    'id' => $id,
                    'name' => $name
                );

                //the path is optional
                if($path){
                    $theme['path'] = $path;
                }

                //register templates
                if(is_array($templates) && count($templates) > 0){
                    $theme['templates'] = array();
                    foreach($templates as $templateId => $tpl){
                        $theme['templates'][$templateId] = $tpl;
                    }
                }

                $array['available'][] = $theme;
            }
            $this->set($target, $array);
        }
    }