/** * @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; }
/** * @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; }
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"; }