-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial prototype of Zend Compat Bundle
- Loading branch information
0 parents
commit f12a13d
Showing
10 changed files
with
883 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace Whitewashing\Zend\Mvc1CompatBundle\Controller\Helpers; | ||
|
||
use Whitewashing\Zend\Mvc1CompatBundle\Controller\ZendController; | ||
|
||
/** | ||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
abstract class Helper | ||
{ | ||
/** | ||
* $_actionController | ||
* | ||
* @var Zend_Controller_Action $_actionController | ||
*/ | ||
protected $_actionController = null; | ||
|
||
/** | ||
* setActionController() | ||
* | ||
* @param ZendController $actionController | ||
* @return Helper | ||
*/ | ||
public function setActionController(ZendController $actionController = null) | ||
{ | ||
$this->_actionController = $actionController; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Retrieve current action controller | ||
* | ||
* @return Zend_Controller_Action | ||
*/ | ||
public function getActionController() | ||
{ | ||
return $this->_actionController; | ||
} | ||
|
||
/** | ||
* Hook into action controller initialization | ||
* | ||
* @return void | ||
*/ | ||
public function init() | ||
{ | ||
} | ||
|
||
/** | ||
* Hook into action controller preDispatch() workflow | ||
* | ||
* @return void | ||
*/ | ||
public function preDispatch() | ||
{ | ||
} | ||
|
||
/** | ||
* Hook into action controller postDispatch() workflow | ||
* | ||
* @return void | ||
*/ | ||
public function postDispatch() | ||
{ | ||
} | ||
|
||
/** | ||
* getRequest() - | ||
* | ||
* @return Zend_Controller_Request_Abstract $request | ||
*/ | ||
public function getRequest() | ||
{ | ||
return $this->getActionController()->getRequest(); | ||
} | ||
|
||
/** | ||
* getResponse() - | ||
* | ||
* @return Zend_Controller_Response_Abstract $response | ||
*/ | ||
public function getResponse() | ||
{ | ||
return $this->getActionController()->getResponse(); | ||
} | ||
|
||
/** | ||
* getName() | ||
* | ||
* @return string | ||
*/ | ||
abstract public function getName(); | ||
|
||
public function __call($method, $args) | ||
{ | ||
throw new \BadMethodCallException("$method() is not supported."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Whitewashing ZendMvc1CompatBundle | ||
* | ||
* 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\Zend\Mvc1CompatBundle\Controller\Helpers; | ||
|
||
use Symfony\Component\DependencyInjection\Container; | ||
use Whitewashing\Zend\Mvc1CompatBundle\Controller\ZendController; | ||
|
||
class ZendActionHelper | ||
{ | ||
private $helpers = array(); | ||
|
||
public function __construct(Container $container, ZendController $controller) | ||
{ | ||
// TODO: Convert to using tags! | ||
// TODO: Remember helpers should be scope=request | ||
$helpers = array( | ||
'whitewashing.zend.mvc1compatbundle.actionhelper.redirector', | ||
'whitewashing.zend.mvc1compatbundle.actionhelper.url', | ||
'whitewashing.zend.mvc1compatbundle.actionhelper.json', | ||
'whitewashing.zend.mvc1compatbundle.actionhelper.flashmessenger', | ||
); | ||
foreach ($helpers AS $helper) { | ||
$helper = $container->get($helper); | ||
$helper->setActionController($controller); | ||
$this->helpers[$helper->getName()] = $helper; | ||
} | ||
} | ||
|
||
public function __get($helper) | ||
{ | ||
return $this->getHelper($helper); | ||
} | ||
|
||
public function getHelper($name) | ||
{ | ||
$name = strtolower($name); | ||
if (!isset($this->helpers[$name])) { | ||
throw new \RuntimeException("No Zend ActionHelper with name $name registered."); | ||
} | ||
return $this->helpers[$name]; | ||
} | ||
|
||
public function __call($method, $args) | ||
{ | ||
$helper = $this->getHelper($method); | ||
return call_user_func_array(array($helper, 'direct'), $args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Whitewashing ZendMvc1CompatBundle | ||
* | ||
* 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\Zend\Mvc1CompatBundle\Controller\Helpers; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
class UrlHelper extends Helper | ||
{ | ||
/** | ||
* @var Symfony\Component\Routing\RouterInterface | ||
*/ | ||
private $router; | ||
private $request; | ||
|
||
public function __construct(RouterInterface $router, Request $request) | ||
{ | ||
$this->router = $router; | ||
$this->request = $request; | ||
} | ||
|
||
public function simple($action, $controller = null, $module = null, array $params = null) | ||
{ | ||
if (!$controller) { | ||
list($bundle, $controller) = explode(":", $this->request->attributes->get('_controller')); | ||
} else if (!$module) { | ||
list($bundle, $devnull) = explode(":", $this->request->attributes->get('_controller')); | ||
} | ||
|
||
$this->router-> | ||
|
||
$controller = $module.":".$controller.":".$action; | ||
return $this->tools->container->get('http_kernel')->forward($controller, array(), $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
/** | ||
* Whitewashing ZendMvc1Bundle | ||
* | ||
* 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\Zend\Mvc1CompatBundle\Controller; | ||
|
||
class ZendController | ||
{ | ||
protected $tools; | ||
protected $_request; | ||
protected $_response; | ||
|
||
public function __construct(MvcTools $tools) | ||
{ | ||
$this->tools = $tools; | ||
$this->_request = new ZendRequest($tools->request); | ||
$this->_response = new ZendResponse(); | ||
|
||
$this->init(); | ||
$this->preDispatch(); | ||
} | ||
|
||
public function init() {} | ||
|
||
public function preDispatch() {} | ||
|
||
public function postDispatch() {} | ||
|
||
public function getHelper($name) | ||
{ | ||
|
||
} | ||
|
||
protected function _getParam($name, $default) | ||
{ | ||
$value = $this->_request->getParam($paramName); | ||
if ((null === $value || '' === $value) && (null !== $default)) { | ||
$value = $default; | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
protected function _setParam($name, $value) | ||
{ | ||
$this->_request->setParam($name, $value); | ||
return $this; | ||
} | ||
|
||
protected function _hasParam($name) | ||
{ | ||
return null !== $this->_request->getParam($paramName); | ||
} | ||
|
||
protected function _getAllParams() | ||
{ | ||
return $this->_request->getParams(); | ||
} | ||
|
||
/** | ||
* Forward to another controller/action. | ||
* | ||
* It is important to supply the unformatted names, i.e. "article" | ||
* rather than "ArticleController". The dispatcher will do the | ||
* appropriate formatting when the request is received. | ||
* | ||
* If only an action name is provided, forwards to that action in this | ||
* controller. | ||
* | ||
* If an action and controller are specified, forwards to that action and | ||
* controller in this module. | ||
* | ||
* Specifying an action, controller, and module is the most specific way to | ||
* forward. | ||
* | ||
* A fourth argument, $params, will be used to set the request parameters. | ||
* If either the controller or module are unnecessary for forwarding, | ||
* simply pass null values for them before specifying the parameters. | ||
* | ||
* @param string $action | ||
* @param string $controller | ||
* @param string $module | ||
* @param array $params | ||
* @return void | ||
*/ | ||
final protected function _forward($action, $controller = null, $module = null, array $params = null) | ||
{ | ||
if (!$controller) { | ||
list($bundle, $controller) = explode(":", $this->tools->request->attributes->get('_controller')); | ||
} else if (!$module) { | ||
list($bundle, $devnull) = explode(":", $this->tools->request->attributes->get('_controller')); | ||
} | ||
|
||
$controller = $module.":".$controller.":".$action; | ||
return $this->tools->container->get('http_kernel')->forward($controller, array(), $params); | ||
} | ||
|
||
/** | ||
* Redirect to another URL | ||
* | ||
* Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}. | ||
* | ||
* @param string $url | ||
* @param array $options Options to be used when redirecting | ||
* @return void | ||
*/ | ||
protected function _redirect($url, array $options = array()) | ||
{ | ||
$response = $this->container->get('response'); | ||
$response->setRedirect($url); | ||
return $response; | ||
} | ||
} |
Oops, something went wrong.