public function testCanPromptCharWithoutIgnoreCase() { fwrite($this->adapter->stream, 'FOObar'); $char = new Char(); $char->setEcho(false); $char->setConsole($this->adapter); $char->setIgnoreCase(false); ob_start(); $response = $char->show(); ob_get_clean(); $this->assertEquals('b', $response); }
/** * Show a list of options and prompt the user to select one of them. * * @return string Selected option */ public function show() { // Show prompt text and available options $console = $this->getConsole(); $console->writeLine($this->promptText); foreach ($this->options as $k => $v) { $console->writeLine(' ' . $k . ') ' . $v); } // Prepare mask $mask = implode("", array_keys($this->options)); if ($this->allowEmpty) { $mask .= "\r\n"; } // Prepare other params for parent class $this->setAllowedChars($mask); $oldPrompt = $this->promptText; $oldEcho = $this->echo; $this->echo = false; $this->promptText = null; // Retrieve a single character $response = parent::show(); // Restore old params $this->promptText = $oldPrompt; $this->echo = $oldEcho; // Display selected option if echo is enabled if ($this->echo) { if (isset($this->options[$response])) { $console->writeLine($this->options[$response]); } else { $console->writeLine(); } } $this->lastResponse = $response; return $response; }
/** * @return array */ public function show() { $inputs = array(); $more = 'n'; $valid = ''; do { $tmpMsg = $this->message; do { // for input $input = Line::prompt($tmpMsg, $this->isOptional, 1500); $tmpMsg = $this->invalidMessage; $isValid = true; if (is_callable($this->validateCallback)) { $isValid = call_user_func($this->validateCallback, $input); if ($isValid) { // is valid and callable given $inputs[] = $input; } } else { // callable not given, store the input as is. $inputs[] = $input; } } while (!$isValid && !empty($input) && $this->isOptional); // valid property given now continue if (!empty($input)) { // ask fore more $more = Char::prompt($this->moreMessage, 'yn', true, false, false); } } while ($more == 'y' && !empty($input)); return $this->lastResponse = $inputs; }
/** * @return array */ public function show() { $inputs = array(); $more = 'n'; $msgsGiven = count($this->messages) > 0; $isRequired = false; if (method_exists($this->prompt, 'getAllowEmpty')) { $isRequired = !$this->prompt->getAllowEmpty(); } do { if (!$this->skipFirst) { if ($msgsGiven) { $msg = array_shift($this->messages); } elseif (method_exists($this->prompt, 'getPromptText') && method_exists($this->prompt, 'setPromptText')) { $msg = $this->prompt->getPromptText(); $this->prompt->setPromptText($msg); } do { $input = $this->prompt->show(); $inputs[] = $input; } while ($isRequired && empty($input)); } $this->skipFirst = false; if (!$msgsGiven) { $more = Char::prompt($this->moreMessage, 'yn', true, false, false); } } while ($more == 'y' || $msgsGiven && !empty($this->messages)); return $this->lastResponse = $inputs; }
/** * Show a list of options and prompt the user to select one of them. * * @return string Selected option */ public function show() { /** * Show prompt text and available options */ $console = $this->getConsole(); $console->writeLine($this->promptText); foreach ($this->options as $k => $v) { $console->writeLine(' ' . $k . ') ' . $v); } /** * Ask for selection */ $mask = implode("", array_keys($this->options)); if ($this->allowEmpty) { $mask .= "\r\n"; } $this->setAllowedChars($mask); $oldPrompt = $this->promptText; $this->promptText = 'Pick one option: '; $response = parent::show(); $this->promptText = $oldPrompt; return $response; }
/** * Show the confirmation message and return result. * * @return bool */ public function show() { $response = parent::show() === $this->yesChar; return $this->lastResponse = $response; }
public function consoleEntityAction() { $request = $this->getRequest(); // Make sure that we are running in a console and the user has not tricked our // application into running this action from a public web server. if (!$request instanceof ConsoleRequest) { throw new \RuntimeException('You can only use this action from a console!'); } $all = $request->getParam('all'); $entity = $request->getParam('entityName'); $namespace = $request->getParam('namespace'); $filepath = $request->getParam('dir'); $entitymanager = $request->getParam('entityManager'); // If we have no Parameters given, well ask the user if (!isset($entity) and $all === false) { $char = Char::prompt('Do you want do create one Model (o) or All Models (a)?', 'ao', true, false, true); if ($char == 'o') { $entity = Line::prompt('Please Enter the Name of the Entity to be created: ', false, 100); } else { $all = true; } } if ($namespace == false) { $namespace = Line::prompt('Please Enter the Name of Namespace to be used: ', false, 100); } if ($filepath == false) { $filepath = Line::prompt('Please Enter a File-Path for the Entity-Files: (std: "Entities") ', true, 100); // If no filepath given, we set an default filepath if (empty($filepath)) { $filepath = 'Entities'; } } if (!is_dir($filepath)) { if (Confirm::prompt('Directory ' . $filepath . ' does not exist. Create? [y/n]', 'y', 'n')) { if (!mkdir($filepath, 0777, true)) { return 'EXIT: Directory could not be created.'; } } else { return 'EXIT: Invalid Directory.'; } } if ($entitymanager == false) { $entitymanager = Line::prompt('Please Enter a entity-manager (default:doctrine.entitymanager.orm_default): ', true, 100); // If no entitymanager given, we set an default if ($entitymanager == false) { $entitymanager = 'doctrine.entitymanager.orm_default'; } } // Check on a valid entitymanager try { $em = $this->getServiceLocator()->get($entitymanager); if (!is_a($em, 'Doctrine\\ORM\\EntityManager')) { throw new ServiceNotFoundException(); } } catch (ServiceNotFoundException $e) { return 'Exit: Invalid Entitymanager'; } // All Validated, we generate now. $this->setEntitymanager($entitymanager); $this->setFilepath($filepath); $this->setNamespace($namespace); if ($all === true) { $tables = array(); } else { $tables = array($entity); } $this->setTables($tables); $this->generate(); return 'Files successfully created' . "\n"; }