build WidgetBundle files.

@param string $namespace
@param string $format
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);
        }
    }
1276177
public static function add_namespaces(array $namespaces, $prepend = false)
	{
		if ( ! $prepend)
		{
			static::$namespaces = array_merge(static::$namespaces, $namespaces);
		}
		else
		{
			static::$namespaces = $namespaces + static::$namespaces;
		}
	}
128105
public function make($namespace)
    {
        $unqualifiedNames = explode('\\', $namespace);
        $vendorName = array_shift($unqualifiedNames);
        $bundleName = array_pop($unqualifiedNames);

        $bundleClassname = $bundleName;
        if ('Symfony' !== $vendorName) {
            $bundleClassname = $vendorName.$bundleName;
        }

        $fullyQualifiedClassname = $namespace.'\\'.$bundleClassname;

        return new Bundle($fullyQualifiedClassname);
    }
756943
private function addService($path, $bundleName, $name, $formTypeName)
    {
        $ref = '<services>';
        $replaceBefore = true;
        $group = $bundleName . '_' . $name;

        $declaration = <<<EOF
        <service id="$bundleName.form.type.$name" class="%$bundleName.form.type.$name.class%">
            <argument>%$bundleName.model.$name.class%</argument>
            <argument type="collection">
                <argument>$group</argument>
            </argument>
            <tag name="form.type" alias="$formTypeName" />
        </service>
EOF;

        if ($this->refExist($path, $declaration)) {
            return;
        }

        if (!$this->refExist($path, $ref)) {
            $ref = '</container>';
            $replaceBefore = false;
            $declaration = <<<EOF
    <services>
$declaration
    </services>
EOF;
        }

        $this->dumpFile($path, "\n" . $declaration . "\n", $ref, $replaceBefore);
    }
171556
public static function getFormatClass($format)
    {
        // Return a namespace in a given format
        $class = sprintf('%s\Format\%sFormat', __NAMESPACE__, ucfirst(strtolower($format)));

        if (!class_exists($class)) {
            throw new \DomainException(
                sprintf(
                    'Structure format: %s not supported. Class: %s not found.',
                    $format,
                    $class
                )
            );
        }

        return $class;
    }
792854
public function addTwigPath(string $namespace, string $path): ExtensionInterface
    {
        if ($this->driver) {
            throw new \RuntimeException('Driver has already been created.  Namespaces cannot be added.');
        }
        $this->twigNamespaces[$namespace][] = $path;

        return $this;
    }
419855
public function setFormat(string $format): VisualizerTask
    {
        switch ($format) {
            case VisualizerTask::FORMAT_PUML:
            case VisualizerTask::FORMAT_PNG:
            case VisualizerTask::FORMAT_EPS:
            case VisualizerTask::FORMAT_SVG:
                $this->format = $format;
                break;
            default:
                $message = "'$format' is not a valid format";
                $this->log($message, Project::MSG_ERR);
                throw new BuildException($message);
                break;
        }

        return $this;
    }
70034
public function addingNamespaceInComposer($namespace, $path, $output = 'composer.json')
    {
        $file = base_path('composer.json');
        $data = json_decode($this->filesystem->get($file), true);
        
        $rootStub = $this->config->get('tie.stubs.root');
        if(is_array($rootStub)) {
            $rootStub = data_get($this->config->get($rootStub), 'path',  '');
        }

        $path = str_replace(base_path().'/', '', $path) . '/' . $rootStub;

        $data["autoload"]["psr-4"] = array_merge($data["autoload"]["psr-4"], [ $namespace => $path ]);
        $this->filesystem->put(base_path($output), json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
    }
463857
protected function namespaceCreateAllDir(string $namespace){
        if ( is_dir($namespace)) return;
        $dirList = explode('\\' , str_replace('/' , '\\' , $namespace));
        $path = $this->annotationConfig->getConfig()['buildPath'];
        foreach ($dirList as $k => $dir){
            $path .=  '/' . $dir;
            // if not existed create the dir
            if ( !is_dir($path)) mkdir($path);
        }
    }
27280
protected function file( string $namespace ): FileInterface {

    $meta = $this->getNamespace( $namespace );
    return $this->path->get( $namespace . '.' . $meta[ 'format' ] );
  }
372732
private function getBundle(string $locale, string $namespace)
    {
        assert(empty($locale) === false && empty($namespace) === false);

        $bundles   = $this->getBundles();
        $hasBundle = isset($bundles[$locale][$namespace]) === true;
        $result    = $hasBundle === true ? $bundles[$locale][$namespace] : null;

        return $result;
    }
932804
protected function writeRulesFile($namespace)
    {
        $stub = file_get_contents(
            __DIR__.'/../Stubs/Rules.php'
        );

        $stub = $this->replace('{{Namespace}}', $namespace, $stub);

        file_put_contents(
            base_path('app/Settings/Resources/Rules.php'),
            $stub
        );
    }
266807
public function getWidgetMetadata($format = null)
    {
        $options = $this->getOptions($format)
            ->usePeriod(false);

        return $this->request->send($options);
    }
698582
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new WidgetContentResolverPass());
        //get widgetItems
        $container->addCompilerPass(new WidgetItemPass());
    }
176168
public function exportUsers(Workspace $workspace, $format)
    {
        $this->checkEditionAccess($workspace);
        $exporter = $this->container->get('claroline.exporter.' . $format);
        $exporterManager = $this->container->get('claroline.manager.exporter_manager');
        $file = $exporterManager->export(
            'Claroline\CoreBundle\Entity\User',
            $exporter,
            array('workspace' => $workspace)
        );
        $response = new StreamedResponse();

        $response->setCallBack(
            function () use ($file) {
                readfile($file);
            }
        );

        $response->headers->set('Content-Transfer-Encoding', 'octet-stream');
        $response->headers->set('Content-Type', 'application/force-download');
        $response->headers->set('Content-Disposition', 'attachment; filename=users.' . $format);

        switch ($format) {
            case 'csv': $response->headers->set('Content-Type', 'text/csv'); break;
            case 'xls': $response->headers->set('Content-Type', 'application/vnd.ms-excel'); break;
        }

        $response->headers->set('Connection', 'close');

        return $response;
    }
367864
public function add_template_directory($directory, $namespace = null) {
		if ($this->filesystem_loader === null) {
			$this->filesystem_loader = new \Twig_Loader_Filesystem($directory);
		}

		if ($namespace === null) {
			$this->filesystem_loader->addPath($directory);
		} else {
			$this->filesystem_loader->addPath($directory, $namespace);
		}
	}
1348595
public static function registerNamespace($namespace, $prepend = false)
    {
        if (false === $prepend) {
            self::$namespaces[] = $namespace;
        } else {
            array_unshift(self::$namespaces, $namespace);
        }
    }