Skip to content
Snippets Groups Projects

Pluggable restful

Merged Patrick Barroca requested to merge pluggable-restful into master
Compare and
+ 14
9
Preferences
Compare changes
Files
@@ -46,27 +46,28 @@ class Restful_Bootstrap {
* @param Zend_Controller_Front $controller
* @param strings $prefix
*/
public static function asPlugin($controller, $prefix, $viewRenderer) {
static::_addRoutes($controller->getRouter(), $prefix);
public static function asPlugin($controller, $named, $viewRenderer) {
static::_addRoutes($controller->getRouter(), $named);
if ($viewRenderer)
$viewRenderer->view->addHelperPath('Restful/View/Helper', 'Restful_View_Helper');
}
protected static function _addRoutes($router, $prefix) {
$prefixed = function($path) use ($prefix) { return $prefix.$path; } ;
protected static function _addRoutes($router, $module) {
$prefixed = function($path) use ($module) { return ($module) ? $module.'/'.$path : $path; };
$moduled = function($params) use ($module) { return ($module) ? array_merge($params, ['module' => $module]) : $params ; };
$router
->addRoute('restindex',
new Zend_Controller_Router_Route($prefixed(':model/*'), ['page' => 1]))
new Zend_Controller_Router_Route($prefixed(':model/*'), $moduled(['page' => 1])))
->addRoute('restshow',
new Zend_Controller_Router_Route($prefixed(':model/:id'), ['action' => 'show']))
new Zend_Controller_Router_Route($prefixed(':model/:id'), $moduled(['action' => 'show'])))
->addRoute('restnew',
new Zend_Controller_Router_Route($prefixed(':model/new'), ['action' => 'new']))
new Zend_Controller_Router_Route($prefixed(':model/new'), $moduled(['action' => 'new'])))
->addRoute('restedit',
new Zend_Controller_Router_Route($prefixed(':model/:id/edit'), ['action' => 'edit']))
new Zend_Controller_Router_Route($prefixed(':model/:id/edit'), $moduled(['action' => 'edit'])))
->addRoute('restcatalog',
new Zend_Controller_Router_Route_Static($prefixed('catalog'), ['action' => 'catalog']))
new Zend_Controller_Router_Route_Static($prefixed('catalog'), $moduled(['action' => 'catalog'])))
;
}