Returns whether an option is set.
public isOptionSet ( string $name ) : boolean | ||
$name | string | The long or short option name. |
return | boolean | Returns `true` if the option is set and `false` otherwise. |
public function handleUpdate(Args $args) { $targetName = $args->getArgument('name'); if (!$this->targetManager->hasTarget($targetName)) { throw NoSuchTargetException::forTargetName($targetName); } $targetToUpdate = $this->targetManager->getTarget($targetName); $installerName = $targetToUpdate->getInstallerName(); $location = $targetToUpdate->getLocation(); $urlFormat = $targetToUpdate->getUrlFormat(); $parameters = $targetToUpdate->getParameterValues(); if ($args->isOptionSet('installer')) { $installerName = $args->getOption('installer'); } if ($args->isOptionSet('location')) { $location = $args->getOption('location'); } if ($args->isOptionSet('url-format')) { $urlFormat = $args->getOption('url-format'); } $this->parseParams($args, $parameters); $this->unsetParams($args, $parameters); $updatedTarget = new InstallTarget($targetName, $installerName, $location, $urlFormat, $parameters); if ($this->targetsEqual($targetToUpdate, $updatedTarget)) { throw new RuntimeException('Nothing to update.'); } $this->targetManager->addTarget($updatedTarget); return 0; }
/** * Handles the "find" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { $criteria = array(); if ($args->isOptionSet('path')) { $criteria['path'] = $args->getOption('path'); $criteria['language'] = $args->getOption('language'); } if ($args->isOptionSet('name')) { if (isset($criteria['path'])) { throw new RuntimeException('The options --name and --path cannot be combined.'); } $criteria['path'] = '/**/' . $args->getOption('name'); $criteria['language'] = $args->getOption('language'); } if ($args->isOptionSet('class')) { $criteria['class'] = $args->getOption('class'); } if ($args->isOptionSet('type')) { $criteria['bindingType'] = $args->getOption('type'); } if (!$criteria) { throw new RuntimeException('No search criteria specified.'); } return $this->listMatches($io, $criteria); }
public function handleUpdate(Args $args) { $serverName = $args->getArgument('name'); if (!$this->serverManager->hasServer($serverName)) { throw NoSuchServerException::forServerName($serverName); } $serverToUpdate = $this->serverManager->getServer($serverName); $installerName = $serverToUpdate->getInstallerName(); $documentRoot = $serverToUpdate->getDocumentRoot(); $urlFormat = $serverToUpdate->getUrlFormat(); $parameters = $serverToUpdate->getParameterValues(); if ($args->isOptionSet('installer')) { $installerName = $args->getOption('installer'); } if ($args->isOptionSet('document-root')) { $documentRoot = $args->getOption('document-root'); } if ($args->isOptionSet('url-format')) { $urlFormat = $args->getOption('url-format'); } $this->parseParams($args, $parameters); $this->unsetParams($args, $parameters); $updatedServer = new Server($serverName, $installerName, $documentRoot, $urlFormat, $parameters); if ($this->serversEqual($serverToUpdate, $updatedServer)) { throw new RuntimeException('Nothing to update.'); } $this->serverManager->addServer($updatedServer); return 0; }
private function getStability(Args $args) { if ($args->isOptionSet('stable')) { return PuliStrategy::STABLE; } if ($args->isOptionSet('unstable')) { return PuliStrategy::UNSTABLE; } return preg_match('/\\-(dev|alpha|beta)/', PuliApplicationConfig::VERSION) ? PuliStrategy::UNSTABLE : PuliStrategy::STABLE; }
private function getStability(Args $args) { if ($args->isOptionSet('stable')) { return GithubStrategy::STABLE; } if ($args->isOptionSet('unstable')) { return GithubStrategy::UNSTABLE; } foreach (array('-dev', '-alpha', '-beta') as $stability) { if (false !== strpos(PuliApplicationConfig::VERSION, $stability)) { return GithubStrategy::UNSTABLE; } } return GithubStrategy::STABLE; }
public function handleList(Args $args, IO $io) { $table = new Table(PuliTableStyle::borderless()); $table->setHeaderRow(array('Name', 'Class', 'Description')); foreach ($this->installerManager->getInstallerDescriptors() as $descriptor) { $className = $descriptor->getClassName(); if (!$args->isOptionSet('long')) { $className = StringUtil::getShortClassName($className); } $parameters = array(); foreach ($descriptor->getParameters() as $parameterName => $parameter) { if (!$parameter->isRequired()) { $parameterName .= '=' . StringUtil::formatValue($parameter->getDefaultValue()); } $parameters[] = $parameterName; } $description = $descriptor->getDescription(); if (!empty($parameters)) { // non-breaking space $description .= ' <c1>(' . implode(", ", $parameters) . ')</c1>'; } $table->addRow(array('<u>' . $descriptor->getName() . '</u>', '<c1>' . $className . '</c1>', $description)); } $table->render($io); return 0; }
/** * Handles the "config <key>" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handleShow(Args $args, IO $io) { $raw = !$args->isOptionSet('parsed'); $value = $this->manager->getConfigKey($args->getArgument('key'), null, true, $raw); $io->writeLine(StringUtil::formatValue($value, false)); return 0; }
/** * Returns the non-root packages selected in the console arguments. * * @param Args $args The console arguments. * @param PackageCollection $packages The available packages. * * @return string[] The package names. */ public static function getPackageNamesWithoutRoot(Args $args, PackageCollection $packages) { // Display all packages if "all" is set if ($args->isOptionSet('all')) { return $packages->getInstalledPackageNames(); } $packageNames = array(); foreach ($args->getOption('package') as $packageName) { $packageNames[] = $packageName; } return $packageNames ?: $packages->getInstalledPackageNames(); }
/** * Returns the non-root modules selected in the console arguments. * * @param Args $args The console arguments * @param ModuleList $modules The available modules * * @return string[] The module names */ public static function getModuleNamesWithoutRoot(Args $args, ModuleList $modules) { // Display all modules if "all" is set if ($args->isOptionSet('all')) { return $modules->getInstalledModuleNames(); } $moduleNames = array(); foreach ($args->getOption('module') as $moduleName) { $moduleNames[] = $moduleName; } return $moduleNames ?: $modules->getInstalledModuleNames(); }
/** * Handles the "ls" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { $path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath); $resource = $this->repo->get($path); if (!$resource->hasChildren()) { throw new RuntimeException(sprintf('The resource "%s" does not have children.', $resource->getPath())); } if ($args->isOptionSet('long')) { $this->listLong($io, $resource->listChildren()); } else { $this->listShort($io, $resource->listChildren()); } return 0; }
/** * Returns the package states that should be displayed for the given * console arguments. * * @param Args $args The console arguments. * * @return int[] A list of {@link PackageState} constants. */ private function getSelectedStates(Args $args) { $states = array(); if ($args->isOptionSet('enabled')) { $states[] = PackageState::ENABLED; } if ($args->isOptionSet('not-found')) { $states[] = PackageState::NOT_FOUND; } if ($args->isOptionSet('not-loadable')) { $states[] = PackageState::NOT_LOADABLE; } return $states ?: PackageState::all(); }
public function handleUpdate(Args $args) { $flags = $args->isOptionSet('force') ? AssetManager::OVERRIDE | AssetManager::IGNORE_SERVER_NOT_FOUND : AssetManager::OVERRIDE; $mappingToUpdate = $this->getMappingByUuidPrefix($args->getArgument('uuid')); $path = $mappingToUpdate->getGlob(); $serverPath = $mappingToUpdate->getServerPath(); $serverName = $mappingToUpdate->getServerName(); if ($args->isOptionSet('path')) { $path = Path::makeAbsolute($args->getOption('path'), $this->currentPath); } if ($args->isOptionSet('server-path')) { $serverPath = $args->getOption('server-path'); } if ($args->isOptionSet('server')) { $serverName = $args->getOption('server'); } $updatedMapping = new AssetMapping($path, $serverName, $serverPath, $mappingToUpdate->getUuid()); if ($this->mappingsEqual($mappingToUpdate, $updatedMapping)) { throw new RuntimeException('Nothing to update.'); } $this->assetManager->addRootAssetMapping($updatedMapping, $flags); return 0; }
public function testIsOptionDefined() { $format = ArgsFormat::build()->addOption(new Option('option1', null, Option::NO_VALUE))->addOption(new Option('option2', null, Option::OPTIONAL_VALUE))->getFormat(); $args = new Args($format); $this->assertTrue($args->isOptionDefined('option1')); $this->assertTrue($args->isOptionDefined('option2')); $this->assertFalse($args->isOptionSet('foo')); }
/** * Returns the path mapping states selected in the console arguments. * * @param Args $args The console arguments. * * @return int[] The selected {@link PathMappingState} constants. */ private function getPathMappingStates(Args $args) { $states = array(PathMappingState::ENABLED => 'enabled', PathMappingState::NOT_FOUND => 'not-found', PathMappingState::CONFLICT => 'conflict'); $states = array_filter($states, function ($option) use($args) { return $args->isOptionSet($option); }); return array_keys($states) ?: PathMappingState::all(); }
/** * Returns the binding states selected in the console arguments. * * @param Args $args The console arguments. * * @return int[] The selected {@link BindingState} constants. */ private function getBindingStates(Args $args) { $states = array(); if ($args->isOptionSet('enabled')) { $states[] = BindingState::ENABLED; } if ($args->isOptionSet('disabled')) { $states[] = BindingState::DISABLED; } if ($args->isOptionSet('undecided')) { $states[] = BindingState::UNDECIDED; } if ($args->isOptionSet('type-not-found')) { $states[] = BindingState::TYPE_NOT_FOUND; } if ($args->isOptionSet('type-not-enabled')) { $states[] = BindingState::TYPE_NOT_ENABLED; } if ($args->isOptionSet('invalid')) { $states[] = BindingState::INVALID; } return $states ?: BindingState::all(); }
/** * @param Args $args * @param ClassBinding $bindingToUpdate * * @return ClassBinding */ private function getUpdatedClassBinding(Args $args, ClassBinding $bindingToUpdate) { $className = $bindingToUpdate->getClassName(); $typeName = $bindingToUpdate->getTypeName(); $bindingParams = $bindingToUpdate->getParameterValues(); if ($args->isOptionSet('class')) { $className = $args->getOption('class'); } if ($args->isOptionSet('type')) { $typeName = $args->getOption('type'); } $this->parseParams($args, $bindingParams); $this->unsetParams($args, $bindingParams); return new ClassBinding($className, $typeName, $bindingParams, $bindingToUpdate->getUuid()); }
/** * Returns the binding type states selected in the console arguments. * * @param Args $args The console arguments. * * @return int[] A list of {@link BindingTypeState} constants. */ private function getBindingTypeStates(Args $args) { $states = array(); if ($args->isOptionSet('enabled')) { $states[] = BindingTypeState::ENABLED; } if ($args->isOptionSet('duplicate')) { $states[] = BindingTypeState::DUPLICATE; } return $states ?: BindingTypeState::all(); }
/** * Returns the path mapping states selected in the console arguments. * * @param Args $args The console arguments. * * @return int[] The selected {@link PathMappingState} constants. */ private function getPathMappingStates(Args $args) { $states = array(); if ($args->isOptionSet('enabled')) { $states[] = PathMappingState::ENABLED; } if ($args->isOptionSet('not-found')) { $states[] = PathMappingState::NOT_FOUND; } if ($args->isOptionSet('conflict')) { $states[] = PathMappingState::CONFLICT; } return $states ?: PathMappingState::all(); }