Renders the stack (Manager and repository) for an entity in a bundle

@param Bundle $bundle
@param $entityName
431592
public function renderEntityStack(Bundle $bundle, $entityName)
    {
        $configuration = $this->getEntityStackConfiguration($bundle, $entityName);

        $this->renderManagerFile($configuration);
        $this->renderRepositoryFile($configuration);
    }
560228
protected function generateDatatable($bundle, $entity, $metadata, $forceOverwrite)
    {
        try {
            $this->getDatatableGenerator($bundle)->generate($bundle, $entity, $metadata[0], $forceOverwrite);
        } catch (\RuntimeException $e) {
            // form already exists
        }
    }
965170
private void addBundle(String baseName, Locale locale, I_CmsResourceBundle bundle) {

        CmsResourceBundleLoader.addBundleToCache(baseName, locale, bundle);
    }
192379
protected function generateIndexView(AbstractResourceBundle $bundle, &$summary)
    {
        $path = $bundle->getPath() . '/Resources/views/' . $this->model . '/index.html.twig';

        if (file_exists($path)) {
            $summary[] = '';
            $summary[] = '<bg=red>Index view already exist.</>';

            return;
        }

        $this->renderFile('crud/index.html.twig.twig',
            $path,
            array(
                'bundle'  => $bundle->getName(),
                'model'   => $this->model,
                'prefix'  => $this->getBundlePrefix($bundle),
                'vars'    => strtolower(Inflector::pluralize($this->model)),
                'actions' => array(
                    'add' => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_create')
                )
            )
        );

        $summary[] = '';
        $summary[] = '<bg=green>Index view created.</>';
    }
648981
protected function generateMacrosView(AbstractResourceBundle $bundle)
    {
        $path = $bundle->getPath() . '/Resources/views/' . $this->model . '/macros.html.twig';

        if (!file_exists($path)) {
            $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($this->bundle->getName()) . '\\' . $this->model;
            $metadata = $this->getEntityMetadata($entityClass);
            $identifier = $this->getContainer()->get('doctrine')
                ->getManager()
                ->getClassMetadata($entityClass)
                ->getIdentifier();

            $actions = array();
            array_map(function($key) use ($bundle, &$actions) {
                if (in_array($key, array('show', 'update'))) {
                    $actions[$key] = strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_' . $key);
                }
            }, $this->configuration['actions']);

            $actions['delete'] = strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_delete');

            $this->renderFile('crud/macros.html.twig.twig',
                $bundle->getPath() . '/Resources/views/' . $this->model . '/macros.html.twig',
                array(
                    'bundle'  => $bundle->getName(),
                    'model'   => $this->model,
                    'prefix'  => $this->getBundlePrefix($bundle),
                    'vars'    => strtolower(Inflector::pluralize($this->model)),
                    'identifier' => $identifier[0],
                    'fields'  => $this->getFieldsFromMetadata($metadata[0]),
                    'actions' => $actions
                )
            );
        }
    }
981798
public function generate($namespace, $bundle, $dir, $format, $structure, $dbDriver)
    {
        $dir .= '/'.strtr($namespace, '\\', '/');
        if (file_exists($dir)) {
            if (!is_dir($dir)) {
                throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" exists but is a file.', realpath($dir)));
            }
            $files = scandir($dir);
            if ($files != array('.', '..')) {
                throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not empty.', realpath($dir)));
            }
            if (!is_writable($dir)) {
                throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not writable.', realpath($dir)));
            }
        }

        $driverDir = array(
            'orm' => 'Entity',
            'mongodb' => 'Document',
            'couchdb' => 'CouchDocument',
            'custom' => 'Model',
        );

        $basename = substr($bundle, 0, -6);
        $parameters = array(
            'namespace' => $namespace,
            'bundle' => $bundle,
            'format' => $format,
            'db_driver' => $dbDriver,
            'model_namespace' => $namespace.'\\'.$driverDir[$dbDriver],
            'bundle_basename' => $basename,
            'extension_alias' => Container::underscore($basename),
        );

        $this->renderFile('bundle/Bundle.php.twig', $dir.'/'.$bundle.'.php', $parameters);
        $this->renderFile('bundle/Extension.php.twig', $dir.'/DependencyInjection/'.$basename.'Extension.php', $parameters);
        $this->renderFile('bundle/Configuration.php.twig', $dir.'/DependencyInjection/Configuration.php', $parameters);
        $this->renderFile('bundle/DefaultController.php.twig', $dir.'/Controller/DefaultController.php', $parameters);
        $this->renderFile('bundle/DefaultControllerTest.php.twig', $dir.'/Tests/Controller/DefaultControllerTest.php', $parameters);
        $this->renderFile('bundle/index.html.twig.twig', $dir.'/Resources/views/Default/index.html.twig', $parameters);
        $this->renderFile('bundle/services.'.$format.'.twig', $dir.'/Resources/config/services.'.$format, $parameters);

        $this->generateRoutes($namespace, $bundle, $dir, $format, $basename);
        $this->generateModels($namespace, $bundle, $dir, $dbDriver, $basename);
        $this->generateEventsClass($namespace, $bundle, $dir, $dbDriver, $basename);

        if ($structure) {
            $this->renderFile('bundle/messages.fr.xlf', $dir.'/Resources/translations/messages.fr.xlf', $parameters);

            $this->filesystem->mkdir($dir.'/Resources/doc');
            $this->filesystem->touch($dir.'/Resources/doc/index.rst');
            $this->filesystem->mkdir($dir.'/Resources/translations');
            $this->filesystem->mkdir($dir.'/Resources/public/css');
            $this->filesystem->mkdir($dir.'/Resources/public/images');
            $this->filesystem->mkdir($dir.'/Resources/public/js');
        }
    }
925615
public function addBundle(Bundle $bundle)
    {
        foreach ($bundle as $resource) {
            if (is_string($resource)) {
                $this->addFile($resource);
            } else {
                $this->buildFromIterator($resource);
            }
        }
    }
257609
protected function generateCreateView(AbstractResourceBundle $bundle, &$summary)
    {
        $this->generateFormView($bundle);
        $path = $bundle->getPath() . '/Resources/views/' . $this->model . '/create.html.twig';

        if (file_exists($path)) {
            $summary[] = '';
            $summary[] = '<bg=red>Create view already exist.</>';

            return;
        }

        $this->renderFile('crud/create.html.twig.twig',
            $path,
            array(
                'bundle'  => $bundle->getName(),
                'model'   => $this->model,
                'prefix'  => $this->getBundlePrefix($bundle),
                'action'  => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_create'),
                'cancel'  => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_index'),
            )
        );

        $summary[] = '';
        $summary[] = '<bg=green>Create view created.</>';
    }
648745
public function pushBundle(string $name, string $bundle): self
    {
        if (!class_exists($bundle))
        {
            throw new Invalid('Processor ' . $bundle . ' not found');
        }

        $this->bundles[$name] = $bundle;

        return $this;
    }
874448
private void startBundle( final Bundle bundle )
        throws BundleException
    {
        // Don't start if bundle already active
        int bundleState = bundle.getState();
        if( bundleState == Bundle.ACTIVE )
        {
            return;
        }

        // Don't start if bundle is a fragment bundle
        Dictionary bundleHeaders = bundle.getHeaders();
        if( bundleHeaders.get( Constants.FRAGMENT_HOST ) != null )
        {
            return;
        }

        // Start bundle
        bundle.start();

        bundleState = bundle.getState();
        if( bundleState != Bundle.ACTIVE )
        {
            long bundleId = bundle.getBundleId();
            String bundleName = bundle.getSymbolicName();
            String bundleStateStr = bundleStateToString( bundleState );
            throw new BundleException(
                "Bundle (" + bundleId + ", " + bundleName + ") not started (still " + bundleStateStr + ")"
            );
        }
    }
1171237
protected function generateShowView(AbstractResourceBundle $bundle, &$summary)
    {
        $path = $bundle->getPath() . '/Resources/views/' . $this->model . '/show.html.twig';
        $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($this->bundle->getName()) . '\\' . $this->model;
        $identifier = $this->getContainer()->get('doctrine')
            ->getManager()
            ->getClassMetadata($entityClass)
            ->getIdentifier();

        if (file_exists($path)) {
            $summary[] = '';
            $summary[] = '<bg=red>Show view already exist.</>';

            return;
        }

        $this->renderFile('crud/show.html.twig.twig',
            $path,
            array(
                'bundle'     => $bundle->getName(),
                'model'      => $this->model,
                'identifier' => $identifier[0],
                'prefix'     => $this->getBundlePrefix($bundle),
                'cancel'     => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_index'),
                'actions'    => array(
                    'edit' => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_update')
                )
            )
        );

        $summary[] = '';
        $summary[] = '<bg=green>Show view created.</>';
    }
189279
public function createApplication(ObjectManager $om, $name, $route, $reference = null, $bundleName = null)
    {
        $canonicalName = strtolower(($reference === null) ? $name : $reference);
        $entity = $om->getRepository('CanalTPSamCoreBundle:Application')->findOneByCanonicalName($canonicalName);
        if (is_null($entity)) {
            $entity = new Application($name);
            $entity->setDefaultRoute($route);
            $entity->setCanonicalName($canonicalName);
            $entity->setBundleName($bundleName);

            $om->persist($entity);
        }

        $this->addReference('app-' . $entity->getCanonicalName(), $entity);
    }
208685
public function downgradeBundle(Bundle $bundle, $version)
    {
        $this->doMigrate($bundle, $version, Migrator::DIRECTION_DOWN);
    }
1111800
private function createRepository(EntityManagerInterface $entityManager, $entityName)
    {
        /** @var ClassMetadata $metadata */
        $metadata            = $entityManager->getClassMetadata($entityName);
        $repositoryClassName = $metadata->getCustomRepositoryClassName()
            ?: $entityManager->getConfiguration()->getDefaultRepositoryClassName();

        return new $repositoryClassName($entityManager, $metadata);
    }
1020037
static function add($bundle)
	{
		// load bundle config file
		if (!self::$bundles) self::$bundles = Config::load("bundler.php");

		// check if bundle exists
		if (!isset(self::$bundles[$bundle])) {
			throw new \Exception("Bundle ($bundle) not found in the config file");
		}

		foreach (self::$bundles[$bundle] as $category => $filenames) {
			$filenames = explode(",", $filenames);
			foreach ($filenames as $filename) {
				//echo "$category -> $filename <br>";
				self::$stack[$category][] = self::find($filename);
			}
		}

	}
1234449
@Override
	public void processBundles(T ctx, List<JoinableResourceBundle> bundles) {
		globalPreprocessor.processBundles(ctx, bundles);
	}
941145
private function getBundleValue(ResourceBundleInterface $bundle, string $key): array
    {
        return [
            BundleStorageInterface::INDEX_PAIR_VALUE  => $bundle->getValue($key),
            BundleStorageInterface::INDEX_PAIR_LOCALE => $bundle->getLocale(),
        ];
    }