This commit is contained in:
2018-07-08 17:34:50 +02:00
commit d2d098006c
112 changed files with 40655 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace MightyPork\Exceptions;
/**
* 'Access denied' kind of exception
*/
class AccessException extends RuntimeException
{
//
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace MightyPork\Exceptions;
/**
* Wrong method arguments passed.
*/
class ArgumentException extends RuntimeException
{
//
}
@@ -0,0 +1,33 @@
<?php
namespace MightyPork\Exceptions;
trait ExceptionConstructorTrait
{
/**
* Create from (Cause), or (Message, Cause).
* Cause is Exception.
*
* @param mixed $arg1 Cause, or Message if second arg is Cause
* @param mixed|null $arg2 Cause
*/
public function __construct($arg1 = null, $arg2 = null)
{
$cause = null;
$message = "";
if ($arg1 instanceof \Exception) {
// Invoked without a message, only cause
$cause = $arg1;
$message = $cause->getMessage(); // Repeat the message so it's easy to see in the logs
} elseif (is_string($arg1)) {
// First is message
$message = $arg1;
// Second, optional, is a cause
if ($arg2 instanceof \Exception) {
$cause = $arg2;
}
}
// call Exception constructor
parent::__construct($message, 0, $cause);
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace MightyPork\Exceptions;
/**
* Malformed config field, invalid syntax
*/
class FormatException extends RuntimeException
{
//
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace MightyPork\Exceptions;
/**
* Something that should exist, doesn't
*/
class NotExistException extends RuntimeException
{
//
}
@@ -0,0 +1,11 @@
<?php
namespace MightyPork\Exceptions;
/**
* tried to run a method that's not implemented yet.
*/
class NotImplementedException extends RuntimeException
{
//
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace MightyPork\Exceptions;
/**
* Custom exception that happens rarely and does not need to be handled explicitly.
*/
abstract class RuntimeException extends \RuntimeException
{
use ExceptionConstructorTrait;
}
+14
View File
@@ -0,0 +1,14 @@
<?php
namespace MightyPork\Exceptions;
class ViewException extends RuntimeException
{
public $captured;
public function __construct(\Exception $cause, $captured)
{
$this->captured = $captured;
parent::__construct($cause);
}
}