Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit b55a41a233b9f357ac689cd3805b9f525238cee5 1 parent b097734
@beberlei authored
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
View
10 Controller/CatchAllRequestListener.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;
View
4 Controller/Helpers/ContextSwitch.php
@@ -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
{
View
4 Controller/Helpers/Helper.php
@@ -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)
View
14 Controller/Helpers/HelperBroker.php
@@ -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);
View
4 Controller/Helpers/Layout.php
@@ -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
{
View
19 Controller/Helpers/Redirector.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\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())
View
10 Controller/Helpers/UrlHelper.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\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);
}
View
4 Controller/Helpers/ViewRenderer.php
@@ -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
{
View
4 Controller/RouteNameParser.php
@@ -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;
View
10 Controller/ZendController.php
@@ -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);
}
View
4 Controller/ZendRequest.php
@@ -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;
View
6 Controller/ZendResponse.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\HttpFoundation\Response;
+use Symfony\Component\Controller\Response;
class ZendResponse
{
View
37 DependencyInjection/Mvc1CompatExtension.php → ...tion/WhitewashingZFMvcCompatExtension.php
@@ -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';
}
}
View
15 README.markdown
@@ -33,20 +33,19 @@ Simplifies moving your Zend 1.x MVC apps to Symfony 2 if you follow the way I in
return array(
//..
- new Whitewashing\Zend\Mvc1CompatBundle\WhitewashingZendMvc1CompatBundle(),
+ new Whitewashing\ZFMvcCompatBundle\WhitewashingZFMvcCompatBundle(),
);
2. Add the Whitewashing namespace to your autolod.php.
3. Register Zend_View as template engine in your config.yml:
- app.config:
- templating:
- engine: ["phtml"]
+ framework:
+ templating: { engines: ["twig", "phtml"] }
4. Enable the Compat Bundle in config.yml:
- zendmvc1.compat:
+ whitewashing_zf_mvc_compat:
default_layout_resource: "MyBundle::layout.html.phtml"
## Usage
@@ -62,7 +61,7 @@ and redirector helper calls. If you do want to use a another bundle name then ma
should become:
namespace Application\BlogBundle\Controller;
- use Whitewashing\Zend\Mvc1CompatBundle\Controller\ZendController;
+ use Whitewashing\ZFMvcCompatBundle\Controller\ZendController;
class PostController extends ZendController
{
@@ -86,7 +85,7 @@ You have to convert all your Zend routes to Symfony routes, place them in a $Bun
them in your app/config/routing.yml. Additionally Symfony has no "catch-all" routes by default, so you have to make use
of the catch all mechanism defined by the compat bundle:
- zendmvc1.compat:
+ whitewashing_zf_mvc_compat:
catchall_bundles: ["BlogBundle"]
When this mechanism is enabled you can request:
@@ -96,7 +95,7 @@ When this mechanism is enabled you can request:
7. Security and ACLs
You probably implemented some kind of authentication, security and acl mechanism using controller plugins, Zend_Acl and
-Zend_Auth. Ditch that code and use the SecurityBundle for this.
+Zend_Auth. You have to use Zend_Acl inside a kernel event, preferably after routing took place to reimplement that logic.
## Semantic differences
View
54 Resources/config/compat.xml
@@ -1,69 +1,69 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<container xmlns="http://www.symfony-project.org/schema/dic/services"
+<?xml version="1.0" ?>
+
+<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd">
+ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
- <parameter key="templating.engine.zend.class">Whitewashing\Zend\Mvc1CompatBundle\View\ZendViewEngine</parameter>
- <parameter key="whitewashing.zend.mvc1compat.default_layout_resource">WhitewashingZendMvc1CompatBundle::layout.html.phtml</parameter>
- <parameter key="whitewashing.zend.mvc1compat.catchall_bundles" type="collection" />
+ <parameter key="templating.engine.zend.class">Whitewashing\ZFMvcCompatBundle\View\ZendViewEngine</parameter>
+ <parameter key="whitewashing.zfmvccompat.default_layout_resource">WhitewashingZFMvcCompatBundle::layout.html.phtml</parameter>
+ <parameter key="whitewashing.zfmvccompat.catchall_bundles" type="collection" />
</parameters>
<services>
- <service id="whitewashing.zend.mvc1compat.core.view.listener" class="Whitewashing\Zend\Mvc1CompatBundle\View\CoreViewListener">
+ <service id="whitewashing.zfmvccompat.kernel_listener.view" class="Whitewashing\ZFMvcCompatBundle\View\CoreViewListener">
<tag name="kernel.listener" event="core.view" method="filterResponse" />
<argument id="templating" type="service" />
- <argument id="kernel" type="service" />
+ <argument id="whitewashing.zfmvccompat.view" type="service" />
</service>
- <service id="whitewashing.zend.mvc1compat.core.request.listener" class="Whitewashing\Zend\Mvc1CompatBundle\Controller\CatchAllRequestListener">
+ <service id="whitewashing.zfmvccompat.kernel_listener.request" class="Whitewashing\ZFMvcCompatBundle\Controller\CatchAllRequestListener">
<tag name="kernel.listener" event="core.request" method="resolve" />
- <argument type="service" id="whitewashing.zend.mvc1compat.nameparser" />
- <argument>%whitewashing.zend.mvc1compat.catchall_bundles%</argument>
+ <argument type="service" id="whitewashing.zfmvccompat.nameparser" />
+ <argument>%whitewashing.zfmvccompat.catchall_bundles%</argument>
</service>
- <service id="whitewashing.zend.mvc1compat.view" class="Whitewashing\Zend\Mvc1CompatBundle\View\View1">
+ <service id="whitewashing.zfmvccompat.view" class="Whitewashing\ZFMvcCompatBundle\View\View1">
<argument type="service" id="service_container" />
- <argument type="service" id="whitewashing.zend.mvc1compat.nameparser" />
+ <argument type="service" id="whitewashing.zfmvccompat.nameparser" />
</service>
<service id="templating.engine.phtml" class="%templating.engine.zend.class%" public="false">
<argument type="service" id="templating.locator" />
<argument type="service" id="service_container" />
<argument type="service" id="templating.name_parser" />
- <argument type="service" id="whitewashing.zend.mvc1compat.view" />
+ <argument type="service" id="whitewashing.zfmvccompat.view" />
</service>
- <service id="whitewashing.zend.mvc1compat.nameparser" class="Whitewashing\Zend\Mvc1CompatBundle\Controller\RouteNameParser">
+ <service id="whitewashing.zfmvccompat.nameparser" class="Whitewashing\ZFMvcCompatBundle\Controller\RouteNameParser">
<argument type="service" id="kernel" />
</service>
- <service id="whitewashing.zend.mvc1compat.controller.request" class="Whitewashing\Zend\Mvc1CompatBundle\Controller\ZendRequest" scope="request">
+ <service id="whitewashing.zfmvccompat.controller.request" class="Whitewashing\ZFMvcCompatBundle\Controller\ZendRequest" scope="request">
<argument type="service" id="request" />
- <argument type="service" id="whitewashing.zend.mvc1compat.nameparser" />
+ <argument type="service" id="whitewashing.zfmvccompat.nameparser" />
</service>
- <service id="whitewashing.zend.mvc1compat.actionhelper.contextswitch" class="Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers\ContextSwitch">
+ <service id="whitewashing.zfmvccompat.actionhelper.contextswitch" class="Whitewashing\ZFMvcCompatBundle\Controller\Helpers\ContextSwitch">
</service>
- <service id="whitewashing.zend.mvc1compat.actionhelper.url" class="Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers\UrlHelper" scope="request">
+ <service id="whitewashing.zfmvccompat.actionhelper.url" class="Whitewashing\ZFMvcCompatBundle\Controller\Helpers\UrlHelper" scope="request">
<argument type="service" id="router" />
- <argument type="service" id="whitewashing.zend.mvc1compat.nameparser" />
+ <argument type="service" id="whitewashing.zfmvccompat.nameparser" />
<argument type="service" id="request" />
</service>
- <service id="whitewashing.zend.mvc1compat.actionhelper.redirector" class="Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers\Redirector" scope="request">
- <argument type="service" id="whitewashing.zend.mvc1compat.actionhelper.url" />
- <argument type="service" id="response" strict="false" />
+ <service id="whitewashing.zfmvccompat.actionhelper.redirector" class="Whitewashing\ZFMvcCompatBundle\Controller\Helpers\Redirector" scope="request">
+ <argument type="service" id="whitewashing.zfmvccompat.actionhelper.url" />
</service>
- <service id="whitewashing.zend.mvc1compat.actionhelper.layout" class="Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers\Layout" scope="request">
- <argument>%whitewashing.zend.mvc1compat.default_layout_resource%</argument>
+ <service id="whitewashing.zfmvccompat.actionhelper.layout" class="Whitewashing\ZFMvcCompatBundle\Controller\Helpers\Layout" scope="request">
+ <argument>%whitewashing.zfmvccompat.default_layout_resource%</argument>
</service>
- <service id="whitewashing.zend.mvc1compat.actionhelper.viewrenderer" class="Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers\ViewRenderer" scope="request">
- <argument>%whitewashing.zend.mvc1compat.default_layout_resource%</argument>
+ <service id="whitewashing.zfmvccompat.actionhelper.viewrenderer" class="Whitewashing\ZFMvcCompatBundle\Controller\Helpers\ViewRenderer" scope="request">
+ <argument>%whitewashing.zfmvccompat.default_layout_resource%</argument>
</service>
</services>
</container>
View
18 WhitewashingZendMvc1CompatBundle.php → ...xamples/Application/ApplicationBundle.php
@@ -1,6 +1,6 @@
<?php
/*
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,19 +11,11 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle;
+namespace Application;
use Symfony\Component\HttpKernel\Bundle\Bundle;
-class WhitewashingZendMvc1CompatBundle extends Bundle
+class ApplicationBundle extends Bundle
{
- public function getNamespace()
- {
- return __NAMESPACE__;
- }
-
- public function getPath()
- {
- return strtr(__DIR__, '\\', '/');
- }
-}
+
+}
View
30 Resources/examples/Application/Controller/GuestbookController.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Application\Controller;
+use Whitewashing\ZFMvcCompatBundle\Controller\ZendController;
+
+class GuestbookController extends ZendController
+{
+ public function indexAction()
+ {
+ $guestbook = new \Application_Model_GuestbookMapper();
+ $this->view->entries = $guestbook->fetchAll();
+ }
+
+ public function signAction()
+ {
+ $request = $this->getRequest();
+ $form = new \Application_Form_Guestbook();
+
+ if ($this->getRequest()->isPost()) {
+ if ($form->isValid($request->getPost())) {
+ $comment = new \Application_Model_Guestbook($form->getValues());
+ $mapper = new \Application_Model_GuestbookMapper();
+ $mapper->save($comment);
+ return $this->_helper->redirector('index');
+ }
+ }
+
+ $this->view->form = $form;
+ }
+}
View
50 Resources/examples/Application/Form/Guestbook.php
@@ -0,0 +1,50 @@
+<?php
+class Application_Form_Guestbook extends Zend_Form
+{
+ public function init()
+ {
+ // Set the method for the display form to POST
+ $this->setMethod('post');
+
+ // Add an email element
+ $this->addElement('text', 'email', array(
+ 'label' => 'Your email address:',
+ 'required' => true,
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ 'EmailAddress',
+ )
+ ));
+
+ // Add the comment element
+ $this->addElement('textarea', 'comment', array(
+ 'label' => 'Please Comment:',
+ 'required' => true,
+ 'validators' => array(
+ array('validator' => 'StringLength', 'options' => array(0, 20))
+ )
+ ));
+
+ // Add a captcha
+ $this->addElement('captcha', 'captcha', array(
+ 'label' => 'Please enter the 5 letters displayed below:',
+ 'required' => true,
+ 'captcha' => array(
+ 'captcha' => 'Figlet',
+ 'wordLen' => 5,
+ 'timeout' => 300
+ )
+ ));
+
+ // Add the submit button
+ $this->addElement('submit', 'submit', array(
+ 'ignore' => true,
+ 'label' => 'Sign Guestbook',
+ ));
+
+ // And finally add some CSRF protection
+ $this->addElement('hash', 'csrf', array(
+ 'ignore' => true,
+ ));
+ }
+}
View
6 Resources/examples/Application/Model/DbTable/Guestbook.php
@@ -0,0 +1,6 @@
+<?php
+class Application_Model_DbTable_Guestbook extends Zend_Db_Table_Abstract
+{
+ /** Table name */
+ protected $_name = 'guestbook';
+}
View
89 Resources/examples/Application/Model/Guestbook.php
@@ -0,0 +1,89 @@
+<?php
+class Application_Model_Guestbook
+{
+ protected $_comment;
+ protected $_created;
+ protected $_email;
+ protected $_id;
+
+ public function __construct(array $options = null)
+ {
+ if (is_array($options)) {
+ $this->setOptions($options);
+ }
+ }
+
+ public function __set($name, $value)
+ {
+ $method = 'set' . $name;
+ if (('mapper' == $name) || !method_exists($this, $method)) {
+ throw new Exception('Invalid guestbook property');
+ }
+ $this->$method($value);
+ }
+
+ public function __get($name)
+ {
+ $method = 'get' . $name;
+ if (('mapper' == $name) || !method_exists($this, $method)) {
+ throw new Exception('Invalid guestbook property');
+ }
+ return $this->$method();
+ }
+
+ public function setOptions(array $options)
+ {
+ $methods = get_class_methods($this);
+ foreach ($options as $key => $value) {
+ $method = 'set' . ucfirst($key);
+ if (in_array($method, $methods)) {
+ $this->$method($value);
+ }
+ }
+ return $this;
+ }
+
+ public function setComment($text)
+ {
+ $this->_comment = (string) $text;
+ return $this;
+ }
+
+ public function getComment()
+ {
+ return $this->_comment;
+ }
+
+ public function setEmail($email)
+ {
+ $this->_email = (string) $email;
+ return $this;
+ }
+
+ public function getEmail()
+ {
+ return $this->_email;
+ }
+
+ public function setCreated($ts)
+ {
+ $this->_created = $ts;
+ return $this;
+ }
+
+ public function getCreated()
+ {
+ return $this->_created;
+ }
+
+ public function setId($id)
+ {
+ $this->_id = (int) $id;
+ return $this;
+ }
+
+ public function getId()
+ {
+ return $this->_id;
+ }
+}
View
69 Resources/examples/Application/Model/GuestbookMapper.php
@@ -0,0 +1,69 @@
+<?php
+class Application_Model_GuestbookMapper
+{
+ protected $_dbTable;
+
+ public function setDbTable($dbTable)
+ {
+ if (is_string($dbTable)) {
+ $dbTable = new $dbTable();
+ }
+ if (!$dbTable instanceof Zend_Db_Table_Abstract) {
+ throw new Exception('Invalid table data gateway provided');
+ }
+ $this->_dbTable = $dbTable;
+ return $this;
+ }
+
+ public function getDbTable()
+ {
+ if (null === $this->_dbTable) {
+ $this->setDbTable('Application_Model_DbTable_Guestbook');
+ }
+ return $this->_dbTable;
+ }
+
+ public function save(Application_Model_Guestbook $guestbook)
+ {
+ $data = array(
+ 'email' => $guestbook->getEmail(),
+ 'comment' => $guestbook->getComment(),
+ 'created' => date('Y-m-d H:i:s'),
+ );
+
+ if (null === ($id = $guestbook->getId())) {
+ unset($data['id']);
+ $this->getDbTable()->insert($data);
+ } else {
+ $this->getDbTable()->update($data, array('id = ?' => $id));
+ }
+ }
+
+ public function find($id, Application_Model_Guestbook $guestbook)
+ {
+ $result = $this->getDbTable()->find($id);
+ if (0 == count($result)) {
+ return;
+ }
+ $row = $result->current();
+ $guestbook->setId($row->id)
+ ->setEmail($row->email)
+ ->setComment($row->comment)
+ ->setCreated($row->created);
+ }
+
+ public function fetchAll()
+ {
+ $resultSet = $this->getDbTable()->fetchAll();
+ $entries = array();
+ foreach ($resultSet as $row) {
+ $entry = new Application_Model_Guestbook();
+ $entry->setId($row->id)
+ ->setEmail($row->email)
+ ->setComment($row->comment)
+ ->setCreated($row->created);
+ $entries[] = $entry;
+ }
+ return $entries;
+ }
+}
View
7 Resources/examples/Application/Resources/config/routing.yml
@@ -0,0 +1,7 @@
+zfmvccompat_guestbook_homepage:
+ pattern: /zfguestbook
+ defaults: { _controller: "ApplicationBundle:Guestbook:index" }
+
+zfmvccompat_guestbook_sign:
+ pattern: /zfguestbook/sign
+ defaults: { _controller: "ApplicationBundle:Guestbook:sign" }
View
12 Resources/examples/Application/Resources/views/Guestbook/index.html.phtml
@@ -0,0 +1,12 @@
+<p><a href="<?php echo $this->url(
+ array(),
+ 'zfmvccompat_guestbook_sign',
+ true) ?>">Sign Our Guestbook</a></p>
+
+Guestbook Entries: <br />
+<dl>
+ <?php foreach ($this->entries as $entry): ?>
+ <dt><?php echo $this->escape($entry->email) ?></dt>
+ <dd><?php echo $this->escape($entry->comment) ?></dd>
+ <?php endforeach ?>
+</dl>
View
5 Resources/examples/Application/Resources/views/Guestbook/sign.html.phtml
@@ -0,0 +1,5 @@
+Please use the form below to sign our guestbook!
+
+<?php
+$this->form->setAction($this->url());
+echo $this->form->__toSTring();
View
23 Resources/examples/Application/Resources/views/layout.html.phtml
@@ -0,0 +1,23 @@
+<?php echo $this->doctype() ?>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Zend Framework Quickstart Application</title>
+</head>
+<body>
+<div id="header" style="background-color: #EEEEEE; height: 30px;">
+ <div id="header-logo" style="float: left">
+ <b>ZF Quickstart Application</b>
+ </div>
+ <div id="header-navigation" style="float: right">
+ <a href="<?php echo $this->url(
+ array('controller'=>'guestbook'),
+ 'zfmvccompat_guestbook_homepage',
+ true) ?>">Guestbook</a>
+ </div>
+</div>
+
+<?php echo $this->content ?>
+
+</body>
+</html>
View
4 Tests/Controller/RouteNameParserTest.php
@@ -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\Tests\Controller;
+namespace Whitewashing\ZFMvcCompatBundle\Tests\Controller;
use Whitewashing\Zend\Mvc1CompatBundle\Controller\RouteNameParser;
View
2  Tests/TestInit.php
@@ -27,7 +27,7 @@
"../View/ParameterBag.php",
"../View/View1.php",
"../View/ZendViewEngine.php",
- "../WhitewashingZendMvc1CompatBundle.php",
+ "../WhitewashingZFMvcCompatBundle.php",
"../DependencyInjection/Mvc1CompatExtension.php",
"../Controller/ZendController.php",
"../Controller/ZendRequest.php",
View
2  Tests/View/ZendViewEngineTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Whitewashing\Zend\Mvc1CompatBundle\Tests\View;
+namespace Whitewashing\ZFMvcCompatBundle\Tests\View;
use Whitewashing\Zend\Mvc1CompatBundle\View\ZendViewEngine;
View
40 View/CoreViewListener.php
@@ -1,6 +1,6 @@
<?php
/**
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -11,11 +11,13 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\View;
+namespace Whitewashing\ZFMvcCompatBundle\View;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpKernel\KernelInterface;
-use Whitewashing\Zend\Mvc1CompatBundle\Controller\ZendController;
+use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
+use Symfony\Component\HttpFoundation\Response;
+use Whitewashing\ZFMvcCompatBundle\Controller\ZendController;
class CoreViewListener
{
@@ -25,30 +27,32 @@ class CoreViewListener
private $templating;
/**
- * @var Symfony\Component\HttpKernel\KernelInterface
+ *
+ * @var Whitewashing\ZFMvcCompatBundle\View\View1
*/
- private $kernel;
+ private $zendView;
- public function __construct($templating, KernelInterface $kernel)
+ public function __construct($templating, $zendView)
{
$this->templating = $templating;
- $this->kernel = $kernel;
+ $this->zendView = $zendView;
}
- public function filterResponse(Event $event, $response)
+ public function filterResponse(GetResponseForControllerResultEvent $event)
{
/* @var $request \Symfony\Component\HttpFoundation\Request */
- $request = $event->get('request');
- if ($request->attributes->has('zend_compat_controller') && !$response) {
+ $request = $event->getRequest();
+
+
+ if ($request->attributes->has('zend_compat_controller') && !$event->hasResponse()) {
/* @var $zendController ZendController */
$zendController = $request->attributes->get('zend_compat_controller');
$zendController->postDispatch();
-
/* @var $zendRequest ZendRequest */
$zendRequest = $zendController->getRequest();
/* @var $response Symfony\Component\HttpFoundation\Response */
- $response = $this->kernel->getContainer()->get('response');
+ $response = new Response();
/* @var $zendResponse ZendResponse */
$zendResponse = $zendController->getResponse();
@@ -63,14 +67,22 @@ public function filterResponse(Event $event, $response)
$zendRequest->getActionName(),
"html", "phtml"
);
- $content = $this->templating->render($viewName, $zendController->view->allVars());
+
+ $vars = $zendController->view->allVars();
+ foreach ($vars AS $k => $v) {
+ if ($v instanceof \Zend_Form) {
+ $v->setView($this->zendView);
+ }
+ }
+
+ $content = $this->templating->render($viewName, $vars);
if ($zendController->getHelper('layout')->isEnabled()) {
$content = $this->templating->render($zendController->getHelper('layout')->getLayout(), array('content' => $content));
}
$response->setContent($content);
}
+ $event->setResponse($response);
}
- return $response;
}
}
View
4 View/ParameterBag.php
@@ -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\View;
+namespace Whitewashing\ZFMvcCompatBundle\View;
class ParameterBag
{
View
6 View/View1.php
@@ -11,10 +11,10 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\View;
+namespace Whitewashing\ZFMvcCompatBundle\View;
use Symfony\Component\DependencyInjection\ContainerInterface;
-use Whitewashing\Zend\Mvc1CompatBundle\Controller\RouteNameParser;
+use Whitewashing\ZFMvcCompatBundle\Controller\RouteNameParser;
class View1 extends \Zend_View
{
@@ -58,6 +58,6 @@ public function partialLoop($resource, array $models = array())
public function url(array $urlOptions = array(), $name = null, $absolute = false)
{
- return $this->container->get('whitewashing.zend.mvc1compat.actionhelper.url')->url($urlOptions, $name, $absolute);
+ return $this->container->get('whitewashing.zfmvccompat.actionhelper.url')->url($urlOptions, $name, $absolute);
}
}
View
10 View/ZendViewEngine.php
@@ -1,7 +1,7 @@
<?php
/**
- * Whitewashing ZendMvc1CompatBundle
+ * Whitewashing ZFMvcCompatBundle
*
* LICENSE
*
@@ -12,10 +12,10 @@
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
-namespace Whitewashing\Zend\Mvc1CompatBundle\View;
+namespace Whitewashing\ZFMvcCompatBundle\View;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
-use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocatorInterface;
+use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
@@ -65,7 +65,7 @@ class ZendViewEngine implements EngineInterface
* @param TemplateNameParserInterface $parser
* @param Zend_View_Interface $zendView
*/
- public function __construct(TemplateLocatorInterface $locator, ContainerInterface $container, TemplateNameParserInterface $parser, $zendView)
+ public function __construct(FileLocatorInterface $locator, ContainerInterface $container, TemplateNameParserInterface $parser, $zendView)
{
$this->locator = $locator;
$this->container = $container;
@@ -116,7 +116,7 @@ public function renderResponse($view, array $parameters = array(), Response $res
public function supports($name)
{
$template = $this->parser->parse($name);
- return 'phtml' === $template['engine'];
+ return $template && 'phtml' === $template->get('engine');
}
protected function findTemplate($name)
View
34 WhitewashingZFMvcCompatBundle.php
@@ -0,0 +1,34 @@
+<?php
+/*
+ * Whitewashing ZFMvcCompatBundle
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to kontakt@beberlei.de so I can send you a copy immediately.
+ */
+
+namespace Whitewashing\ZFMvcCompatBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+class WhitewashingZFMvcCompatBundle extends Bundle
+{
+ public function boot()
+ {
+ if ($this->container->has('whitewashing.zfmvcompat.db')) {
+ \Zend_Db_Table::setDefaultAdapter($this->container->get('whitewashing.zfmvcompat.db'));
+ }
+
+ $refl = new \ReflectionClass('Zend_Session');
+ $vars = array('_sessionStarted', '_readable', '_writable');
+ foreach ($vars AS $var) {
+ $property = $refl->getProperty($var);
+ $property->setAccessible(true);
+ $property->setValue(null, true);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.