Url: hide Icinga Exceptions

This commit is contained in:
Thomas Gelf 2018-06-14 10:14:08 +02:00
parent 810e873566
commit 33ff71ce94

View File

@ -2,10 +2,13 @@
namespace dipl\Web; namespace dipl\Web;
use Exception;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Exception\ProgrammingError;
use Icinga\Web\Url as WebUrl; use Icinga\Web\Url as WebUrl;
use Icinga\Web\UrlParams; use Icinga\Web\UrlParams;
use InvalidArgumentException; use InvalidArgumentException;
use RuntimeException;
/** /**
* Class Url * Class Url
@ -91,8 +94,14 @@ class Url extends WebUrl
foreach ($params as $k => $v) { foreach ($params as $k => $v) {
$urlParams->set($k, $v); $urlParams->set($k, $v);
} }
try {
$url->setParams($urlParams); $url->setParams($urlParams);
} catch (ProgrammingError $e) {
throw new RuntimeException($e->getMessage());
}
$url->setBasePath($request->getBaseUrl()); $url->setBasePath($request->getBaseUrl());
return $url; return $url;
} }
@ -101,15 +110,34 @@ class Url extends WebUrl
if (property_exists($this, 'basePath')) { if (property_exists($this, 'basePath')) {
parent::setBasePath($basePath); parent::setBasePath($basePath);
} else { } else {
return $this->setBaseUrl($basePath); $this->setBaseUrl($basePath);
}
return $this;
}
public function setParams($params)
{
try {
return parent::setParams($params);
} catch (ProgrammingError $e) {
throw new InvalidArgumentException($e->getMessage(), 0, $e);
} }
} }
protected static function getRequest() protected static function getRequest()
{ {
try {
$app = Icinga::app(); $app = Icinga::app();
} catch (ProgrammingError $e) {
throw new RuntimeException($e->getMessage(), 0, $e);
}
if ($app->isCli()) { if ($app->isCli()) {
try {
return new FakeRequest(); return new FakeRequest();
} catch (Exception $e) {
throw new RuntimeException($e->getMessage(), 0, $e);
}
} else { } else {
return $app->getRequest(); return $app->getRequest();
} }