/** * Asks for the prefix and sets it on the InputInterface as the 'prefix' option, if this option is not set yet. * Will set the default to a snake_cased namespace when the namespace has been set on the InputInterface. * * @param array $text What you want printed before the prefix is asked. If null is provided it'll write a default text. * @param string $namespace An optional namespace. If this is set it'll create the default based on this prefix. * If it's not provided it'll check if the InputInterface already has the namespace option. * * @return string The prefix. But it's also been set on the InputInterface. */ protected function askForPrefix(array $text = null, $namespace = null) { $prefix = $this->assistant->getOptionOrDefault('prefix', null); if (is_null($text)) { $text = array('You can add a prefix to the table names of the generated entities for example: ' . '<comment>projectname_bundlename_</comment>', 'Enter an underscore \'_\' if you don\'t want a prefix.', ''); } while (is_null($prefix)) { if (count($text) > 0) { $this->assistant->writeLine($text); } if (is_null($namespace) || empty($namespace)) { $namespace = $this->assistant->getOption('namespace'); } else { $namespace = $this->fixNamespace($namespace); } $defaultPrefix = GeneratorUtils::cleanPrefix($this->convertNamespaceToSnakeCase($namespace)); $prefix = GeneratorUtils::cleanPrefix($this->assistant->ask('Tablename prefix', $defaultPrefix)); if ($prefix == '') { break; } $output = $this->assistant->getOutput(); if (!preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $prefix)) { $output->writeln(sprintf('<bg=red> "%s" contains invalid characters</>', $prefix)); $prefix = $text = null; continue; } $this->assistant->setOption('prefix', $prefix); } return $prefix; }
/** * Asks for the prefix and sets it on the InputInterface as the 'prefix' option, if this option is not set yet. * Will set the default to a snake_cased namespace when the namespace has been set on the InputInterface. * * @param array $text What you want printed before the prefix is asked. If null is provided it'll write a default text. * @param string $namespace An optional namespace. If this is set it'll create the default based on this prefix. * If it's not provided it'll check if the InputInterface already has the namespace option. * * @return string The prefix. But it's also been set on the InputInterface. */ protected function askForPrefix(array $text = null, $namespace = null) { $prefix = $this->assistant->getOptionOrDefault('prefix', null); if (is_null($text)) { $text = array('You can add a prefix to the table names of the generated entities for example: ' . '<comment>projectname_bundlename_</comment>', 'Enter an underscore \'_\' if you don\'t want a prefix.', ''); } if (is_null($prefix)) { if (count($text) > 0) { $this->assistant->writeLine($text); } if (is_null($namespace) || empty($namespace)) { $namespace = $this->assistant->getOption('namespace'); } else { $namespace = $this->fixNamespace($namespace); } $defaultPrefix = GeneratorUtils::cleanPrefix($this->convertNamespaceToSnakeCase($namespace)); $prefix = GeneratorUtils::cleanPrefix($this->assistant->ask('Tablename prefix', $defaultPrefix)); $this->assistant->setOption('prefix', $prefix); } return $prefix; }