Skip to content
Snippets Groups Projects
Commit 8e36dec4 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

bootstrapping routes can take a prefix

parent 5e04ac59
1 merge request!1Pluggable restful
...@@ -24,23 +24,42 @@ THE SOFTWARE. ...@@ -24,23 +24,42 @@ THE SOFTWARE.
*/ */
class Restful_Bootstrap { class Restful_Bootstrap {
public static function bootstrap() { public static function bootstrap() {
Zend_Controller_Front::getInstance() Zend_Controller_Front::getInstance()
->setControllerDirectory(['default' => 'application/controllers']) ->setControllerDirectory(['default' => 'application/controllers'])
->throwExceptions(true) ->throwExceptions(true);
->getRouter() $router = Zend_Controller_Front::getInstance()->getRouter();
->removeDefaultRoutes() $router->removeDefaultRoutes();
->addRoute('restindex', new Zend_Controller_Router_Route(':model/*'), ['page' => 1]) static::_addRoutes($router, $prefix='');
}
/**
* @param Zend_Controller_Front $controller
* @param strings $prefix
*/
public static function asPlugin($controller, $prefix) {
static::_addRoutes($controller->getRouter(), $prefix);
}
protected static function _addRoutes($router, $prefix) {
$prefixed = function($path) use ($prefix) { return $prefix.$path; } ;
$router
->addRoute('restindex',
new Zend_Controller_Router_Route($prefixed(':model/*'), ['page' => 1]))
->addRoute('restshow', ->addRoute('restshow',
new Zend_Controller_Router_Route(':model/:id', ['action' => 'show'])) new Zend_Controller_Router_Route($prefixed(':model/:id'), ['action' => 'show']))
->addRoute('restnew', ->addRoute('restnew',
new Zend_Controller_Router_Route(':model/new', ['action' => 'new'])) new Zend_Controller_Router_Route($prefixed(':model/new'), ['action' => 'new']))
->addRoute('restedit', ->addRoute('restedit',
new Zend_Controller_Router_Route(':model/:id/edit', ['action' => 'edit'])) new Zend_Controller_Router_Route($prefixed(':model/:id/edit'), ['action' => 'edit']))
->addRoute('restcatalog', ->addRoute('restcatalog',
new Zend_Controller_Router_Route_Static('catalog', ['action' => 'catalog'])) new Zend_Controller_Router_Route_Static($prefixed('catalog'), ['action' => 'catalog']))
;
;
} }
} }
\ No newline at end of file
storm @ d82464a8
Subproject commit 7e275ba41bbd6317a17ed695f003bdec6e7fa83f Subproject commit d82464a880448fb2bbbfe61e1754803cf07f6f4e
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment