public function testCreatingUnknownStatusSucceeds() { $connector = new TestConnector('default', new ArrayConfig([])); $status = new Status($connector, Status::UNKNOWN); $this->assertTrue($status->isUnknown()); $this->assertSame(Status::UNKNOWN, $status->getStatus()); $this->assertSame('default', $status->getConnectionName()); $status = Status::unknown($connector); $this->assertTrue($status->isUnknown()); $this->assertSame(Status::UNKNOWN, $status->getStatus()); $this->assertSame('default', $status->getConnectionName()); }
/** * Checks connection via HTTP(s). * * @return Status of the connection to the configured host */ public function getStatus() { if ($this->config->has('fake_status')) { return new Status($this, $this->config->get('fake_status')); } if (!$this->config->has('status_test')) { return Status::unknown($this, ['message' => 'No status_test path specified']); } $path = $this->config->get('status_test'); try { $info = []; $verbose = $this->config->get('status_verbose', true); $response = $this->getConnection()->get($path, ['on_stats' => function (TransferStats $stats) use(&$info, $verbose) { if (!$verbose) { return; } $info['effective_uri'] = (string) $stats->getEffectiveUri(); $info['transfer_time'] = $stats->getTransferTime(); $info = array_merge($info, $stats->getHandlerStats()); if ($stats->hasResponse()) { $info['status_code'] = $stats->getResponse()->getStatusCode(); } else { $error_data = $stats->getHandlerErrorData(); if (is_array($error_data) || is_string($error_data)) { $info['handler_error_data'] = $error_data; } } }]); $status_code = $response->getStatusCode(); if ($status_code >= 200 && $status_code < 300) { $msg['message'] = 'GET succeeded: ' . $path; if (!empty($info)) { $msg['info'] = $info; } return Status::working($this, $msg); } return Status::failing($this, ['message' => 'GET failed: ' . $path, 'headers' => $response->getHeaders(), 'info' => $info]); } catch (Exception $e) { error_log('[' . static::CLASS . '] Error on "' . $path . '": ' . $e->getTraceAsString()); return Status::failing($this, ['message' => 'Error on "' . $path . '": ' . $e->getMessage()]); } }
/** * Depending on the type of client and how the connection works this method * may return UNKNOWN Status or create an actual connection and check whether * it works as expected. Status checks should strive to be fast though. * * Whether to do actual status checks of the underlying connection is entirely * up to the connector. * * @return Status of this connector */ public function getStatus() { if ($this->config->has('fake_status')) { return new Status($this, $this->config->get('fake_status')); } return Status::unknown($this); }