src/Kunstmaan/GeneratorBundle/Command/KunstmaanGenerateCommand.php
protected function askForBundleName(
        $objectName,
        $namespace = null,
        $questionMoreBundles = "\nIn which bundle do you want to create the %s",
        $questionOneBundle = "The %s will be created for the <comment>%s</comment> bundle.\n"
    ) {
        if (Kernel::VERSION_ID >= 40000) {
            return new Sf4AppBundle($this->getContainer()->getParameter('kernel.project_dir'));
        }

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

        // If the user provided the namespace as input option
        if (!is_null($namespace)) {
            foreach ($ownBundles as $key => $bundleInfo) {
                if (GeneratorUtils::fixNamespace($namespace) == GeneratorUtils::fixNamespace(
                        $bundleInfo['namespace']
                    )
                ) {
                    $bundleName = $bundleInfo['name'];

                    break;
                }
            }

            // When the provided namespace was not found, we show an error on the screen and ask the bundle again
            if (empty($bundleName)) {
                $this->assistant->writeError("The provided bundle namespace '$namespace' was not found...");
            }
        }

        if (empty($bundleName)) {
            // If we only have 1 bundle, we don't need to ask
            if (count($ownBundles) > 1) {
                $bundleSelect = [];
                foreach ($ownBundles as $key => $bundleInfo) {
                    $bundleSelect[$key] = $bundleInfo['name'];
                }
                $bundleId = $this->assistant->askSelect(
                    sprintf($questionMoreBundles, $objectName),
                    $bundleSelect
                );
                $bundleName = $ownBundles[$bundleId]['name'];

                $this->assistant->writeLine('');
            } else {
                $bundleName = $ownBundles[1]['name'];
                $this->assistant->writeLine(
                    [sprintf($questionOneBundle, $objectName, $bundleName)]
                );
            }
        }

        $bundle = $this->assistant->getKernel()->getBundle($bundleName);

        return $bundle;
    }
protected function askForBundleName(
        $objectName,
        $namespace = null,
        $questionMoreBundles = "\nIn which bundle do you want to create the %s",
        $questionOneBundle = "The %s will be created for the <comment>%s</comment> bundle.\n"
    ) {
        if (Kernel::VERSION_ID >= 40000) {
            return new Sf4AppBundle($this->getContainer()->getParameter('kernel.project_dir'));
        }

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

        // If the user provided the namespace as input option
        if (!is_null($namespace)) {
            foreach ($ownBundles as $key => $bundleInfo) {
                if (GeneratorUtils::fixNamespace($namespace) == GeneratorUtils::fixNamespace(
                        $bundleInfo['namespace']
                    )
                ) {
                    $bundleName = $bundleInfo['name'];

                    break;
                }
            }

            // When the provided namespace was not found, we show an error on the screen and ask the bundle again
            if (empty($bundleName)) {
                $this->assistant->writeError("The provided bundle namespace '$namespace' was not found...");
            }
        }

        if (empty($bundleName)) {
            // If we only have 1 bundle, we don't need to ask
            if (count($ownBundles) > 1) {
                $bundleSelect = [];
                foreach ($ownBundles as $key => $bundleInfo) {
                    $bundleSelect[$key] = $bundleInfo['name'];
                }
                $bundleId = $this->assistant->askSelect(
                    sprintf($questionMoreBundles, $objectName),
                    $bundleSelect
                );
                $bundleName = $ownBundles[$bundleId]['name'];

                $this->assistant->writeLine('');
            } else {
                $bundleName = $ownBundles[1]['name'];
                $this->assistant->writeLine(
                    [sprintf($questionOneBundle, $objectName, $bundleName)]
                );
            }
        }

        $bundle = $this->assistant->getKernel()->getBundle($bundleName);

        return $bundle;
    }
protected function askForBundleName ( $ objectName , $ namespace = null , $ questionMoreBundles = "\nIn which bundle do you want to create the %s" , $ questionOneBundle = "The %s will be created for the <comment>%s</comment> bundle.\n" ) { if ( Kernel :: VERSION_ID >= 40000 ) { return new Sf4AppBundle ( $ this -> getContainer ( ) -> getParameter ( 'kernel.project_dir' ) ) ; } $ ownBundles = $ this -> getOwnBundles ( ) ; if ( count ( $ ownBundles ) <= 0 ) { $ this -> assistant -> writeError ( "Looks like you don't have created any bundles for your project..." , true ) ; } // If the user provided the namespace as input option if ( ! is_null ( $ namespace ) ) { foreach ( $ ownBundles as $ key => $ bundleInfo ) { if ( GeneratorUtils :: fixNamespace ( $ namespace ) == GeneratorUtils :: fixNamespace ( $ bundleInfo [ 'namespace' ] ) ) { $ bundleName = $ bundleInfo [ 'name' ] ; break ; } } // When the provided namespace was not found, we show an error on the screen and ask the bundle again if ( empty ( $ bundleName ) ) { $ this -> assistant -> writeError ( "The provided bundle namespace '$namespace' was not found..." ) ; } } if ( empty ( $ bundleName ) ) { // If we only have 1 bundle, we don't need to ask if ( count ( $ ownBundles ) > 1 ) { $ bundleSelect = [ ] ; foreach ( $ ownBundles as $ key => $ bundleInfo ) { $ bundleSelect [ $ key ] = $ bundleInfo [ 'name' ] ; } $ bundleId = $ this -> assistant -> askSelect ( sprintf ( $ questionMoreBundles , $ objectName ) , $ bundleSelect ) ; $ bundleName = $ ownBundles [ $ bundleId ] [ 'name' ] ; $ this -> assistant -> writeLine ( '' ) ; } else { $ bundleName = $ ownBundles [ 1 ] [ 'name' ] ; $ this -> assistant -> writeLine ( [ sprintf ( $ questionOneBundle , $ objectName , $ bundleName ) ] ) ; } } $ bundle = $ this -> assistant -> getKernel ( ) -> getBundle ( $ bundleName ) ; return $ bundle ; }
Ask for which bundle we need to generate something. It there is only one custom bundle
created by the user, we don't ask anything and just use that bundle. If the user provided
a namespace as input option, we try to get that bundle first.

@param string      $objectName          The thing we are going to create (pagepart, bundle, layout, ...)
@param string|null $namespace           The namespace provided as input option
@param string      $questionMoreBundles
@param string      $questionOneBundle

@return BundleInterface
Ask for which bundle we need to generate something . It there is only one custom bundle created by the user we don t ask anything and just use that bundle . If the user provided a namespace as input option we try to get that bundle first .