diff --git a/.php_cs b/.php_cs index dbbd3ad00..cc1acabbf 100644 --- a/.php_cs +++ b/.php_cs @@ -25,6 +25,6 @@ return Symfony\CS\Config\Config::create() 'Resources/public', 'Tests/js', ]) - ->files()->name('*.php') + ->files()->name('/\.php$/') ) ; diff --git a/Command/GeneratePlatformUISkeletonBundleCommand.php b/Command/GeneratePlatformUISkeletonBundleCommand.php new file mode 100644 index 000000000..386702dd5 --- /dev/null +++ b/Command/GeneratePlatformUISkeletonBundleCommand.php @@ -0,0 +1,38 @@ +setName('generate:ez:platform-ui-plugin'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->getGenerator( + $this->getContainer()->get('kernel')->getBundle('eZPlatformUIBundle') + ); + parent::execute($input, $output); + } + + protected function createGenerator() + { + return new PlatformUIPluginGenerator($this->getContainer()->get('filesystem')); + + // $thisBundle = $this->getContainer()->get('kernel')->getBundle('BDEzPlatformUIExtensionSkeletonGeneratorBundle'); + // $skeletonDirs = $this->getSkeletonDirs($thisBundle); + // $generator->setSkeletonDirs($skeletonDirs); + // return $generator; + } +} diff --git a/Generator/PlatformUIPluginGenerator.php b/Generator/PlatformUIPluginGenerator.php new file mode 100644 index 000000000..ec7a9cf14 --- /dev/null +++ b/Generator/PlatformUIPluginGenerator.php @@ -0,0 +1,77 @@ +filesystem = $filesystem; + } + + public function generate($namespace, $bundle, $dir, $format, $structure) + { + $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))); + } + } + + $basename = substr($bundle, 0, -6); + $parameters = array( + 'namespace' => $namespace, + 'bundle' => $bundle, + 'format' => $format, + 'bundle_basename' => $basename, + 'extension_alias' => Container::underscore($basename), + ); + + if ('xml' === $format || 'annotation' === $format) { + $this->renderFile('bundle/yui.xml.twig', $dir . '/Resources/config/yui.xml', $parameters); + $this->renderFile('bundle/css.xml.twig', $dir . '/Resources/config/css.xml', $parameters); + } else { + $this->renderFile('bundle/yui.' . $format . '.twig', $dir . '/Resources/config/yui.' . $format, $parameters); + $this->renderFile('bundle/css.' . $format . '.twig', $dir . '/Resources/config/css.' . $format, $parameters); + } + + $this->renderFile('bundle/Bundle.php.twig', $dir . '/' . $bundle . '.php', $parameters); + $this->renderFile('bundle/PlatformUIPluginExtension.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); + + if ('annotation' != $format) { + $this->renderFile('bundle/routing.'.$format.'.twig', $dir.'/Resources/config/routing.'.$format, $parameters); + } + + 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'); + } + } +} diff --git a/Resources/SensioGeneratorBundle/skeleton/bundle/Configuration.php.twig b/Resources/SensioGeneratorBundle/skeleton/bundle/Configuration.php.twig new file mode 100644 index 000000000..d77aa2b2f --- /dev/null +++ b/Resources/SensioGeneratorBundle/skeleton/bundle/Configuration.php.twig @@ -0,0 +1,37 @@ +root('{{ extension_alias }}'); + + // Here you should define the parameters that are allowed to + // configure your bundle. See the documentation linked above for + // more information on that topic. + + return $treeBuilder; + } +{% endblock class_body %} +} diff --git a/Resources/SensioGeneratorBundle/skeleton/bundle/PlatformUIPluginExtension.php.twig b/Resources/SensioGeneratorBundle/skeleton/bundle/PlatformUIPluginExtension.php.twig new file mode 100644 index 000000000..5d2085b7b --- /dev/null +++ b/Resources/SensioGeneratorBundle/skeleton/bundle/PlatformUIPluginExtension.php.twig @@ -0,0 +1,58 @@ +{% extends 'skeleton/bundle/Extension.php.twig' %} + +{% block use_statements %} +{{ parent() }} +use Symfony\Component\Yaml\Yaml; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; +use Symfony\Component\Config\Resource\FileResource; +{% endblock use_statements %} + +{% block class_definition %} +class {{ bundle_basename }}Extension extends Extension implements PrependExtensionInterface +{% endblock class_definition %} + +{% block class_body %} +{{ parent() }} + /** + * {@inheritdoc} + */ + public function load(array $configs, ContainerBuilder $container) + { + $configuration = new Configuration(); + $config = $this->processConfiguration($configuration, $configs); + } + + public function prepend(ContainerBuilder $container) + { + $container->prependExtensionConfig( + 'assetic', array('bundles' => array('{{ bundle }}')) + ); + + $this->prependYui($container); + $this->prependCss($container); + } + + private function prependYui(ContainerBuilder $container) + { + $container->setParameter( + 'extension_skeleton.js_dir', + 'bundles/{{ extension_alias }}/js' + ); + $yuiConfigFile = __DIR__ . '/../Resources/config/yui.yml'; + $config = Yaml::parse(file_get_contents($yuiConfigFile)); + $container->prependExtensionConfig('ez_platformui', $config); + $container->addResource(new FileResource($yuiConfigFile)); + } + + private function prependCss(ContainerBuilder $container) + { + $container->setParameter( + 'extension_skeleton.css_dir', + 'bundles/{{ extension_alias }}/css' + ); + $cssConfigFile = __DIR__ . '/../Resources/config/css.yml'; + $config = Yaml::parse(file_get_contents($cssConfigFile)); + $container->prependExtensionConfig('ez_platformui', $config); + $container->addResource(new FileResource($cssConfigFile)); + } +{% endblock %} diff --git a/Resources/SensioGeneratorBundle/skeleton/bundle/css.yml.twig b/Resources/SensioGeneratorBundle/skeleton/bundle/css.yml.twig new file mode 100644 index 000000000..8cad4efa8 --- /dev/null +++ b/Resources/SensioGeneratorBundle/skeleton/bundle/css.yml.twig @@ -0,0 +1,4 @@ +system: + default: + css: + files: diff --git a/Resources/SensioGeneratorBundle/skeleton/bundle/yui.yml.twig b/Resources/SensioGeneratorBundle/skeleton/bundle/yui.yml.twig new file mode 100644 index 000000000..21d9cb0ed --- /dev/null +++ b/Resources/SensioGeneratorBundle/skeleton/bundle/yui.yml.twig @@ -0,0 +1,4 @@ +system: + default: + yui: + modules: