/**
  * {@inheritdoc}
  */
 public function installModule($installPath, $name = null, $installerName = InstallInfo::DEFAULT_INSTALLER_NAME, $env = Environment::PROD)
 {
     Assert::string($installPath, 'The install path must be a string. Got: %s');
     Assert::string($installerName, 'The installer name must be a string. Got: %s');
     Assert::oneOf($env, Environment::all(), 'The environment must be one of: %2$s. Got: %s');
     Assert::nullOrModuleName($name);
     $this->assertModulesLoaded();
     $installPath = Path::makeAbsolute($installPath, $this->rootDir);
     foreach ($this->modules as $module) {
         if ($installPath === $module->getInstallPath()) {
             return;
         }
     }
     if (null === $name && ($moduleFile = $this->loadModuleFile($installPath))) {
         // Read the name from the module file
         $name = $moduleFile->getModuleName();
     }
     if (null === $name) {
         throw new InvalidConfigException(sprintf('Could not find a name for the module at %s. The name should ' . 'either be passed to the installer or be set in the "name" ' . 'property of %s.', $installPath, $installPath . '/puli.json'));
     }
     if ($this->modules->contains($name)) {
         throw NameConflictException::forName($name);
     }
     $relInstallPath = Path::makeRelative($installPath, $this->rootDir);
     $installInfo = new InstallInfo($name, $relInstallPath);
     $installInfo->setInstallerName($installerName);
     $installInfo->setEnvironment($env);
     $module = $this->loadModule($installInfo);
     $this->assertNoLoadErrors($module);
     $this->rootModuleFile->addInstallInfo($installInfo);
     try {
         $this->moduleFileStorage->saveRootModuleFile($this->rootModuleFile);
     } catch (Exception $e) {
         $this->rootModuleFile->removeInstallInfo($name);
         throw $e;
     }
     $this->modules->add($module);
 }
 protected function addJsonToRootModuleFile(stdClass $jsonData, RootModuleFile $moduleFile)
 {
     if (isset($jsonData->order)) {
         $moduleFile->setModuleOrder((array) $jsonData->order);
     }
     if (isset($jsonData->plugins)) {
         $moduleFile->setPluginClasses($jsonData->plugins);
     }
     if (isset($jsonData->config)) {
         $config = $moduleFile->getConfig();
         foreach ($this->objectsToArrays($jsonData->config) as $key => $value) {
             $config->set($key, $value);
         }
     }
     if (isset($jsonData->modules)) {
         foreach ($jsonData->modules as $moduleName => $moduleData) {
             $installInfo = new InstallInfo($moduleName, $moduleData->{'install-path'});
             if (isset($moduleData->env)) {
                 $installInfo->setEnvironment($moduleData->env);
             }
             if (isset($moduleData->installer)) {
                 $installInfo->setInstallerName($moduleData->installer);
             }
             if (isset($moduleData->{'disabled-bindings'})) {
                 foreach ($moduleData->{'disabled-bindings'} as $uuid) {
                     $installInfo->addDisabledBindingUuid(Uuid::fromString($uuid));
                 }
             }
             $moduleFile->addInstallInfo($installInfo);
         }
     }
 }