|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Canvas\Api\Controllers; |
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use PDOException; |
|
9
|
|
|
use Phalcon\Http\Response; |
|
|
|
|
|
|
10
|
|
|
use Canvas\Http\Exception\InternalServerErrorException; |
|
11
|
|
|
use RedisException; |
|
12
|
|
|
use PhpAmqpLib\Exception\AMQPIOException ; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class IndexController. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Canvas\Api\Controllers |
|
18
|
|
|
* |
|
19
|
|
|
* @property Redis $redis |
|
20
|
|
|
* @property Beanstalk $queue |
|
21
|
|
|
* @property Mysql $db |
|
22
|
|
|
* @property \Monolog\Logger $log |
|
23
|
|
|
*/ |
|
24
|
|
|
class IndexController extends BaseController |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Index. |
|
28
|
|
|
* |
|
29
|
|
|
* @method GET |
|
30
|
|
|
* @url / |
|
31
|
|
|
* |
|
32
|
|
|
* @return Response |
|
33
|
|
|
*/ |
|
34
|
|
|
public function index($id = null) : Response |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->response(['Woot Baka']); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Show the status of the diferent services. |
|
41
|
|
|
* |
|
42
|
|
|
* @method GET |
|
43
|
|
|
* @url /status |
|
44
|
|
|
* |
|
45
|
|
|
* @return Response |
|
46
|
|
|
*/ |
|
47
|
|
|
public function status() : Response |
|
48
|
|
|
{ |
|
49
|
|
|
$response = []; |
|
50
|
|
|
|
|
51
|
|
|
//Try to connect to Redis |
|
52
|
|
|
try { |
|
53
|
|
|
$this->redis->hSet('htest', 'a', 'x'); |
|
54
|
|
|
$this->redis->hSet('htest', 'b', 'y'); |
|
55
|
|
|
$this->redis->hSet('htest', 'c', 'z'); |
|
56
|
|
|
$this->redis->hSet('htest', 'd', 't'); |
|
57
|
|
|
$this->redis->hGetAll('htest'); |
|
58
|
|
|
|
|
59
|
|
|
//$this->redis->ping(); |
|
60
|
|
|
} catch (RedisException $e) { |
|
61
|
|
|
$this->log->error($e->getMessage(), $e->getTrace()); |
|
62
|
|
|
$response['errors']['redis'] = $e->getMessage(); |
|
63
|
|
|
} catch (Exception $e) { |
|
64
|
|
|
$this->log->error("Redis isn't working. {$e->getMessage()}", $e->getTrace()); |
|
65
|
|
|
$response['errors']['redis'] = "Redis isn't working."; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
//Try to connect to RabbitMQ |
|
69
|
|
|
try { |
|
70
|
|
|
$this->queue; |
|
71
|
|
|
} catch (AMQPIOException $e) { |
|
|
|
|
|
|
72
|
|
|
$this->log->error($e->getMessage(), $e->getTrace()); |
|
73
|
|
|
$response['errors']['RabbitMQ'] = $e->getMessage(); |
|
74
|
|
|
} catch (Exception $e) { |
|
75
|
|
|
$this->log->error("RabbitMQ isn't working. {$e->getMessage()}", $e->getTrace()); |
|
76
|
|
|
$response['errors']['RabbitMQ'] = "RabbitMQ isn't working."; |
|
77
|
|
|
} finally { |
|
78
|
|
|
$this->queue->close(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
//Try to connect to db |
|
82
|
|
|
try { |
|
83
|
|
|
$this->db->connect(); |
|
84
|
|
|
} catch (PDOException $e) { |
|
85
|
|
|
$this->log->error($e->getMessage(), $e->getTrace()); |
|
86
|
|
|
$response['errors']['db'] = $e->getMessage(); |
|
87
|
|
|
} catch (Exception $e) { |
|
88
|
|
|
$this->log->error("The database isn't working. {$e->getMessage()}", $e->getTrace()); |
|
89
|
|
|
$response['errors']['db'] = "The database isn't working."; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (!count($response)) { |
|
93
|
|
|
return $this->response(['OK']); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
throw new InternalServerErrorException(json_encode($response)); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths