src/Kunstmaan/GeneratorBundle/Helper/InputAssistant.php
public function askForNamespace(array $text = null)
    {
        $namespace = $this->input->hasOption('namespace') ? $this->input->getOption('namespace') : null;

        // When the Namespace is filled in return it immediately if valid.
        try {
            if (!is_null($namespace) && !empty($namespace)) {
                Validators::validateBundleNamespace($namespace);

                return $namespace;
            }
        } catch (\Exception $error) {
            $this->writeError(array("Namespace '$namespace' is incorrect. Please provide a correct value.", $error->getMessage()));
            exit;
        }

        $ownBundles = $this->getOwnBundles();
        if (count($ownBundles) <= 0) {
            $this->writeError("Looks like you don't have created a bundle for your project, create one first.", true);
        }

        $namespace = '';

        // If we only have 1 or more bundles, we can prefill it.
        if (count($ownBundles) > 0) {
            $namespace = $ownBundles[1]['namespace'] . '/' . $ownBundles[1]['name'];
        }

        $namespaces = $this->getNamespaceAutoComplete($this->kernel);

        if (!is_null($text) && (count($text) > 0)) {
            $this->output->writeln($text);
        }

        $question = new Question($this->questionHelper->getQuestion('Bundle Namespace', $namespace), $namespace);
        $question->setValidator(array('Sensio\Bundle\GeneratorBundle\Command\Validators', 'validateBundleNamespace'));
        $question->setAutocompleterValues($namespaces);
        $namespace = $this->questionHelper->ask($this->input, $this->output, $question);

        if ($this->input->hasOption('namespace')) {
            $this->input->setOption('namespace', $namespace);
        }

        return $namespace;
    }
public function askForNamespace(array $text = null)
    {
        $namespace = $this->input->hasOption('namespace') ? $this->input->getOption('namespace') : null;

        // When the Namespace is filled in return it immediately if valid.
        try {
            if (!is_null($namespace) && !empty($namespace)) {
                Validators::validateBundleNamespace($namespace);

                return $namespace;
            }
        } catch (\Exception $error) {
            $this->writeError(array("Namespace '$namespace' is incorrect. Please provide a correct value.", $error->getMessage()));
            exit;
        }

        $ownBundles = $this->getOwnBundles();
        if (count($ownBundles) <= 0) {
            $this->writeError("Looks like you don't have created a bundle for your project, create one first.", true);
        }

        $namespace = '';

        // If we only have 1 or more bundles, we can prefill it.
        if (count($ownBundles) > 0) {
            $namespace = $ownBundles[1]['namespace'] . '/' . $ownBundles[1]['name'];
        }

        $namespaces = $this->getNamespaceAutoComplete($this->kernel);

        if (!is_null($text) && (count($text) > 0)) {
            $this->output->writeln($text);
        }

        $question = new Question($this->questionHelper->getQuestion('Bundle Namespace', $namespace), $namespace);
        $question->setValidator(array('Sensio\Bundle\GeneratorBundle\Command\Validators', 'validateBundleNamespace'));
        $question->setAutocompleterValues($namespaces);
        $namespace = $this->questionHelper->ask($this->input, $this->output, $question);

        if ($this->input->hasOption('namespace')) {
            $this->input->setOption('namespace', $namespace);
        }

        return $namespace;
    }
public function askForNamespace ( array $ text = null ) { $ namespace = $ this -> input -> hasOption ( 'namespace' ) ? $ this -> input -> getOption ( 'namespace' ) : null ; // When the Namespace is filled in return it immediately if valid. try { if ( ! is_null ( $ namespace ) && ! empty ( $ namespace ) ) { Validators :: validateBundleNamespace ( $ namespace ) ; return $ namespace ; } } catch ( \ Exception $ error ) { $ this -> writeError ( array ( "Namespace '$namespace' is incorrect. Please provide a correct value." , $ error -> getMessage ( ) ) ) ; exit ; } $ ownBundles = $ this -> getOwnBundles ( ) ; if ( count ( $ ownBundles ) <= 0 ) { $ this -> writeError ( "Looks like you don't have created a bundle for your project, create one first." , true ) ; } $ namespace = '' ; // If we only have 1 or more bundles, we can prefill it. if ( count ( $ ownBundles ) > 0 ) { $ namespace = $ ownBundles [ 1 ] [ 'namespace' ] . '/' . $ ownBundles [ 1 ] [ 'name' ] ; } $ namespaces = $ this -> getNamespaceAutoComplete ( $ this -> kernel ) ; if ( ! is_null ( $ text ) && ( count ( $ text ) > 0 ) ) { $ this -> output -> writeln ( $ text ) ; } $ question = new Question ( $ this -> questionHelper -> getQuestion ( 'Bundle Namespace' , $ namespace ) , $ namespace ) ; $ question -> setValidator ( array ( 'Sensio\Bundle\GeneratorBundle\Command\Validators' , 'validateBundleNamespace' ) ) ; $ question -> setAutocompleterValues ( $ namespaces ) ; $ namespace = $ this -> questionHelper -> ask ( $ this -> input , $ this -> output , $ question ) ; if ( $ this -> input -> hasOption ( 'namespace' ) ) { $ this -> input -> setOption ( 'namespace' , $ namespace ) ; } return $ namespace ; }
Asks for the namespace and sets it on the InputInterface as the 'namespace' option, if this option is not set yet.

@param array $text what you want printed before the namespace is asked

@return string The namespace. But it's also been set on the InputInterface.
Asks for the namespace and sets it on the InputInterface as the namespace option if this option is not set yet .