Working version of project

This commit is contained in:
Mateusz Pieła 2021-04-26 23:01:23 +02:00
parent 0b21896cd5
commit 5411c00ee9
9 changed files with 259 additions and 46 deletions

View file

@ -1,18 +1,73 @@
<?php
namespace Includes;
use Classes\Xmpp;
use Classes\Webhook;
use Config\Config;
/**
* Main Application Class
* @package Includes
*/
class App
{
protected $config;
/**
* Start application
*/
public function start(){
print("SERVING WEBHOOK API");
public function __construct()
{
$this->config = new Config();
}
/**
* Main application loop
*/
public function start(){
if($this->checkIfRequestMethodIsPost() && $this->checkAuthorization()) {
$this->handleIncomingData();
}
}
/**
* Check if client is authorized to post via this gate
* @return bool
*/
private function checkAuthorization()
{
if(isset($_GET['apikey']) && $_GET['apikey'] === $this->config->api_key)
{
return true;
}
else
{
die("ERROR: Client not authenticated to use this application");
}
return false;
}
/**
* Check if request method is post
* @return bool
*/
private function checkIfRequestMethodIsPost()
{
if($_SERVER["REQUEST_METHOD"])
{
return true;
}
return false;
}
private function handleIncomingData()
{
$post = file_get_contents("php://input");
$wh = new Webhook($post);
$xmpp = new Xmpp();
$xmpp->start();
$xmpp->connect();
$xmpp->sendMessage($wh->getMessage());
$xmpp->disconnect();
}
}