Permalink
Browse files

Initial commit: web interface for bundle generator

  • Loading branch information...
RapotOR committed Jun 28, 2011
0 parents commit fe822184ec1105e675eff20367bb333a95f9f000
@@ -0,0 +1,58 @@
+<?php
+
+namespace Sf2gen\Bundle\GeneratorBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+
+//annotations
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+
+use Sensio\Bundle\GeneratorBundle\Generator\BundleGenerator;
+use Sensio\Bundle\GeneratorBundle\Command\Validators;
+
+use Sf2gen\Bundle\GeneratorBundle\Form\GenerateBundleType;
+use Sf2gen\Bundle\GeneratorBundle\Entity\Bundle;
+
+/**
+ * Controller for bundle generating
+ *
+ * @author Cédric Lahouste <cedric.lahouste@gmail.com>
+ */
+class BundleController extends Controller
+{
+ /**
+ * @Route("/bundle", name="_generator_bundle")
+ * @Template()
+ */
+ public function generateAction()
+ {
+ $request = $this->get('request');
+ $bundle = new Bundle();
+
+ $form = $this->get('form.factory')->create(new GenerateBundleType(), $bundle);
+
+ if ('POST' == $request->getMethod()) {
+ $form->bindRequest($request);
+
+ if ($form->isValid()) {
+ $namespace = $bundle->namespace_vendor . "\\" . $bundle->namespace_bundle;
+ $dir = '/' === substr($bundle->dir, -1, 1) ? $bundle->dir : $bundle->dir.'/';
+ if (!$this->get('filesystem')->isAbsolutePath($dir)) {
+ $dir = dirname($this->get('kernel')->getRootDir()).'/'.$dir;
+ }
+
+ $generator = new BundleGenerator($this->get('filesystem'), $this->get('kernel')->locateResource('@SensioGeneratorBundle/Resources/skeleton/bundle'));
+ $generator->generate($namespace, $bundle->bundle_name, $dir, $bundle->format, $bundle->structure);
+
+ $request->getSession()->setFlash('notice','Your bundle has been generated.');
+ return new RedirectResponse($this->generateUrl('_generator'));
+ }
+ }
+
+ return array(
+ 'form' => $form->createView()
+ );
+ }
+}
@@ -0,0 +1,29 @@
+<?php
+
+namespace Sf2gen\Bundle\GeneratorBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+
+//annotations
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+
+/**
+ * Main controller containing the menu
+ *
+ * @author Cédric Lahouste <cedric.lahouste@gmail.com>
+ */
+class MainController extends Controller
+{
+ /**
+ * @Route("/", name="_generator")
+ * @Template()
+ */
+ public function indexAction()
+ {
+ return array(
+ 'message' => $this->get('request')->getSession()->getFlash('notice')
+ );
+ }
+}
@@ -0,0 +1,68 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sf2gen\Bundle\GeneratorBundle\Entity;
+
+use Symfony\Component\Validator\Constraints as Assert;
+
+/**
+ * Bundle entity
+ *
+ * @author Cédric Lahouste <cedric.lahouste@gmail.com>
+ */
+class Bundle
+{
+ /**
+ * @Assert\NotBlank
+ */
+ public $namespace_vendor;
+
+ /**
+ * @Assert\NotBlank
+ */
+ public $namespace_bundle;
+
+ /**
+ * @Assert\NotBlank
+ */
+ public $bundle_name;
+
+ /**
+ * @Assert\NotBlank
+ */
+ public $dir;
+
+ /**
+ * @Assert\Choice(callback="getConfigurationFormats")
+ */
+ public $format;
+
+ public $structure;
+
+ public function __construct()
+ {
+ $this->dir = 'src';
+ $this->format = 'annotation';
+ }
+
+ /**
+ * @return array
+ */
+ static public function getConfigurationFormats()
+ {
+ return array(
+ 'xml' => 'xml',
+ 'yml' => 'yml',
+ 'php' => 'php',
+ 'annotation' => 'annotation'
+ );
+ }
+}
@@ -0,0 +1,37 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sf2gen\Bundle\GeneratorBundle\Form;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormBuilder;
+
+use Sf2gen\Bundle\GeneratorBundle\Entity\Bundle;
+
+/**
+ * Form for Bundle generating
+ *
+ * @author Cédric Lahouste <cedric.lahouste@gmail.com>
+ */
+class GenerateBundleType extends AbstractType
+{
+ public function buildForm(FormBuilder $builder, array $options)
+ {
+ $builder
+ ->add('namespace_vendor', 'text')
+ ->add('namespace_bundle', 'text')
+ ->add('bundle_name', 'text')
+ ->add('dir', 'text')
+ ->add('format', 'choice', array('choices' => Bundle::getConfigurationFormats()))
+ ->add('structure', 'checkbox')
+ ;
+ }
+}
@@ -0,0 +1,6 @@
+_generator:
+ resource: "@Sf2genGeneratorBundle/Controller/MainController.php"
+ type: annotation
+_generator_bundle:
+ resource: "@Sf2genGeneratorBundle/Controller/BundleController.php"
+ type: annotation
Oops, something went wrong.

0 comments on commit fe82218

Please sign in to comment.