Api\V1\Engine\Api::isValidRequestMethod PHP Method

isValidRequestMethod() public static method

This is called in backend/modules//engine/api.php to limit certain calls to a given request method.
public static isValidRequestMethod ( string $method ) : boolean
$method string
return boolean
    public static function isValidRequestMethod($method)
    {
        if ($method !== $_SERVER['REQUEST_METHOD']) {
            $message = 'Illegal request method, only ' . $method . ' allowed for this method';
            return self::output(self::BAD_REQUEST, array('message' => $message));
        }
        return true;
    }

Usage Example

Example #1
0
 /**
  * Get a list of all the forms
  *
  * @param int $limit  The maximum number of items to retrieve.
  * @param int $offset The offset.
  * @return array
  */
 public static function getAll($limit = 30, $offset = 0)
 {
     if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('GET')) {
         // redefine
         $limit = (int) $limit;
         $offset = (int) $offset;
         // validate
         if ($limit > 10000) {
             return BaseAPI::output(BaseAPI::ERROR, array('message' => 'Limit can\'t be larger than 10000.'));
         }
         $forms = (array) BackendModel::getContainer()->get('database')->getRecords('SELECT i.id, i.language, i.name, i.method,
              UNIX_TIMESTAMP(i.created_on) AS created_on,
              UNIX_TIMESTAMP(i.edited_on) AS edited_on
              FROM forms AS i
              ORDER BY i.created_on DESC
              LIMIT ?, ?', array($offset, $limit));
         $return = array('forms' => null);
         foreach ($forms as $row) {
             $item['form'] = array();
             // set attributes
             $item['form']['@attributes']['id'] = $row['id'];
             $item['form']['@attributes']['created_on'] = date('c', $row['created_on']);
             $item['form']['@attributes']['language'] = $row['language'];
             // set content
             $item['form']['name'] = $row['name'];
             $item['form']['method'] = $row['method'];
             $return['forms'][] = $item;
         }
         return $return;
     }
 }
All Usage Examples Of Api\V1\Engine\Api::isValidRequestMethod