/** * Creates the context. * * @param string|null $homeDir The path to the * home directory or * `null` if none * exists. * @param string $rootDir The path to the * project's root * directory. * @param Config $config The configuration. * @param RootModuleFile $rootModuleFile The root module * file. * @param ConfigFile|null $configFile The configuration * file or `null` if * none exists. * @param EventDispatcherInterface|null $dispatcher The event * dispatcher. * @param string $env The environment * that Puli is * running in. */ public function __construct($homeDir, $rootDir, Config $config, RootModuleFile $rootModuleFile, ConfigFile $configFile = null, EventDispatcherInterface $dispatcher = null, $env = Environment::DEV) { Assert::directory($rootDir, 'The root directory %s is not a directory.'); Assert::oneOf($env, Environment::all(), 'The environment must be one of: %2$s. Got: %s'); parent::__construct($homeDir, $config, $configFile, $dispatcher); $this->rootDir = Path::canonicalize($rootDir); $this->rootModuleFile = $rootModuleFile; $this->env = $env; }
/** * {@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); }
/** * Sets the environment that the package is installed in. * * @param string $env One of the {@link Environment} constants. */ public function setEnvironment($env) { Assert::oneOf($env, Environment::all(), 'The environment must be one of: %2$s. Got: %s'); $this->env = $env; }
/** * Sets the environment of the managed Puli project. * * @param string $env One of the {@link Environment} constants. */ public function setEnvironment($env) { if ($this->started) { throw new LogicException('Puli is already started'); } Assert::oneOf($env, Environment::all(), 'The environment must be one of: %2$s. Got: %s'); $this->env = $env; }