App\Console\Commands\SkinMake::registerSkin PHP Method

registerSkin() protected method

registerSkin
protected registerSkin ( ) : integer
return integer
    protected function registerSkin()
    {
        $plugin = $this->attr('plugin');
        $id = $this->attr('skinTarget') . '/skin/' . $this->attr('skinId');
        $class = $this->attr('namespace') . '\\Skin\\' . $this->attr('skinClass');
        $title = $this->attr('skinTitle');
        $description = $this->attr('description');
        $skinFile = $this->attr('skinFile');
        // 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($skinFile, $classmap)) {
            $classmap[] = $skinFile;
        }
        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);
    }