Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit d9853fd

Browse files
committed
Enhancement: a check for CouchDB
Related: easybib/issues#4396
1 parent 813842f commit d9853fd

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* @license http://framework.zend.com/license/new-bsd New BSD License
4+
*/
5+
6+
namespace ZendDiagnostics\Check;
7+
8+
use ZendDiagnostics\Result;
9+
10+
/**
11+
* Ensures a connection to CouchDB is possible.
12+
*/
13+
class CouchDB extends GuzzleHttpService
14+
{
15+
/**
16+
* @param array $couchDbSettings
17+
*
18+
* @return self
19+
*/
20+
public function __construct(array $couchDbSettings)
21+
{
22+
$couchDbUrl = '';
23+
if ($couchDbSettings['port'] === '5984' || $couchDbSettings['port'] === '80') {
24+
$couchDbUrl .= 'http://';
25+
} else {
26+
$couchDbUrl .= 'https://';
27+
}
28+
29+
if ($couchDbSettings['username'] && $couchDbSettings['password']) {
30+
$couchDbUrl .= sprintf(
31+
'%s:%s@',
32+
$couchDbSettings['username'],
33+
$couchDbSettings['password']
34+
);
35+
}
36+
37+
$couchDbUrl .= sprintf(
38+
'%s:%s/%s',
39+
$couchDbSettings['host'],
40+
$couchDbSettings['port'],
41+
$couchDbSettings['dbname']
42+
);
43+
44+
parent::__construct($couchDbUrl);
45+
}
46+
47+
/**
48+
* {@inheritDoc}
49+
*/
50+
public function check()
51+
{
52+
$result = parent::check();
53+
if ($result instanceof Result\Success) {
54+
return $result;
55+
}
56+
57+
$msg = $result->getMessage();
58+
$msg = preg_replace('=\/\/(.+):{1}(.+)(\@){1}=i', '//', $msg);
59+
60+
$failure = new Result\Failure($msg, $result->getData());
61+
62+
return $failure;
63+
}
64+
}

0 commit comments

Comments
 (0)