alavieille/composer-assets

View on GitHub
src/ComposerAssets/JsonFile/BowerJsonFile.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Alav\ComposerAssets\JsonFile;

use Composer\Json\JsonFile;

/**
 * Class BowerJsonFile
 */
class BowerJsonFile extends AbstractJsonFile
{
    const BOWER_FILE_NAME = 'bower.json';
    const RC_FILE_NAME = '.bowerrc';

    protected $vendorDir;

    /**
     * @param $vendorDir
     */
    public function __construct($vendorDir)
    {
        $this->vendorDir = $vendorDir;
    }

    /**
     * @param array $jsonContent
     */
    public function createBowerJson(array $jsonContent)
    {
        $jsonFile = $this->initJsonFile(self::BOWER_FILE_NAME);
        $jsonFile->write($jsonContent);
        $this->createBoweRc();
    }

    /**
     * Create .bowerrc file
     */
    protected function createBoweRc()
    {
        $jsonFile = new JsonFile(self::RC_FILE_NAME);
        if (!$jsonFile->exists()) {
            $jsonContent = [];
            $jsonContent['directory'] = $this->vendorDir.'/bower_components';
            $jsonFile->write($jsonContent);
        }
    }
}