Permalink
Browse files

Update to current Symfony code, add example from ZF Guestbook Tutorial

  • Loading branch information...
beberlei committed Jul 8, 2011
1 parent b097734 commit b55a41a233b9f357ac689cd3805b9f525238cee5
Showing with 470 additions and 140 deletions.
  1. +5 −5 Controller/CatchAllRequestListener.php
  2. +2 −2 Controller/Helpers/ContextSwitch.php
  3. +2 −2 Controller/Helpers/Helper.php
  4. +7 −7 Controller/Helpers/HelperBroker.php
  5. +2 −2 Controller/Helpers/Layout.php
  6. +9 −10 Controller/Helpers/Redirector.php
  7. +7 −3 Controller/Helpers/UrlHelper.php
  8. +2 −2 Controller/Helpers/ViewRenderer.php
  9. +2 −2 Controller/RouteNameParser.php
  10. +5 −5 Controller/ZendController.php
  11. +2 −2 Controller/ZendRequest.php
  12. +3 −3 Controller/ZendResponse.php
  13. +18 −19 DependencyInjection/{Mvc1CompatExtension.php → WhitewashingZFMvcCompatExtension.php}
  14. +7 −8 README.markdown
  15. +27 −27 Resources/config/compat.xml
  16. +5 −13 WhitewashingZendMvc1CompatBundle.php → Resources/examples/Application/ApplicationBundle.php
  17. +30 −0 Resources/examples/Application/Controller/GuestbookController.php
  18. +50 −0 Resources/examples/Application/Form/Guestbook.php
  19. +6 −0 Resources/examples/Application/Model/DbTable/Guestbook.php
  20. +89 −0 Resources/examples/Application/Model/Guestbook.php
  21. +69 −0 Resources/examples/Application/Model/GuestbookMapper.php
  22. +7 −0 Resources/examples/Application/Resources/config/routing.yml
  23. +12 −0 Resources/examples/Application/Resources/views/Guestbook/index.html.phtml
  24. +5 −0 Resources/examples/Application/Resources/views/Guestbook/sign.html.phtml
  25. +23 −0 Resources/examples/Application/Resources/views/layout.html.phtml
  26. +2 −2 Tests/Controller/RouteNameParserTest.php
  27. +1 −1 Tests/TestInit.php
  28. +1 −1 Tests/View/ZendViewEngineTest.php
  29. +26 −14 View/CoreViewListener.php
  30. +2 −2 View/ParameterBag.php
  31. +3 −3 View/View1.php
  32. +5 −5 View/ZendViewEngine.php
  33. +34 −0 WhitewashingZFMvcCompatBundle.php
@@ -1,6 +1,6 @@
<?php
/*
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,9 +11,9 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller;
+namespace Whitewashing\ZFMvcCompatBundle\Controller;
-use Symfony\Component\EventDispatcher\Event;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class CatchAllRequestListener
{
@@ -30,9 +30,9 @@ public function __construct(RouteNameParser $parser, $enabledBundles)
$this->enabledBundles = $enabledBundles;
}
- public function resolve(Event $event)
+ public function resolve(GetResponseEvent $event)
{
- $request = $event->get('request');
+ $request = $event->getRequest();
if ($request->attributes->has('_controller')) {
return;
@@ -1,6 +1,6 @@
<?php
/*
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,7 +11,7 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers;
+namespace Whitewashing\ZFMvcCompatBundle\Controller\Helpers;
class ContextSwitch extends Helper
{
@@ -1,8 +1,8 @@
<?php
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers;
+namespace Whitewashing\ZFMvcCompatBundle\Controller\Helpers;
-use Whitewashing\Zend\Mvc1CompatBundle\Controller\ZendController;
+use Whitewashing\ZFMvcCompatBundle\Controller\ZendController;
/**
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
@@ -11,10 +11,10 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers;
+namespace Whitewashing\ZFMvcCompatBundle\Controller\Helpers;
use Symfony\Component\DependencyInjection\Container;
-use Whitewashing\Zend\Mvc1CompatBundle\Controller\ZendController;
+use Whitewashing\ZFMvcCompatBundle\Controller\ZendController;
class HelperBroker
{
@@ -25,11 +25,11 @@ public function __construct(Container $container, ZendController $controller)
// TODO: Convert to using tags!
// TODO: Remember helpers should be scope=request
$helpers = array(
- 'whitewashing.zend.mvc1compat.actionhelper.redirector',
- 'whitewashing.zend.mvc1compat.actionhelper.url',
- 'whitewashing.zend.mvc1compat.actionhelper.contextswitch',
- 'whitewashing.zend.mvc1compat.actionhelper.layout',
- 'whitewashing.zend.mvc1compat.actionhelper.viewrenderer',
+ 'whitewashing.zfmvccompat.actionhelper.redirector',
+ 'whitewashing.zfmvccompat.actionhelper.url',
+ 'whitewashing.zfmvccompat.actionhelper.contextswitch',
+ 'whitewashing.zfmvccompat.actionhelper.layout',
+ 'whitewashing.zfmvccompat.actionhelper.viewrenderer',
);
foreach ($helpers AS $helper) {
$helper = $container->get($helper);
@@ -1,6 +1,6 @@
<?php
/*
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,7 +11,7 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers;
+namespace Whitewashing\ZFMvcCompatBundle\Controller\Helpers;
class Layout extends Helper
{
@@ -1,6 +1,6 @@
<?php
/*
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,9 +11,9 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers;
+namespace Whitewashing\ZFMvcCompatBundle\Controller\Helpers;
-use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\RedirectResponse;
class Redirector extends Helper
{
@@ -32,10 +32,9 @@ class Redirector extends Helper
*/
protected $response;
- public function __construct(UrlHelper $urlHelper, Response $response)
+ public function __construct(UrlHelper $urlHelper)
{
$this->urlHelper = $urlHelper;
- $this->response = $response;
}
public function getName()
@@ -67,20 +66,20 @@ public function setUseAbsoluteUri($flag = true)
public function setGotoSimple($action, $controller = null, $module = null, array $params = array())
{
- $this->response->setRedirect($this->urlHelper->direct($action, $controller, $module, $params));
+ $this->response = new RedirectResponse($this->urlHelper->direct($action, $controller, $module, $params));
}
public function setGotoRoute(array $urlOptions = array(), $name = null, $absolute = true)
{
- $this->response->setRedirect($this->urlHelper->url($urlOptions, $name, $absolute || $this->useAbsoluteUri));
+ $this->response = new RedirectResponse($this->urlHelper->url($urlOptions, $name, $absolute || $this->useAbsoluteUri));
}
public function setGotoUrl($url, array $options = array())
{
- if (isset($options['code'])) {
- $this->response->setStatusCode($options['code']);
+ if (!isset($options['code'])) {
+ $options['code'] = null;
}
- $this->response->setRedirect($url);
+ $this->response = new RedirectResponse($url, $options['code']);
}
public function gotoSimple($action, $controller = null, $module = null, array $params = array())
@@ -1,6 +1,6 @@
<?php
/**
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,9 +11,9 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers;
+namespace Whitewashing\ZFMvcCompatBundle\Controller\Helpers;
-use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Controller\Request;
use Symfony\Component\Routing\RouterInterface;
class UrlHelper extends Helper
@@ -77,6 +77,10 @@ public function simple($action, $controller = null, $module = null, array $param
public function url($urlOptions = array(), $name = null, $absolute = false)
{
+ if ($name === null) {
+ $name = $this->request->get('_route');
+ }
+
return $this->router->generate($name, $urlOptions, $absolute);
}
@@ -1,6 +1,6 @@
<?php
/*
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,7 +11,7 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers;
+namespace Whitewashing\ZFMvcCompatBundle\Controller\Helpers;
class ViewRenderer extends Helper
{
@@ -1,6 +1,6 @@
<?php
/*
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,7 +11,7 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller;
+namespace Whitewashing\ZFMvcCompatBundle\Controller;
use Symfony\Component\HttpKernel\KernelInterface;
@@ -11,12 +11,12 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller;
+namespace Whitewashing\ZFMvcCompatBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
-use Whitewashing\Zend\Mvc1CompatBundle\View\ParameterBag;
-use Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers\HelperBroker;
+use Whitewashing\ZFMvcCompatBundle\View\ParameterBag;
+use Whitewashing\ZFMvcCompatBundle\Controller\Helpers\HelperBroker;
abstract class ZendController implements ContainerAwareInterface
{
@@ -46,7 +46,7 @@ public function setContainer(ContainerInterface $container = null)
$this->container = $container;
$this->request = $container->get('request');
$this->request->attributes->set('zend_compat_controller', $this);
- $this->_request = $this->container->get('whitewashing.zend.mvc1compat.controller.request');
+ $this->_request = $this->container->get('whitewashing.zfmvccompat.controller.request');
$this->_response = new ZendResponse();
$this->view = new ParameterBag();
$this->_helper = new HelperBroker($this->container, $this);
@@ -147,7 +147,7 @@ public function getResponse()
$module = $this->_request->getModuleName();
}
- $nameParser = $this->container->get('whitewashing.zend.mvc1compat.nameparser');
+ $nameParser = $this->container->get('whitewashing.zfmvccompat.nameparser');
$controller = $nameParser->formatModule($module)."Bundle:".$nameParser->formatController($controller).":".$action;
return $this->container->get('http_kernel')->forward($controller, array(), $params);
}
@@ -1,6 +1,6 @@
<?php
/**
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,7 +11,7 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller;
+namespace Whitewashing\ZFMvcCompatBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
@@ -1,6 +1,6 @@
<?php
/**
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,9 +11,9 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\Controller;
+namespace Whitewashing\ZFMvcCompatBundle\Controller;
-use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Controller\Response;
class ZendResponse
{
@@ -1,7 +1,7 @@
<?php
/**
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -12,50 +12,49 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\DependencyInjection;
+namespace Whitewashing\ZFMvcCompatBundle\DependencyInjection;
-use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Resource\FileResource;
+use Symfony\Component\HttpKernel\DependencyInjection\Extension;
+use Symfony\Component\Config\FileLocator;
-class Mvc1CompatExtension extends Extension
+class WhitewashingZFMvcCompatExtension extends Extension
{
- public function compatLoad(array $configs, ContainerBuilder $container)
+ public function load(array $configs, ContainerBuilder $container)
{
- $loader = new XmlFileLoader($container, __DIR__.'/../Resources/config');
+ $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('compat.xml');
foreach ($configs AS $config) {
if (isset($config['default_layout_resource'])) {
$container->setParameter(
- 'whitewashing.zend.mvc1compat.default_layout_resource',
+ 'whitewashing.zfmvccompat.default_layout_resource',
$config['default_layout_resource']
);
}
if (isset($config['catchall_bundles'])) {
$container->setParameter(
- 'whitewashing.zend.mvc1compat.catchall_bundles',
+ 'whitewashing.zfmvccompat.catchall_bundles',
$config['catchall_bundles']
);
}
+ if (isset($config['db_conn'])) {
+ $def = new Definition('Zend_Db_Adapter_Abstract');
+ $def->setFactoryClass('Zend_Db');
+ $def->setFactoryMethod('factory');
+ $def->setArguments(array($config['db_conn']['adapter'], $config['db_conn']['params']));
+
+ $container->setDefinition('whitewashing.zfmvcompat.db', $def);
+ }
}
}
public function getAlias()
{
- return 'zendmvc1';
- }
-
- public function getNamespace()
- {
- return 'http://www.whitewashing.de/symfony/schema/zend/mvc1compat.xsd';
- }
-
- public function getXsdValidationBasePath()
- {
- return false;
+ return 'whitewashing_zf_mvc_compat';
}
}
Oops, something went wrong.

0 comments on commit b55a41a

Please sign in to comment.