resq/catalyst/api-bundle/Controller/APIController.php

41 lines
1 KiB
PHP

<?php
namespace Catalyst\APIBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
abstract class APIController extends Controller
{
protected function checkRequiredParameters(Request $req, $params = [])
{
$missing = [];
// check if parameters are there
foreach ($params as $param)
{
if ($req->getMethod() == 'GET')
{
$check = $req->query->get($param);
if (empty($check))
$missing[] = $param;
}
// else if ($req->getMethod() == 'POST')
else
{
$check = $req->request->get($param);
if (empty($check))
$missing[] = $param;
}
}
// check missing parameters
if (count($missing) > 0)
{
$miss_string = implode(', ', $missing);
return 'Missing required parameter(s): ' . $miss_string;
}
return false;
}
}