Permalink
Browse files

simplified controllers

  • Loading branch information...
1 parent 85901aa commit 2f989edc3e1c43b31c5fa51e8050becd1581dc0c @bamarni bamarni committed Jul 10, 2012
@@ -11,25 +11,19 @@
namespace Genemu\Bundle\FormBundle\Controller;
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Response;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
-
/**
* Class Base64Controller
*
* @author Olivier Chauvel <olivier@generation-multiple.com>
*/
-class Base64Controller extends Controller
+class Base64Controller extends ContainerAware
{
- /**
- * @Route("/genemu_base64", name="genemu_base64")
- */
- public function base64Action(Request $request)
+ public function base64Action()
{
- $query = $request->server->get('QUERY_STRING');
+ $query = $this->container->get('request')->server->get('QUERY_STRING');
$datas = preg_split('([;,]{1})', $query);
return new Response(base64_decode($datas[2]), 200, array('Content-Type' => $datas[0]));
@@ -11,26 +11,21 @@
namespace Genemu\Bundle\FormBundle\Controller;
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Response;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
-
use Genemu\Bundle\FormBundle\Gd\File\Image;
/**
* Class ImageController
*
* @author Olivier Chauvel <olivier@generation-multiple.com>
*/
-class ImageController extends Controller
+class ImageController extends ContainerAware
{
- /**
- * @Route("/genemu_change_image", name="genemu_form_image")
- */
- public function changeAction(Request $request)
+ public function changeAction()
{
+ $request = $this->container->get('request');
$rootDir = rtrim($this->container->getParameter('genemu.form.file.root_dir'), '/\\') . DIRECTORY_SEPARATOR;
$folder = rtrim($this->container->getParameter('genemu.form.file.folder'), '/\\') . DIRECTORY_SEPARATOR;
@@ -11,27 +11,21 @@
namespace Genemu\Bundle\FormBundle\Controller;
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Response;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
-
use Genemu\Bundle\FormBundle\Gd\File\Image;
/**
* Upload Controller
*
* @author Olivier Chauvel <olivier@generation-multiple.com>
*/
-class UploadController extends Controller
+class UploadController extends ContainerAware
{
- /**
- * @Route("/genemu_upload", name="genemu_upload")
- */
- public function uploadAction(Request $request)
+ public function uploadAction()
{
- $handle = $request->files->get('Filedata');
+ $handle = $this->container->get('request')->files->get('Filedata');
$folder = $this->container->getParameter('genemu.form.file.folder');
$uploadDir = $this->container->getParameter('genemu.form.file.upload_dir');
File renamed without changes.
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<routes xmlns="http://symfony.com/schema/routing"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
+
+ <route id="genemu_base64" pattern="/genemu_base64">
+ <default key="_controller">GenemuFormBundle:Base64:base64</default>
+ </route>
+
+</routes>
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<routes xmlns="http://symfony.com/schema/routing"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
+
+ <route id="genemu_form_image" pattern="/genemu_change_image">
+ <default key="_controller">GenemuFormBundle:Image:change</default>
+ </route>
+
+</routes>
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<routes xmlns="http://symfony.com/schema/routing"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
+
+ <route id="genemu_upload" pattern="/genemu_upload">
+ <default key="_controller">GenemuFormBundle:Upload:upload</default>
+ </route>
+
+</routes>
@@ -17,8 +17,7 @@ genemu_form:
``` yml
# app/config/routing.yml
genemu_base64:
- resource: "@GenemuFormBundle/Controller/Base64Controller.php"
- type: annotation
+ resource: "@GenemuFormBundle/Resources/config/routing/base64.xml"
```
* also your captcha should be small, because IE supports only 2083 characters in requests (otherwise they are just skipped).
@@ -15,8 +15,7 @@ genemu_form:
``` yml
genemu_upload:
- resource: "@GenemuFormBundle/Controller/UploadController.php"
- type: annotation
+ resource: "@GenemuFormBundle/Resources/config/routing/upload.xml"
```
## Default Usage:
@@ -14,8 +14,7 @@ genemu_form:
``` yml
genemu_image:
- resource: "@GenemuFormBundle/Controller/ImageController.php"
- type: annotation
+ resource: "@GenemuFormBundle/Resources/config/routing/image.xml"
```
## Default Usage:
View
@@ -1,21 +0,0 @@
-UPGRADE 2.1
-=========
-
-### JQuery Chosen
-
- Widget option cannot specify the choice type anymore, you have to append the widget in the type name instead :
-
- Before:
-
- ```
- $formBuilder
- ->add('country', 'genemu_jquerychosen', array(
- 'widget' => 'country',
- ));
- ```
-
- After:
-
- ```
- $formBuilder->add('country', 'genemu_jquerychosen_country');
- ```
View
@@ -0,0 +1,36 @@
+UPGRADE to Symfony 2.1
+======================
+
+### JQuery Chosen
+
+ [BC BREAK] Widget option cannot specify the choice type anymore, you have to append the widget in the type name instead :
+
+ Before :
+``` php
+ $formBuilder
+ ->add('country', 'genemu_jquerychosen', array(
+ 'widget' => 'country',
+ ));
+```
+ Now :
+``` php
+ $formBuilder->add('country', 'genemu_jquerychosen_country');
+```
+
+### Routing
+
+ [BC BREAK] Routing is defined in xml files instead of annotations (to remove the depency with SensioFrameworkExtraBundle)
+
+ Before :
+ ``` yml
+# app/config/routing.yml
+ genemu_base64:
+ resource: "@GenemuFormBundle/Controller/Base64Controller.php"
+ type: annotation
+ ```
+ Now :
+ ``` yml
+# app/config/routing.yml
+ genemu_base64:
+ resource: "@GenemuFormBundle/Resources/config/routing/base64.xml"
+ ```

0 comments on commit 2f989ed

Please sign in to comment.