Jarves\Controller\Admin\BundleManager\ManagerController::installComposerAction PHP Method

installComposerAction() public method

public installComposerAction ( FOS\RestBundle\Request\ParamFetcher $paramFetcher ) : string
$paramFetcher FOS\RestBundle\Request\ParamFetcher
return string
    public function installComposerAction(ParamFetcher $paramFetcher)
    {
        $name = $paramFetcher->get('name');
        $version = $paramFetcher->get('version');
        $withBundles = filter_var($paramFetcher->get('withBundles'), FILTER_VALIDATE_BOOLEAN);
        if (!is_writeable($vendorDir = $this->getComposerVendorDir())) {
            throw new FileNotWritableException(sprintf('Directory `%s` is not writable.', $vendorDir));
        }
        $composer = $this->getComposer();
        //check if bundle exist
        $this->versionParser = new VersionParser();
        $platformRepo = new PlatformRepository();
        $localRepo = $composer->getRepositoryManager()->getLocalRepository();
        $installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
        $repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
        list($package, ) = $this->getPackage($installedRepo, $repos, $name, $version);
        if (!$package) {
            throw new PackageNotFoundException(sprintf('Can not find package `%s` with version `%s`.', $name, $version));
        }
        $fs = $this->localFilesystem;
        if ($fs->has('composer.json') && is_string($name)) {
            $composerJson = $fs->read('composer.json');
            if ($composerJson) {
                $composerJson = json_decode($composerJson, true);
                if (is_array($composerJson)) {
                    $found = false;
                    foreach ($composerJson['require'] as $key => $value) {
                        if (strtolower($key) == strtolower($name)) {
                            unset($composerJson['require'][$key]);
                            $found = $key;
                        }
                    }
                    if (!$found) {
                        $composerJson['require'][$name] = $version;
                        $fs->write('composer.json', json_encode($composerJson, JSON_PRETTY_PRINT));
                    } else {
                        $name = $found;
                    }
                }
            }
        }
        $install = Installer::create($this->composerIO, $composer);
        $install->setVerbose(true)->setPreferDist(true)->setDevMode(true)->setUpdate(true)->setUpdateWhitelist([$name]);
        if (filter_var($withBundles, FILTER_VALIDATE_BOOLEAN)) {
            $this->searchAndInstallBundles($this->getComposerVendorDir() . $name);
        }
        $this->updateAutoloader();
        return $this->composerIO->getOutput();
    }