PHP code example of antarctica / laravel-base-exceptions
1. Go to this page and download the library: Download antarctica/laravel-base-exceptions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
antarctica / laravel-base-exceptions example snippets
use Antarctica\LaravelBaseExceptions\Exception\HttpException;
class SomeException extends HttpException {
protected $statusCode = 501; // Not implemented - used for demonstration purposes only.
protected $kind = 'some_fault';
protected $details = [
"something" => [
"Something went wrong."
]
];
protected $resolution = 'Please don\'t do that again.';
protected $resolutionURLs = ['http://www.example.com'];
}
use Antarctica\LaravelBaseExceptions\Exception\InvalidArgumentTypeException;
/**
* Determines if the value for an argument is an integer
*
* @param string $argument name of the argument
* @param mixed $var value given for the argument
* @return int
* @throws InvalidArgumentTypeException
* @throws InvalidArgumentValueException
*/
private function validateInt($argument, $var)
{
if (is_numeric($var) === false)
{
throw new InvalidArgumentTypeException(
$argumentName = $argument,
$valueOfCorrectArgumentType = 0,
$argumentValue = $var
);
}
// ...
return $var;
}
use Antarctica\LaravelBaseExceptions\Exception\InvalidArgumentValueException;
/**
* Determines if the value for an argument is an integer
*
* @param string $argument name of the argument
* @param mixed $var value given for the argument
* @return int
* @throws InvalidArgumentTypeException
* @throws InvalidArgumentValueException
*/
private function validateInt($argument, $var)
{
// ...
if ($var <= 0)
{
throw new InvalidArgumentValueException(
$argumentName = $argument,
$reasons = ['Value must not be equal to or less than 0, ' . $var . ' given.'],
$resolution = 'Ensure you are providing a value greater than, and not including 0.'
);
}
return $var;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.