Cachet
Cachet PHP client., (*1)
About Cachet
Cachet is an open source status page system written in PHP. https://github.com/CachetHQ/Cachet., (*2)
Usage
Setup, (*3)
use Mangati\Cachet\Client;
$endpoint = 'https://demo.cachethq.io/api/v1/';
$token = '9yMHsdioQosnyVK4iCVR';
$client = new Client($endpoint, $token);
Components
Get components, (*4)
$components = $client->getComponents();
foreach ($components as $component) {
echo $component->getName();
}
Sorting, (*5)
$components = $client->getComponents([
'sort' => 'id',
'order' => 'desc'
]);
Get by id, (*6)
$component = $client->getComponent(3);
Create new component, (*7)
$component = new Component();
$component->setName('My new component');
$component->setDescription('Component description');
$component->setLink('https://github.com/mangati/cachet');
$component->setStatus(Component::STATUS_OPERATIONAL);
$client->addComponent($component);
Update an existing component, (*8)
$component = new Component();
$component->setId(3);
$component->setName('My new component (updated)');
$client->updateComponent($component);
Delete an existing component, (*9)
$id = 3;
$client->deleteComponent($id);
Incidents
Get incidents, (*10)
$incidents = $client->getIncidents();
foreach ($incidents as $incident) {
echo $incident->getName();
}
Sorting, (*11)
$incidents = $client->getIncidents([
'sort' => 'id',
'order' => 'desc'
]);
Get by id, (*12)
$incident = $client->getIncident(3);
Create new incident, (*13)
$incident = new Incident();
$incident->setName('My new incident');
$incident->setMessage('incident message');
$incident->setStatus(Incident::STATUS_WATCHING);
$client->addIncident($incident);
Update an existing incident, (*14)
$incident = new Incident();
$incident->setId(3);
$incident->setStatus(Incident::STATUS_FIXED);
$client->updateIncident($incident);
Delete an existing incident, (*15)
$id = 3;
$client->deleteIncident($id);
Known issue
Doctrine annotation error:, (*16)
PHP Fatal error: Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Semantical Error] The annotation "@JMS\Serializer\Annotation\Type" in property (...) does not exist, or could not be auto-loaded.'
Can fix it registering the JMS namespace:, (*17)
Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace('JMS\Serializer\Annotation', $rootDir . "/vendor/jms/serializer/src");