/** * {@inheritdoc} */ public function installPackage($installPath, $name = null, $installerName = InstallInfo::DEFAULT_INSTALLER_NAME) { 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::nullOrPackageName($name); $this->assertPackagesLoaded(); $installPath = Path::makeAbsolute($installPath, $this->rootDir); foreach ($this->packages as $package) { if ($installPath === $package->getInstallPath()) { return; } } if (null === $name) { // Read the name from the package file $name = $this->loadPackageFile($installPath)->getPackageName(); } if (null === $name) { throw new InvalidConfigException(sprintf('Could not find a name for the package 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->packages->contains($name)) { throw NameConflictException::forName($name); } $relInstallPath = Path::makeRelative($installPath, $this->rootDir); $installInfo = new InstallInfo($name, $relInstallPath); $installInfo->setInstallerName($installerName); $package = $this->loadPackage($installInfo); $this->assertNoLoadErrors($package); $this->rootPackageFile->addInstallInfo($installInfo); try { $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile); } catch (Exception $e) { $this->rootPackageFile->removeInstallInfo($name); throw $e; } $this->packages->add($package); }
/** * Sets the package name. * * @param string|null $packageName The package name or `null` to unset. * * @throws InvalidArgumentException If the name is not a string or empty. */ public function setPackageName($packageName) { Assert::nullOrPackageName($packageName); $this->packageName = $packageName; }