/** * Perform the resolution & set property. */ public function main() { if (!$this->name) { throw new BuildException("You must specify the name of the executable you want to select.", $this->getLocation()); } if (!$this->propertyName) { throw new BuildException("You must specify the property name to store the path in.", $this->getLocation()); } $execPath = NULL; $cmd = "which {$this->name}"; $outArray = array(); $retCode = -1; $whichResult = exec($cmd, $outArray, $retCode); if ($retCode == 0) { $execPath = $whichResult; } // verify path $request = new InputRequest("Select the path for executable: {$this->name}: "); $request->setDefaultValue($execPath); do { $this->project->getInputHandler()->handleInput($request); $execPath = $request->getInput(); } while (!file_exists($execPath)); $this->project->setProperty($this->propertyName, $execPath); $this->log("Using {$this->name} at {$execPath}", PROJECT_MSG_INFO); }
/** * Get some input from the user * * @param string $prompt * @return string */ protected function getInput($prompt) { require_once 'phing/input/InputRequest.php'; $request = new InputRequest($prompt); $request->setPromptChar(':'); $this->project->getInputHandler()->handleInput($request); $value = $request->getInput(); return $value; }
/** * Constructs user prompt from a request. * * <p>This implementation adds (choice1,choice2,choice3,...) to the * prompt for <code>MultipleChoiceInputRequest</code>s.</p> * * @param $request the request to construct the prompt for. * Must not be <code>null</code>. */ protected function getPrompt(InputRequest $request) { $prompt = $request->getPrompt(); // use is_a() to avoid needing the class to be loaded if (is_a($request, 'YesNoInputRequest')) { // (yes/no) $prompt .= '(' . implode('/', $request->getChoices()) . ')'; } elseif (is_a($request, 'MultipleChoiceInputRequest')) { // (a,b,c,d) $prompt .= '(' . implode(',', $request->getChoices()) . ')'; } if ($request->getDefaultValue() !== null) { $prompt .= ' [' . $request->getDefaultValue() . ']'; } $pchar = $request->getPromptChar(); return $prompt . ($pchar ? $pchar . ' ' : ' '); }
/** * Constructs user prompt from a request. * * <p>This implementation adds (choice1,choice2,choice3,...) to the * prompt for <code>MultipleChoiceInputRequest</code>s.</p> * * @param InputRequest $request the request to construct the prompt for. * Must not be <code>null</code>. * * @return string */ protected function getPrompt(InputRequest $request) { $prompt = $request->getPrompt(); $defaultValue = $request->getDefaultValue(); if ($request instanceof YesNoInputRequest) { $choices = $request->getChoices(); $defaultValue = $choices[(int) (!$request->getDefaultValue())]; $prompt .= '(' . implode('/', $request->getChoices()) . ')'; } elseif ($request instanceof MultipleChoiceInputRequest) { // (a,b,c,d) $prompt .= '(' . implode(',', $request->getChoices()) . ')'; } if ($request->getDefaultValue() !== null) { $prompt .= ' [' . $defaultValue . ']'; } $pchar = $request->getPromptChar(); return $prompt . ($pchar ? $pchar . ' ' : ' '); }
public function main() { if ($this->propertyName === null) { throw new BuildException("You must specify a value for propertyName attribute."); } if ($this->list === null) { throw new BuildException("You must specify a value for list attribute."); } if (!$this->list) { $this->log('empty list.', Project::MSG_ERR); return false; } //输出带序号的列表 $this->log($this->gen($this->list)); $promptText = '请输入数字序号'; do { $request = new InputRequest($promptText); if ($this->defaultLast) { $request->setDefaultValue(count($this->choice)); } $request->setPromptChar(':'); $this->project->getInputHandler()->handleInput($request); $proposedValue = $request->getInput(); $keys = explode(',', $proposedValue); foreach ($keys as $key) { $key = intval($key); if (isset($this->choice[$key - 1])) { $this->accept[] = $this->choice[$key - 1]; } } } while (!$this->accept); if ($this->max) { $this->accept = array_slice($this->accept, 0, $this->max); } $this->project->setUserProperty($this->propertyName, implode(',', $this->accept)); }
/** * Actual method executed by phing. * @throws BuildException */ public function main() { if ($this->propertyName === null) { throw new BuildException("You must specify a value for propertyName attribute."); } if ($this->validargs !== null) { $accept = preg_split('/[\\s,]+/', $this->validargs); // is it a boolean (yes/no) inputrequest? $yesno = false; if (count($accept) == 2) { $yesno = true; foreach ($accept as $ans) { if (!StringHelper::isBoolean($ans)) { $yesno = false; break; } } } if ($yesno) { $request = new YesNoInputRequest($this->message, $accept); } else { $request = new MultipleChoiceInputRequest($this->message, $accept); } } else { $request = new InputRequest($this->message); } // default default is curr prop value $request->setDefaultValue($this->project->getProperty($this->propertyName)); $request->setPromptChar($this->promptChar); // unless overridden... if ($this->defaultValue !== null) { $request->setDefaultValue($this->defaultValue); } $this->project->getInputHandler()->handleInput($request); $value = $request->getInput(); if ($value !== null) { $this->project->setUserProperty($this->propertyName, $value); } }
/** * @param string $prompt The prompt to show to the user. Must not be null. * @param array $choices holds all input values that are allowed. * Must not be null. */ public function __construct($prompt, $choices) { parent::__construct($prompt); $this->choices = $choices; }
/** * Executes this task. */ public function main() { if ($this->property === null) { throw new BuildException('The property attribute must be specified'); } if ($this->message === '') { throw new BuildException('The message attribute must be specified or the element must contain a message'); } if ($this->ignoreIfSet && $this->project->getProperty($this->property) !== null) { if ($this->failIfEmpty) { if ($this->project->getProperty($this->property) != '') { return; } } else { return; } } $request = new InputRequest($this->message); $request->setPromptChar($this->promptCharacter); if ($this->useExistingAsDefault === true) { $request->setDefaultValue($this->project->getProperty($this->property)); } if ($this->default !== null) { $request->setDefaultValue($this->default); } $this->project->getInputHandler()->handleInput($request); $result = $request->getInput(); if ($this->failIfEmpty && $result == '') { throw new BuildException('Input value cannot be empty'); } $this->project->setUserProperty($this->property, $result); }