Build component files

@param string     $bundleDir
@param string     $applicationName
@param Filesystem $filesystem
503272
private static function buildComponentFiles($bundleDir, $applicationName, Filesystem $filesystem)
    {
        $filesystem->setParameters(array(
            'namespace' => $applicationName,
            'applicationName' => $applicationName,
        ));

        $filesystem->mirror(__DIR__.'/../Resources/skeleton/avoo-component', $bundleDir, null, array('override' => true));
    }
645764
protected function createBundleObject(InputInterface $input)
    {
        foreach (array('namespace', 'dir') as $option) {
            if (null === $input->getOption($option)) {
                throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option));
            }
        }

        $namespace = Validators::validateBundleNamespace($input->getOption('namespace'), false);
        if (!$bundleName = $input->getOption('bundle-name')) {
            $bundleName = strtr($namespace, array('\\' => ''));
        }
        $bundleName = Validators::validateBundleName($bundleName);
        $dir = $input->getOption('dir');

        if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) {
            $dir = getcwd().'/'.$dir;
        }
        // add trailing / if necessary
        $dir = '/' === substr($dir, -1, 1) ? $dir : $dir.'/';

        return new Bundle(
            $namespace,
            $bundleName,
            $dir,
            'yml',
            false // unused
        );
    }
592284
def bundle(self, bundle_name):
        
        if self.args.bundle or self.tcex_json.get('package', {}).get('bundle', False):
            if self.tcex_json.get('package', {}).get('bundle_packages') is not None:
                for bundle in self.tcex_json.get('package', {}).get('bundle_packages') or []:
                    bundle_name = bundle.get('name')
                    bundle_patterns = bundle.get('patterns')

                    bundle_apps = []
                    for app in self._app_packages:
                        for app_pattern in bundle_patterns:
                            p = re.compile(app_pattern, re.IGNORECASE)
                            if p.match(app):
                                bundle_apps.append(app)

                    # bundle app in zip
                    if bundle_apps:
                        self.bundle_apps(bundle_name, bundle_apps)
            else:
                self.bundle_apps(bundle_name, self._app_packages)
90562
public static function registerBundle(string $bundleId, \stdClass $bundle)
    {
        $bundle->bundleId = $bundleId;
        self::$runtimeBundles[$bundleId] = $bundle;
    }
379458
public function generate(BundleInterface $bundle, $controllerClassBasename)
    {
        $this->class = sprintf('%s\Controller\%s', $bundle->getNamespace(), $controllerClassBasename);
        $this->file = sprintf(
            '%s/Controller/%s.php',
            $bundle->getPath(),
            str_replace('\\', '/', $controllerClassBasename)
        );
        $parts = explode('\\', $this->class);

        if (file_exists($this->file)) {
            throw new \RuntimeException(sprintf(
                'Unable to generate the admin controller class "%s". The file "%s" already exists.',
                $this->class,
                realpath($this->file)
            ));
        }

        $this->renderFile('AdminController.php.twig', $this->file, array(
            'classBasename' => array_pop($parts),
            'namespace'     => implode('\\', $parts),
        ));
    }
641328
private void buildupPropertiesBundles(final File file) throws IOException {
		File[] files = file.listFiles();

		for (File f : files) {
			if (f.getName().endsWith("properties")) {
				String bundleName = f.getName().substring(0,
						f.getName().indexOf("properties") - 1);

				LOG.info("Loading: " + bundleName);
				ResourceBundle bundle = new PropertyResourceBundle(
						new FileInputStream(f));
				bundles.put(bundleName, bundle);
			}
		}
	}
260158
private function findTemplatesInThemes(BundleInterface $bundle, $theme)
    {
        $templates = $this->findTemplatesInFolder($bundle->getPath().'/Resources/themes/'.$theme);
        $name = $bundle->getName();

        foreach ($templates as $i => $template) {
            $templates[$i] = $template->set('bundle', $name);
        }

        return $templates;
    }
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');
        }
    }
654739
protected function configureAsseticBundle(ContainerBuilder $container, $outputDir)
    {
        $asseticConfig = new AsseticConfiguration();
        $container->prependExtensionConfig('assetic', [
            'assets' => $asseticConfig->build($outputDir),
            'bundles' => ['EkynaMediaBundle'],
        ]);
    }
455824
private function createBundleFile ($minifier, $fileName, $files, $sitePath, $bundleDir, $cleanCode = true)
    {
        $translator = $this->getServiceLocator()->get('translator');
        $message = '';
        $success = false;
        if (!empty($files)) {
            try {
                foreach ($files as $key => $file) {
                    //remove comments
                    if($cleanCode) {
                        $codeToAdd = $this->removeComments($sitePath . $file);
                    }else{
                        $codeToAdd = $sitePath . $file;
                    }
                    //add the file to minify later
                    $minifier->add($codeToAdd);
//                 $minifier = $this->getFileContentsViaCurl($minifier, $file);
                }
                //minify all the files
                $minifier->minify($bundleDir . $fileName);
                $message = $translator->translate('tr_front_minify_assets_compiled_successfully');
                $success = true;
            } catch (\Exception $ex) {
                /**
                 * this will occur only if the bundle.css or bundle.js
                 * is not writable or no permission or other errors
                 */
                  $message = wordwrap($ex->getMessage(), 20, "\n", true);
            }
        }else{
            $success = true;
        }

        return array(
            'message' => $message,
            'success' => $success
        );
    }
1010526
public function runApplicationComponents($applicationComponents)
    {
        foreach ($applicationComponents as $key => $applicationComponent) {
            $class = $applicationComponent->component;
            $parameters = $applicationComponent->parameters;
            $applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null);
            $applicationComponents[$key]->{'object'}->run($this->storage);
        }
    }
943525
@Override
	public void writeBundleTo(String bundlePath, Writer writer) throws ResourceNotFoundException {

		Reader rd = null;

		try {

			// If debug mode is on, resources are retrieved one by one.
			if (config.isDebugModeOn()) {

				rd = resourceHandler.getResource(null, bundlePath);
			} else {

				for (String prefix : bundlePrefixes) {
					if (bundlePath.startsWith(prefix)) {
						bundlePath = bundlePath.substring(prefix.length());
						break;
					}
				}

				// Prefixes are used only in production mode
				String path = PathNormalizer.removeVariantPrefixFromPath(bundlePath);
				rd = resourceBundleHandler.getResourceBundleReader(path);
				if (liveProcessBundles.contains(path)) {
					rd = processInLive(rd);
				}
			}

			IOUtils.copy(rd, writer);
			writer.flush();
		} catch (IOException e) {
			throw new BundlingProcessException("Unexpected IOException writing bundle[" + bundlePath + "]", e);
		} finally {
			IOUtils.close(rd);
			IOUtils.close(writer);
		}
	}
701490
static function BundleFolder($bundleName)
    {
        $packageBundles = self::PackageBundles();
        if (isset($packageBundles[$bundleName])) {
            return $packageBundles[$bundleName];
        }
        return Path::Combine(self::AppBundlesFolder(), $bundleName);
    }
277786
protected function execute(InputInterface $input, OutputInterface $output)
    {
        // find a better way to detect the Application folder
        $bundle_dir = sprintf('%s/../src/Application/Sonata/ProductBundle',
            $this->getContainer()->get('kernel')->getRootDir()
        );

        if (!is_dir($bundle_dir)) {
            throw new \Exception('Please initialize a ProductBundle first in the Application directory');
        }

        $output->writeln(sprintf('Generating files for the <info>%s</info>', $input->getArgument('product')));

        $output->writeln(' > mirroring skeleton files');

        $bundles = $this->getContainer()->get('kernel')->getBundle('SonataProductBundle', false);
        $vendorPath = '';
        foreach ($bundles as $bundle) {
            if (false !== strpos($bundle->getPath(), 'vendor')) {
                $vendorPath = $bundle->getPath();
            }
        }

        $filesystem = new Filesystem();
        $filesystem->mirror($vendorPath.'/Resources/skeleton/product', $bundle_dir);

        $output->writeln(' > mustaching skeleton files');

        Mustache::renderDir($bundle_dir, [
            'product' => $input->getArgument('product'),
            'root_name' => strtolower(preg_replace('/[A-Z]/', '_\\0', $input->getArgument('product'))),
        ]);

        $renames = [
            // entity
            '%s/Entity/Entity.php' => '%s/Entity/%s.php',
            '%s/Repository/Repository.php' => '%s/Repository/%sRepository.php',
            '%s/Provider/EntityProductProvider.php' => '%s/Provider/%sProductProvider.php',
            '%s/Resources/config/doctrine/Entity.orm.xml' => '%s/Resources/config/doctrine/%s.orm.xml',
            '%s/Resources/config/serializer/Entity.xml' => '%s/Resources/config/serializer/Entity.%s.xml',

            // controller
            '%s/Controller/Controller.php' => '%s/Controller/%sController.php',

            // templates
            '%s/Resources/views/Entity/view.html.twig' => '%s/Resources/views/%s/view.html.twig',
            '%s/Resources/views/Entity/form_basket_element.html.twig' => '%s/Resources/views/%s/form_basket_element.html.twig',
            '%s/Resources/views/Entity/final_review_basket_element.html.twig' => '%s/Resources/views/%s/final_review_basket_element.html.twig',
        ];

        $dirs = [
            sprintf('%s/Resources/views/%s', $bundle_dir, $input->getArgument('product')),
            sprintf('%s/Product/%s', $bundle_dir, $input->getArgument('product')),
            sprintf('%s/Provider', $bundle_dir),
        ];

        foreach ($dirs as $dir) {
            $filesystem->mkdir($dir);
        }

        $output->writeln(' > renaming skeleton files');

        foreach ($renames as $from => $to) {
            $from = sprintf($from, $bundle_dir);
            $to = sprintf($to, $bundle_dir, $input->getArgument('product'));

            if (is_file($to) || is_dir($to)) {
                $output->writeln(sprintf(' <info>-</info> deleting unused file : <comment>%s</comment>', basename($from)));
                $filesystem->remove($from);

                continue;
            }

            $output->writeln(sprintf(' <info>+</info> rename <comment>%s</comment> to <comment>%s</comment>', $from, $to));

            $filesystem->rename($from, $to);
        }

        $filesystem->remove([
            sprintf('%s/Product/Entity', $bundle_dir),
            sprintf('%s/Resources/views/Entity', $bundle_dir),
        ]);

        $product = $input->getArgument('product');
        $service = $input->getArgument('service_id');

        $output->write(Mustache::renderString(<<<CONFIG

<info>1. Add this service definition</info>

<comment>services:</comment>
    {{ service }}.manager:
        class: Sonata\ProductBundle\Entity\ProductManager
        arguments:
            - Application\Sonata\ProductBundle\Entity\{{ product }}
            - @doctrine

    {{ service }}.type:
        class: Application\Sonata\ProductBundle\Provider\{{ product }}ProductProvider
        arguments:
            - @serializer

<info>2. Add this service configuration</info>

<comment>sonata_product:</comment>
    products:
        {{ service }}:
            provider: {{ service }}.type
            manager: {{ service }}.manager

<info>3. Define the Product serialization inheritance :</info>

Add this line in <comment>/src/Application/Sonata/ProductBundle/Resources/config/serializer/Entity.Product.xml</comment>

    <discriminator-class value="{{ service }}">Application\Sonata\ProductBundle\Entity\{{ product }}</discriminator-class>

You can customize the serialization of your Product by editing /src/Application/Sonata/ProductBundle/Resources/config/serializer/Entity.Product.xml
(see JMS serializer documentation for more information).

<info>4. Tweak the Product to match its functional requirements</info>

                                <comment>Good luck !</comment>


CONFIG
, ['service' => $service, 'product' => $product]
));
    }
712351
private JoinableResourceBundle buildJoinableResourceBundle(PropertiesConfigHelper props, String bundleName,
			String fileExtension, ResourceReaderHandler rsHandler) {

		// Id for the bundle
		String bundleId = props.getCustomBundleProperty(bundleName, PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_ID);

		String bundlePrefix = props.getCustomBundleProperty(bundleName,
				PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_BUNDLE_PREFIX);

		boolean isComposite = props.getCustomBundleBooleanProperty(bundleName,
				PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_COMPOSITE_FLAG);

		InclusionPattern inclusionPattern = getInclusionPattern(props, bundleName);
		JoinableResourceBundleImpl bundle = null;
		if (isComposite) {
			List<JoinableResourceBundle> nestedBundles = new ArrayList<>();
			List<String> nestedBundleNames = props.getCustomBundlePropertyAsList(bundleName,
					PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_COMPOSITE_NAMES);
			for (String nestedBundleName : nestedBundleNames) {
				JoinableResourceBundle nestedBundle = buildJoinableResourceBundle(props, nestedBundleName,
						fileExtension, rsHandler);
				nestedBundles.add(nestedBundle);
			}
			bundle = new CompositeResourceBundle(bundleId, bundleName, nestedBundles, inclusionPattern, rsHandler,
					bundlePrefix, fileExtension, generatorRegistry);
		} else {

			bundle = new JoinableResourceBundleImpl(bundleId, bundleName, bundlePrefix, fileExtension, inclusionPattern,
					rsHandler, generatorRegistry);
		}

		// Override bundle postprocessor
		String bundlePostProcessors = props.getCustomBundleProperty(bundleName,
				PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_POSTPROCESSOR);
		if (StringUtils.isNotEmpty(bundlePostProcessors)) {
			bundle.setBundlePostProcessor(chainFactory.buildPostProcessorChain(bundlePostProcessors));
		}

		// Override unitary postprocessor
		String unitaryPostProcessors = props.getCustomBundleProperty(bundleName,
				PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_FILE_POSTPROCESSOR);
		if (StringUtils.isNotEmpty(unitaryPostProcessors)) {
			bundle.setUnitaryPostProcessor(chainFactory.buildPostProcessorChain(unitaryPostProcessors));
		}

		// Set conditional comment for IE, in case one is specified
		String explorerConditionalCondition = props.getCustomBundleProperty(bundleName,
				PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_IE_CONDITIONAL_EXPRESSION);
		if (StringUtils.isNotEmpty(explorerConditionalCondition)) {
			bundle.setExplorerConditionalExpression(explorerConditionalCondition);
		}

		// Sets the alternate URL for production mode.
		String alternateProductionURL = props.getCustomBundleProperty(bundleName,
				PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_PRODUCTION_ALT_URL);
		if (StringUtils.isNotEmpty(alternateProductionURL)) {
			bundle.setAlternateProductionURL(props.getCustomBundleProperty(bundleName,
					PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_PRODUCTION_ALT_URL));
		}

		boolean hasDebugURL = false;
		// Sets the debug URL for debug mode.
		if (null != props.getCustomBundleProperty(bundleName, BUNDLE_FACTORY_CUSTOM_DEBUG_URL)) {
			bundle.setDebugURL(props.getCustomBundleProperty(bundleName, BUNDLE_FACTORY_CUSTOM_DEBUG_URL));
			hasDebugURL = true;
			if (StringUtils.isEmpty(bundle.getAlternateProductionURL())) {
				throw new IllegalArgumentException("The bundle '" + bundleName
						+ "', which use a static external resource in debug mode, must use an external resource in Production mode.\n"
						+ "Please check your configuration. ");
			}

			if (StringUtils.isNotEmpty(props.getCustomBundleProperty(bundleName, BUNDLE_FACTORY_CUSTOM_MAPPINGS))) {
				throw new IllegalArgumentException("The bundle '" + bundleName
						+ "', which use a static external resource in debug mode, can't have a bundle mapping.\n"
						+ "Please check your configuration. ");
			}
		}

		// Sets the licence path lists.
		Set<String> licencePathList = props.getCustomBundlePropertyAsSet(bundleName,
				PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_LICENCE_PATH_LIST);
		if (!licencePathList.isEmpty()) {
			bundle.setLicensesPathList(licencePathList);
		}

		List<String> mappings = props.getCustomBundlePropertyAsList(bundleName,
				PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_MAPPINGS);
		if (!hasDebugURL && mappings.isEmpty() && !bundle.isComposite()) {
			throw new IllegalArgumentException("No mappings were defined for the bundle with name: " + bundleName
					+ ". Please specify at least one in configuration. ");
		}

		if (!hasDebugURL) {

			// Add the mappings
			bundle.setMappings(mappings);

			Map<String, VariantSet> variants = props.getCustomBundleVariantSets(bundleName);
			bundle.setVariants(variants);

			// Checks if the bundle files have been modified
			verifyIfBundleIsModified(bundle, mappings, props);
			if (!bundle.isDirty()) {
				for (String variantKey : bundle.getVariantKeys()) {
					if (StringUtils.isNotEmpty(variantKey)) {
						String hashcode = props.getCustomBundleProperty(bundleName,
								PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_HASHCODE_VARIANT + variantKey);
						bundle.setBundleDataHashCode(variantKey, hashcode);
					}
				}

				String hashcode = props.getCustomBundleProperty(bundleName,
						PropertiesBundleConstant.BUNDLE_FACTORY_CUSTOM_HASHCODE);
				bundle.setBundleDataHashCode(null, hashcode);
			}
		}

		return bundle;
	}
35995
public function createBundleSchema($bundleName)
    {
        if (null === $bundle = $this->_application->getBundle($bundleName)) {
            return;
        }

        try {
            $schemaTool = new SchemaTool($bundle->getEntityManager());
            $classes = $this->getBundleSchema($bundle);
            $schemaTool->dropSchema($classes);
            $schemaTool->createSchema($classes);
            unset($schemaTool);
        } catch (\Exception $e) {
            echo $e->getMessage()."\n";
        }
    }
965170
private void addBundle(String baseName, Locale locale, I_CmsResourceBundle bundle) {

        CmsResourceBundleLoader.addBundleToCache(baseName, locale, bundle);
    }