Example #1
0
function test_handler_match_()
{
    should_return(handler_('GET', array('/', '/{home}'), array(), array('func')), when_passed(handler_('GET', array('/', '/{home}'), array(), array('func')), request_(array('method' => 'GET', 'path' => '/hand'))));
    should_return(handler_('GET', array('/'), array(), array('func')), when_passed(handler_('GET', array('/'), array(), array('func')), request_(array('method' => 'GET', 'path' => '/', 'query' => array('foo' => 'bar')))));
    should_return(handler_('GET', array('/'), array('query' => true), array('func')), when_passed(handler_('GET', array('/'), array('query' => true), array('func')), request_(array('method' => 'GET', 'path' => '/', 'query' => array('foo' => 'bar')))));
    should_return(NULL, when_passed(handler_('GET', array('/'), array('query' => true), array('func')), request_(array('method' => 'GET', 'path' => '/', 'query' => array()))));
    should_return(handler_('POST', array('/'), array('action' => 'save_me'), array('func')), when_passed(handler_('POST', array('/'), array('action' => 'save_me'), array('func')), request_(array('method' => 'POST', 'path' => '/', 'form' => array('action' => 'Save Me')))));
    should_return(handler_('POST', array('/'), array(), array('func')), when_passed(handler_('POST', array('/'), array(), array('func')), request_(array('method' => 'POST', 'path' => '/', 'form' => array('action' => 'Save Me')))));
    should_return(NULL, when_passed(handler_('POST', array('/'), array('action' => 'save'), array('func')), request_(array('method' => 'POST', 'path' => '/', 'form' => array('action' => 'Save Me')))));
    should_return(NULL, when_passed(handler_('POST', array('/'), array('action' => 'save'), array('func')), request_(array('method' => 'POST', 'path' => '/', 'form' => array()))));
}
Example #2
0
function handler_macro($method, $paths, $conds, $func)
{
    $req = request_();
    $handler = handler_($method, $paths, $conds, $func);
    if (handler_match_($handler, $req, $matches)) {
        if (is_callable($handler['func'])) {
            call_user_func_array($handler['func'], array_merge(array($req, $matches)));
        } else {
            trigger_error_("Invalid handler macro func", E_USER_ERROR);
        }
    }
}