Skip to content
Raphaël Emourgeon edited this page Oct 28, 2013 · 1 revision

Router API proposal. The main goal is to define a DSL (Domain Specific Language) that'll be translated by Sohoa into Hoa\Router rules.

// default matcher ?

// manual matcher ('as' is mandatory because its the unique route identifier, it must be unique for each HTTP verb)

get('/pages/<id>', array('to' => 'PagesController#page', 'as' => 'page'));
post('/pages/create', array('to' => 'PagesController#create', 'as' => 'page'));

// get or post (or patch or destroy ?)
any('/pages/create', array('to' => 'PagesController#create', 'as' => 'page'));
any('/pages/<id>', array('to' => 'PagesController#page', 'as' => 'page'));

// full controller (rely on introspection so need caching for performances reasons, removed for the moment)
//controller('/pages/', array('to' => 'PagesController'));
 
// RESTful routes

resource('users');

// only/except (for RESTful routes only)

resource('users', array('only' => 'edit');
resource('users', array('except' => 'destroy');

// nesting

resource('invoice') {

  resource('invoice_line');
  
}

// add specific member/collection methods (the route identifier can be infered from the method called)

resource('invoice') {

  patch('validate', array('scope' => 'member'));
}

resource('users') {

  get('banned', array('scope' => 'collection'));
}

// aliasing / named route (for non RESTful routes only)
// let you define an alias for the route, already implemented by
// the identifier of the rule in Hoa\Router imho

get('/login', array('to' => 'UserSessionsController#new', 'as' => 'login'));
delete('/logout', array('to' => 'UserSessionsController#destroy', 'as' => 'logout'));

// subdomain constraints (subdomain is a string or a regex)

constraints(array('subdomain' => 'www')) {

  get('/pages/<id>', array('to' => 'PagesController#page', 'as' => 'page'));

}

constraints(array('subdomain' => '/.*/')) {

  resource('user_sessions');

}

// HTTPS constraints

constraints(array('protocol' => 'https')) {

  resource('user_sessions');

};
Clone this wiki locally