Download the PHP package tconway1/mattyrad-support without Composer
On this page you can find all versions of the php package tconway1/mattyrad-support. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tconway1/mattyrad-support
More information about tconway1/mattyrad-support
Files in tconway1/mattyrad-support
Package mattyrad-support
Short Description A collection of PHP support classes and traits
License MIT
Informations about the package mattyrad-support
MattyRad Support
Installation
composer require mattyrad/support
Table of Contents
- Conformation Trait
- Result Objects
Conformation Trait
Instantiate objects from an unsorted array
Failing to provide all the required arguments will throw an Exception
PHP Fatal error: Uncaught InvalidArgumentException: Sample missing key(s): arg3, arg4
Result Objects
It's very common to require extensible result objects for success and failures, particularly for APIs.
Defining Results
You can hit the ground running with generic success results
For more precision, you can extend the Success result
Failure results are required to be a bit more specific
Instantiating and Returning Results
Consuming Results
You can check for a failure manually
Alternatively, you can leverage Exceptions and cut out the success/failure checks. Attempting to access data from a Failure Result will cause it to throw an Exception
Laravel's Exception Handler handles a number of exceptions by default (like HttpResponseException), which we can use to our advantage by overriding the default toException function of the Failure Result
And error handling will be built in, we can focus on the success path. Any non-built in exceptions can get caught in the render() function of the Exception Handler.