2014-08-22 10:23:12 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-08-22 10:23:12 +02:00
|
|
|
|
|
|
|
namespace Icinga\Exception;
|
|
|
|
|
|
|
|
use Exception;
|
2015-07-27 16:25:41 +02:00
|
|
|
use ReflectionClass;
|
2014-08-22 10:23:12 +02:00
|
|
|
|
|
|
|
class IcingaException extends Exception
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $message format string for vsprintf()
|
|
|
|
* Any futher args: args for vsprintf()
|
|
|
|
* @see vsprintf
|
|
|
|
*
|
|
|
|
* If there is at least one exception, the last one will be also used for the exception chaining.
|
|
|
|
*/
|
2015-07-28 10:43:17 +02:00
|
|
|
public function __construct($message)
|
2014-08-22 10:23:12 +02:00
|
|
|
{
|
|
|
|
$args = array_slice(func_get_args(), 1);
|
|
|
|
$exc = null;
|
|
|
|
foreach ($args as &$arg) {
|
|
|
|
if ($arg instanceof Exception) {
|
|
|
|
$exc = $arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent::__construct(vsprintf($message, $args), 0, $exc);
|
|
|
|
}
|
2015-07-27 16:25:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the exception from an array of arguments
|
|
|
|
*
|
|
|
|
* @param array $args
|
|
|
|
*
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public static function create(array $args)
|
|
|
|
{
|
|
|
|
$e = new ReflectionClass(get_called_class());
|
|
|
|
return $e->newInstanceArgs($args);
|
|
|
|
}
|
2014-08-22 10:23:12 +02:00
|
|
|
}
|