Archived
1
0
Fork 0
This repository has been archived on 2026-04-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
httpcb/app/controllers/ApiController.php

52 lines
1.5 KiB
PHP

<?php
namespace App\Controller;
use App\Controller\ControllerBase,
App\Model\Data\Callback as CallbackModel,
App\Model\Data\Request as RequestModel,
App\Model\Data\RequestMeta as RequestMetaModel;
class ApiController extends ControllerBase
{
/**
* This is the action that the API to be
* tested should make it's callback to. So we can catch it.
*
* @param int $id The test session id so
* we know what test it belongs to.
* @return string
*/
public function endpointAction($id)
{
$this->view->disable();
$allowed_methods = array('GET', 'POST');
if ($this->request->isMethod($allowed_methods)) {
$callback = CallbackModel::get($id);
$request = new RequestModel();
$request->setHeaders($this->request->getHeaders());
$request->setBody($this->request->getRawBody());
$dt = new \DateTime();
$callback->setLastRequest($dt->format('Y-m-d H:i:s'));
$meta = new RequestMetaModel();
$meta->Callback = $callback;
$meta->RequestObject = $request;
$meta->setSourceIp($this->request->getClientAddress());
$meta->setMethod($this->request->isPost() ? 'POST' : 'GET');
$meta->setUri($this->request->getServer('REQUEST_URI'));
$result = $meta->save();
if ($result == false) {
var_dump($meta->getMessages());
}
}
}
}