letrunghieu / active

The helper class for Laravel applications to get active class base on current route
https://www.hieule.info/tag/laravel-active/
MIT License
414 stars 83 forks source link

Feature: third argument to return for when route does not match pattern #15

Closed lowerends closed 9 years ago

lowerends commented 9 years ago

A nice feature would be to have the possibility to add a third argument that would be returned in case the route does not match the given pattern. For example:

# Return string 'selected' if current URI is /foo or /bar or return string 'not-selected' if current URI is not /foo and not /bar
Active::pattern(array('foo', 'bar'), 'selected', 'not-selected');

Would this be something you would consider to add? I'd be glad to help with a pull request!

letrunghieu commented 9 years ago

You can use native PHP to achieve this purpose instead of adding a conditional return statement into each method of the package:

Active::pattern(array('foo', 'bar'), 'selected') ? : 'not-selected'
lowerends commented 9 years ago

Indeed, but I thought it would be a nice addition to this package to make it more fluent.

letrunghieu commented 9 years ago

I think you can make a PR so that I can write performance test for these two options :smile:

lowerends commented 9 years ago

Cool, I'll give it a try the coming days.

lowerends commented 9 years ago

I just created a pull request for this issue in #16. There's no extra conditional return statements used, so there will be no impact on performance.

lowerends commented 9 years ago

Thanks!