Get the bundle name from an Entity namespace

@param $entityNamespace
@param $bundles
@return string|null
547892
protected static function getBundleNameFromEntity($entityNamespace, $bundles)
    {
        $dataBaseNamespace = substr($entityNamespace, 0, strpos($entityNamespace, '\\Entity'));

        foreach ($bundles as $type => $bundle) {
            $bundleRefClass = new \ReflectionClass($bundle);
            if ($bundleRefClass->getNamespaceName() === $dataBaseNamespace) {
                return $type;
            }
        }

        return null;
    }
1193829
protected function getSchemasFromBundle(BundleInterface $bundle)
    {
        $finalSchemas = array();

        if (is_dir($dir = $bundle->getPath() . '/Resources/config')) {
            $finder = new Finder();
            $schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir);

            if (iterator_count($schemas)) {
                foreach ($schemas as $schema) {
                    $logicalName = $this->transformToLogicalName($schema, $bundle);
                    $finalSchema = new \SplFileInfo($this->getFileLocator()->locate($logicalName));

                    $finalSchemas[(string)$finalSchema] = array($bundle, $finalSchema);
                }
            }
        }

        return $finalSchemas;
    }
39186
public function generate($namespace, $bundle, $dir)
    {
        $dir .= '/' . strtr($namespace, '\\', '/');
        if (file_exists($dir)) {
            throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not empty.', realpath($dir)));
        }

        $basename = substr($bundle, 0, -6);
        $parameters = array(
            'namespace' => $namespace,
            'bundle' => $bundle,
            'bundle_basename' => $basename,
            'extension_alias' => Container::underscore($basename),
        );

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

        $this->renderFile('/bundle/services.yml', $dir . '/Resources/config/services.yml', $parameters);
        $this->renderFile('/bundle/routing.yml', $dir . '/Resources/config/routing.yml', $parameters);
    }
1169041
private function buildNamingMap(array $enabledBundles, array $filter)
    {
        $namingMap = [];

        foreach ($enabledBundles as $bundleName => $bundleNamespace) {
            if (count($filter) && !$this->matchFilter($bundleNamespace, $filter)) {
                continue;
            }
            $bundleNamespace = preg_replace("/$bundleName$/", '',
                $bundleNamespace);
            $bundleName = preg_replace('/Bundle$/', '', $bundleName);
            $namingMap[$this->underscore($bundleName)] = $bundleNamespace;
        }

        return $namingMap;
    }
60865
public static function fromBundle(Bundle $bundle): Descriptor
    {
        // Values from bundle
        $name = $bundle->getName();
        $rootNamespace = $bundle->getNamespace();
        $path = $bundle->getPath();

        // Default values, not provided by bundle directly
        $configurationRootName = '';

        return new static($name, $configurationRootName, $rootNamespace, $path);
    }
572828
protected function getValueOptionsFromEntity($entityNamespace) {
		$targets = $this->objectManager->getRepository($entityNamespace)->findBy([], ['id' => 'ASC']);
		$displayNameGetter = 'get' . ucfirst($entityNamespace::DISPLAY_NAME_PROPERTY);
		$options = [];
		foreach ($targets as $target) {
			$options[$target->getId()] = $target->$displayNameGetter();
		}
	
		return $options;
	}
135738
private function getAdminServiceId($bundleName, $adminClassBasename)
    {
        $prefix = substr($bundleName, -6) == 'Bundle' ? substr($bundleName, 0, -6) : $bundleName;
        $suffix = substr($adminClassBasename, -5) == 'Admin' ? substr($adminClassBasename, 0, -5) : $adminClassBasename;
        $suffix = str_replace('\\', '.', $suffix);

        return Container::underscore(sprintf(
            '%s.admin.%s',
            $prefix,
            $suffix
        ));
    }
16289
public function getBundleLoader($bundle, $controller, $params = null){
        $attributes = [
            'data-config'     => $this->configUrl,
            'src'             => $bundle,
            'data-controller' => $controller
        ];

        if(!is_null($params)){
            $attributes['data-params'] = json_encode($params);
        }

        return $this->buildScriptTag($attributes);
    }
819678
protected function getRoutingNodeName()
    {
        $name = strtolower($this->getPackage()->getName());
        // package with the bundle can contain the word a 'bundle' in the name
        $name = preg_replace('/(\/.+)[^a-z]bundle$/', '$1', $name);
        $name = preg_replace('/[^a-z_]+/', '_', $name);

        return $name;
    }
488763
public function generate($namespace, $bundle, $dir, $format, $structure, $fields = null, $parent = null, $packagistParentName = null, $contentResolver = false, $parentContentResolver = false, $orgname = null, $cache = false)
    {
        $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 !== ['.', '..']) {
                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)));
            }
        }

        $basename = substr($bundle, 0, -6);
        $widget = str_replace('VictoireWidget', '', $basename);
        $_fields = [];

        foreach ($fields as $_field) {
            $_fields[] = $_field['fieldName'];
        }

        //guess the toString property we could use
        $toStringProperty = 'id';
        if (in_array('name', $_fields)) {
            $toStringProperty = 'name';
        } elseif (in_array('title', $_fields)) {
            $toStringProperty = 'title';
        } elseif (in_array('description', $_fields)) {
            $toStringProperty = 'description';
        }

        $parameters = [
            'namespace'               => $namespace,
            'bundle'                  => $bundle,
            'parent'                  => $parent,
            'packagistParentName'     => $packagistParentName,
            'orgname'                 => $orgname,
            'widget'                  => $widget,
            'format'                  => $format,
            'fields'                  => $fields,
            'toStringProperty'        => $toStringProperty,
            'bundle_basename'         => $basename,
            'content_resolver'        => $contentResolver,
            'cache'                   => $cache,
            'parent_content_resolver' => $parentContentResolver,
            'extension_alias'         => Container::underscore($basename),
        ];

        $this->renderFile('bundle/Bundle.php.twig', $dir.'/'.$bundle.'.php', $parameters);
        $this->renderFile('README.md.twig', $dir.'/README.md', $parameters);
        $this->renderFile('composer.json.twig', $dir.'/composer.json', $parameters);
        $this->renderFile('bundle/Extension.php.twig', $dir.'/DependencyInjection/'.$basename.'Extension.php', array_merge($parameters, ['format' => 'yml']));
        $this->renderFile('bundle/Configuration.php.twig', $dir.'/DependencyInjection/Configuration.php', $parameters);

        $this->renderFile('widget/entity.php.twig', $dir.'/Entity/Widget'.$widget.'.php', $parameters);
        $this->renderFile('widget/form.php.twig', $dir.'/Form/Widget'.$widget.'Type.php', $parameters);

        $this->renderFile('widget/config.yml.twig', $dir.'/Resources/config/config.yml', $parameters);
        $this->renderFile('widget/services.yml.twig', $dir.'/Resources/config/services.yml', $parameters);

        $this->renderFile('widget/victoire.xliff.twig', $dir.'/Resources/translations/victoire.en.xliff', $parameters);
        $this->renderFile('widget/victoire.xliff.twig', $dir.'/Resources/translations/victoire.fr.xliff', $parameters);

        //Generate new and Edit views
        $this->renderFile('widget/views/new.html.twig.twig', $dir.'/Resources/views/new.html.twig', $parameters);
        $this->renderFile('widget/views/edit.html.twig.twig', $dir.'/Resources/views/edit.html.twig', $parameters);
        $this->renderFile('widget/views/show.html.twig.twig', $dir.'/Resources/views/show.html.twig', $parameters);

        if ($contentResolver) {
            $parameters['parentResolver'] = class_exists('Victoire\\Widget\\'.$parent.'Bundle\\Widget\\Resolver\\Widget'.$parent.'ContentResolver');
            $this->renderFile('widget/ContentResolver.php.twig', $dir.'/Resolver/Widget'.$widget.'ContentResolver.php', $parameters);
        }
    }
543510
public function getNamespace($namespace, $documentsDirectory = null)
    {
        if (!$documentsDirectory) {
            $documentsDirectory = $this->documentDir;
        }

        if (strpos($namespace, ':') !== false) {
            list($bundle, $document) = explode(':', $namespace);
            $bundle = $this->getBundleClass($bundle);

            // If bundle has a sub-namespace it needs to be replaced
            if (strpos($documentsDirectory, '\\')) {
                $bundleSubNamespace = substr(
                    $bundle,
                    $start = strpos($bundle, '\\') + 1,
                    strrpos($bundle, '\\') - $start + 1
                );

                $documentsDirectory = str_replace(
                    $bundleSubNamespace,
                    '',
                    $documentsDirectory
                );
            }

            $namespace = substr($bundle, 0, strrpos($bundle, '\\')) . '\\' .
                $documentsDirectory . '\\' . $document;
        }

        return $namespace;
    }
596871
protected function getObjectRepository(string $entityNamespace): ? ObjectRepository
    {
        return $this
            ->get('base.object_repository_provider')
            ->getObjectRepositoryByEntityNamespace(
                $this->locateEntity($entityNamespace)
            );
    }
212425
private function getServiceDocument(Definition $service, $ns, $bundle, $doc)
    {
        $tags = $service->getTag('graviton.rest');
        if (!empty($tags[0]['collection'])) {
            $doc = $tags[0]['collection'];
            $bundle = $tags[0]['collection'];
        }

        if (strtolower($ns) === 'gravitondyn') {
            $ns = 'GravitonDyn';
        }

        return sprintf(
            '%s\\%s\\Document\\%s',
            ucfirst($ns),
            ucfirst($bundle).'Bundle',
            ucfirst($doc)
        );
    }
687740
protected function retrieveBundleWebFolder()
    {
        $asset = $this->asset;
        
        $namespacesFile = $this->kernel->getRootDir() . '/../vendor/composer/autoload_namespaces.php';
        if (file_exists($namespacesFile)) {
            $map = require $namespacesFile;
            foreach ($map as $namespace => $paths) {
                if ( ! is_array($paths)) {
                    $paths = array($paths);
                }
                
                foreach($paths as $path) {
                    if (strpos($this->asset, $path) !== false) {
                        preg_match('/Bundle(.*)/', $this->asset, $matches);
                        $asset = str_replace("\\", "", $namespace) . $matches[1];
                        break;
                    }
                }
            }
        }

        preg_match('/([^@\/][\w]+Bundle)\/(Resources\/public)?\/(.*)/', $asset, $matches);
        if (!empty($matches) && count($matches) == 4) {
            return sprintf('bundles/%s/%s', preg_replace('/bundle$/', '', strtolower($matches[1])), $matches[3]);
        }

        preg_match('/[\/]?(bundles.*)/', strtolower($asset), $matches);
        if (!empty($matches)) {
            return $matches[1];
        }

        $asset = str_replace("@", "", strtolower($asset));
        $bundleDir = preg_replace('/bundle$/', '', $asset);

        return ($bundleDir !== $asset) ? 'bundles/' . $bundleDir : null;
    }
1240240
public function getBundles($extension = null)
    {
        if ($extension === null) {
            return $this->bundles;
        }
        elseif (isset($this->bundles[$extension])) {
            return $this->bundles[$extension];
        }
        else {
            return null;
        }
    }
1043287
def get_bundle_by_name(self, bundle_name):
        # type: (str) -> Optional[Bundle]
        
        if bundle_name is None:
            # Nothing to do
            return None

        if bundle_name is self.get_symbolic_name():
            # System bundle requested
            return self

        with self.__bundles_lock:
            for bundle in self.__bundles.values():
                if bundle_name == bundle.get_symbolic_name():
                    # Found !
                    return bundle

            # Not found...
            return None
1150812
public function getPrefixForNamespace( $namespace )
	{
		if ( ! isset( $this->processedSchemasByNamespace ) ||
			 count( $this->processedSchemasByNamespace ) != count( $this->processedSchemas )
		)
		{
			$this->processedSchemasByNamespace = array_flip( $this->processedSchemas );
		}

		return isset( $this->processedSchemasByNamespace[ $namespace ] )
			? $this->processedSchemasByNamespace[ $namespace ]
			: false;
	}