Args library learns signals

Args checking library updated with a C-like passion for signals.

The problem

While the previous versions of the Args library did allow for the specification of the exception to be thrown on failure using the below method


I needed a more precise and granular way to control which exception is thrown when.

Else throw

On its own the library will throw exceptions specific to the first check that has failed

Arg::_('foo', 'Argument')->is_string()->is_numeric();

// will throw new InvalidArgumentException('Argument is not numeric')

but the else_throw method allows for a downright maniacal control over what’s thrown when

Arg::_('foo', 'Argument')
->is_string()->else_throw(new NotAStringException())
->is_numeric()->else_throw(new NotNumericException());

// will throw new NotNumericException()

Energy efficiency

The new method allows for more memory efficiency allowing an exception class and a message to be specified in place of requiring the instantiation of a new instance that might never be used.

Arg::_('foo', 'Argument')

// will throw new NotNumericException()

Furthermore the Exception part of the class name can be left out as well

Arg::_('foo', 'Argument')

// will throw new NotNumericException()

Ready for an exceptional fun.

I appreciate your input