/** * Validated option dependencies. * * Validates dependencies by $option. * * @param ezcConsoleOption $option. */ private function validateDependencies(ezcConsoleOption $option) { $optSet = $option->value !== false && (!is_array($option->value) || $option->value !== array()); foreach ($option->getDependencies() as $dep) { if ($dep->ifSet === $optSet) { $this->validateDependency($option, $dep); } } }
public function testConstructionSuccess() { $optionDependency = new ezcConsoleOption("d", "depend"); $optionExclusion = new ezcConsoleOption("e", "exclude"); $ruleDependency = new ezcConsoleOptionRule($optionDependency, array("abc")); $ruleExclusion = new ezcConsoleOptionRule($optionExclusion, array("abc")); $option = new ezcConsoleOption("a", "aaa", ezcConsoleInput::TYPE_INT, 23, true, "Shorthelp", "Longhelp", array($ruleDependency), array($ruleExclusion), false, true, true); $this->assertEquals($option->short, "a"); $this->assertEquals($option->long, "aaa"); $this->assertEquals(ezcConsoleInput::TYPE_INT, $option->type); $this->assertEquals(23, $option->default); $this->assertTrue($option->multiple); $this->assertEquals("Shorthelp", $option->shorthelp); $this->assertEquals("Longhelp", $option->longhelp); $this->assertEquals(array($ruleDependency), $option->getDependencies()); $this->assertEquals(array($ruleExclusion), $option->getExclusions()); $this->assertFalse($option->arguments); $this->assertTrue($option->mandatory); $this->assertTrue($option->isHelpOption); }
/** * Returns the synopsis string for a single option and its dependencies. * * This method returns a part of the program synopsis, specifically for a * certain parameter. The method recursively adds depending parameters up * to the 2nd depth level to the synopsis. The second parameter is used * to store the short names of all options that have already been used in * the synopsis (to avoid adding an option twice). The 3rd parameter * determines the actual deps in the option dependency recursion to * terminate that after 2 recursions. * * @param ezcConsoleOption $option The option to include. * @param array(string) $usedOptions Array of used option short names. * @param int $depth Current recursion depth. * @return string The synopsis for this parameter. * * @apichange This method is deprecates. Implement your own {@link * ezcConsoleInputHelpGenerator} instead, as soon as the * interface is made public. */ protected function createOptionSynopsis(ezcConsoleOption $option, &$usedOptions, $depth = 0) { $synopsis = ''; // Break after a nesting level of 2 if ($depth++ > 2 || in_array($option->short, $usedOptions['short']) && in_array($option->long, $usedOptions['long'])) { return $synopsis; } $usedOptions['short'][] = $option->short; $usedOptions['long'][] = $option->long; $synopsis .= $option->short !== "" ? "-{$option->short}" : "--{$option->long}"; if (isset($option->default)) { $synopsis .= " " . ($option->type === ezcConsoleInput::TYPE_STRING ? '"' : '') . $option->default . ($option->type === ezcConsoleInput::TYPE_STRING ? '"' : ''); } else { if ($option->type !== ezcConsoleInput::TYPE_NONE) { $synopsis .= " "; switch ($option->type) { case ezcConsoleInput::TYPE_STRING: $synopsis .= "<string>"; break; case ezcConsoleInput::TYPE_INT: $synopsis .= "<int>"; break; } } } foreach ($option->getDependencies() as $rule) { $deeperSynopsis = $this->createOptionSynopsis($rule->option, $usedOptions, $depth); $synopsis .= iconv_strlen(trim($deeperSynopsis), 'UTF-8') > 0 ? ' ' . $deeperSynopsis : ''; } if ($option->arguments === false) { $allowsArgs = false; } // Make the whole thing optional? if ($option->mandatory === false) { $synopsis = "[{$synopsis}]"; } return $synopsis . ' '; }