mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-01-18 18:42:53 -05:00
Merge pull request #171 from Icinga/bugfix/info-url-not-working-113
Url: remove unneccessary duplicate code
This commit is contained in:
commit
a646da44f0
2 changed files with 1 additions and 53 deletions
|
|
@ -4,7 +4,7 @@
|
|||
Requirements
|
||||
------------
|
||||
|
||||
* Icinga Web 2 (>= 2.4.1)
|
||||
* Icinga Web 2 (>= 2.5.1)
|
||||
* PHP (>= 5.4 or 7.x)
|
||||
|
||||
The Icinga Web 2 `monitoring` module needs to be configured and enabled.
|
||||
|
|
|
|||
|
|
@ -3,69 +3,17 @@
|
|||
namespace Icinga\Module\Businessprocess\Web;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Url as WebUrl;
|
||||
use Icinga\Web\UrlParams;
|
||||
|
||||
/**
|
||||
* Class Url
|
||||
*
|
||||
* The main purpose of this class is to get unit tests running on CLI
|
||||
* Little code from Icinga\Web\Url has been duplicated, as neither fromPath()
|
||||
* nor getRequest() can be extended in a meaningful way at the time of this
|
||||
* writing
|
||||
*
|
||||
* @package Icinga\Module\Businessprocess\Web
|
||||
*/
|
||||
class Url extends WebUrl
|
||||
{
|
||||
public static function fromPath($url, array $params = array(), $request = null)
|
||||
{
|
||||
if ($request === null) {
|
||||
$request = static::getRequest();
|
||||
}
|
||||
|
||||
if (! is_string($url)) {
|
||||
throw new ProgrammingError(
|
||||
'url "%s" is not a string',
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
$self = new static;
|
||||
|
||||
if ($url === '#') {
|
||||
return $self->setPath($url);
|
||||
}
|
||||
|
||||
$parts = parse_url($url);
|
||||
|
||||
$self->setBasePath($request->getBaseUrl());
|
||||
if (isset($parts['path'])) {
|
||||
$self->setPath($parts['path']);
|
||||
}
|
||||
|
||||
if (isset($urlParts['query'])) {
|
||||
$params = UrlParams::fromQueryString($urlParts['query'])->mergeValues($params);
|
||||
}
|
||||
|
||||
if (isset($parts['fragment'])) {
|
||||
$self->setAnchor($parts['fragment']);
|
||||
}
|
||||
|
||||
$self->setParams($params);
|
||||
return $self;
|
||||
}
|
||||
|
||||
public function setBasePath($basePath)
|
||||
{
|
||||
if (property_exists($this, 'basePath')) {
|
||||
parent::setBasePath($basePath);
|
||||
} else {
|
||||
return $this->setBaseUrl($basePath);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getRequest()
|
||||
{
|
||||
$app = Icinga::app();
|
||||
|
|
|
|||
Loading…
Reference in a new issue