c9s / Pux

Pux is a fast PHP Router and includes out-of-box controller tools
MIT License
1.27k stars 81 forks source link

Merging options nicely #69

Closed rubensayshi closed 9 years ago

rubensayshi commented 10 years ago

As you can see in the test I've added the old code wouldn't merge recursively, as a result you couldn't set 'default' or 'require' options on a mount.

with these changes and the (already merged) change of being able to mount a lambda you can do stuff like the example below with overwriting options etc.

// mount API
$mux->mount('', function(Mux $mux) {
    // mount v1 API
    $mux->mount('/v1/:network', function(Mux $mux) {
        // mount endpoints ...
        $mux->get('/block/:blockhash(.:format)', "BlockController:getBlock");
    }, [
        'default' => [
            'format' => 'xml'
        ],
        'require' => [ 'network' => '[a-zA-Z]{3,4}' ],
    ]);
}, [
    'domain' => 'api.blocktrail.com',
    'default' => [
        'network' => 'BTC',
        'format' => 'json'
    ],
    'require' => [
        'format' => 'json|csv|xml'
    ],
]);
c9s commented 9 years ago

looks good, but I didn't see a test for building mux with lambda? can you add one for that? Thanks!

c9s commented 9 years ago

any update?

c9s commented 9 years ago

I fixed the tests and merged into master