App\Console\Commands\ThemeMake::registerTheme PHP Method

registerTheme() protected method

registerTheme
protected registerTheme ( ) : integer
return integer
    protected function registerTheme()
    {
        $plugin = $this->attr('plugin');
        $id = 'theme/' . $this->attr('themeId');
        $class = $this->attr('namespace') . '\\Theme\\' . $this->attr('themeClass');
        $title = $this->attr('themeTitle');
        $description = $this->attr('description');
        $themeFile = $this->attr('themeFile');
        // add component
        $composerStr = $this->files->get($plugin->getPath('composer.json'));
        $this->originComposerStr = $composerStr;
        $json = json_decode($composerStr);
        $component = data_get($json, 'extra.xpressengine.component');
        if (isset($component->{$id})) {
            throw new \Exception(sprintf('component[%s] already exists.', $id));
        }
        $component->{$id} = new \stdClass();
        $component->{$id}->class = $class;
        $component->{$id}->name = $title;
        $component->{$id}->description = $description;
        $json->extra->xpressengine->component = $component;
        // add autoload
        $classmap = data_get($json, 'autoload.classmap', []);
        if (!in_array($themeFile, $classmap)) {
            $classmap[] = $themeFile;
        }
        if (!isset($json->autoload)) {
            $json->autoload = new \stdClass();
        }
        $json->autoload->classmap = $classmap;
        $json = json_format(json_encode($json));
        return $this->files->put($plugin->getPath('composer.json'), $json);
    }