app/controllers/CallbackController.php: move endpointAction() to ApiController.
This commit is contained in:
parent
7a81eb87e3
commit
bd5a8402e6
3 changed files with 54 additions and 48 deletions
52
app/controllers/ApiController.php
Normal file
52
app/controllers/ApiController.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue