Fix php style

This commit is contained in:
osaajani 2020-01-17 18:19:25 +01:00
parent 461bd9c98d
commit b8bd067dc7
59 changed files with 2307 additions and 1868 deletions

View file

@ -1,11 +1,21 @@
<?php
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace daemons;
use \Monolog\Logger;
use \Monolog\Handler\StreamHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
/**
* Phone daemon class
* Phone daemon class.
*/
class Webhook extends AbstractDaemon
{
@ -16,14 +26,15 @@ class Webhook extends AbstractDaemon
private $bdd;
/**
* Constructor
* Constructor.
*
* @param array $phone : A phone table entry
*/
public function __construct()
{
$name = "RaspiSMS Daemon Webhook";
$name = 'RaspiSMS Daemon Webhook';
$logger = new Logger($name);
$logger->pushHandler(new StreamHandler(PWD_LOGS . '/raspisms.log', Logger::DEBUG));
$logger->pushHandler(new StreamHandler(PWD_LOGS.'/raspisms.log', Logger::DEBUG));
$pid_dir = PWD_PID;
$no_parent = false; //Sended should be rattach to manager, so manager can stop him easily
$additional_signals = [];
@ -35,13 +46,12 @@ class Webhook extends AbstractDaemon
parent::start();
}
public function run()
{
$find_message = true;
while ($find_message)
{
//Call message
//Call message
$msgtype = null;
$maxsize = 409600;
$message = null;
@ -50,16 +60,17 @@ class Webhook extends AbstractDaemon
$success = msg_receive($this->webhook_queue, QUEUE_TYPE_WEBHOOK, $msgtype, $maxsize, $message, true, 0, $error_code);
if (!$success)
{
$this->logger->critical('Error for webhook queue reading, error code : ' . $error_code);
$this->logger->critical('Error for webhook queue reading, error code : '.$error_code);
}
if (!$message)
{
$find_message = false;
continue;
}
$this->logger->info('Trigger webhook : ' . json_encode($message));
$this->logger->info('Trigger webhook : '.json_encode($message));
//Do the webhook http query
$curl = curl_init();
@ -74,30 +85,27 @@ class Webhook extends AbstractDaemon
usleep(0.5 * 1000000);
}
public function on_start()
{
//Set last message at to construct time
$this->last_message_at = microtime(true);
$this->webhook_queue = msg_get_queue(QUEUE_ID_WEBHOOK);
$this->logger->info("Starting Webhook daemon with pid " . getmypid());
$this->logger->info('Starting Webhook daemon with pid '.getmypid());
}
public function on_stop()
public function on_stop()
{
//Delete queue on daemon close
$this->logger->info("Closing queue : " . QUEUE_ID_WEBHOOK);
$this->logger->info('Closing queue : '.QUEUE_ID_WEBHOOK);
msg_remove_queue($this->webhook_queue);
$this->logger->info("Stopping Webhook daemon with pid " . getmypid ());
$this->logger->info('Stopping Webhook daemon with pid '.getmypid());
}
public function handle_other_signals($signal)
{
$this->logger->info("Signal not handled by " . $this->name . " Daemon : " . $signal);
$this->logger->info('Signal not handled by '.$this->name.' Daemon : '.$signal);
}
}