PHPDaemon\Request\Generic::getInteger PHP Method

getInteger() public static method

Get integer value from the given variable
public static getInteger ( &$var, $values = null ) : string
return string Value.
    public static function getInteger(&$var, $values = null)
    {
        if (is_string($var) && ctype_digit($var)) {
            $var = (int) $var;
        }
        if (!is_int($var)) {
            return 0;
        }
        if ($values !== null) {
            return in_array($var, $values, true) ? $var : $values[0];
        }
        return $var;
    }

Usage Example

 public function perform()
 {
     $this->cmp->onAuth(function () {
         if (!$this->req->account['logged']) {
             $this->req->setResult([]);
             return;
         }
         $user_id = $this->req->account['_id'];
         $limit = Request::getInteger($_REQUEST['limit']);
         $offset = Request::getInteger($_REQUEST['offset']);
         if ($limit < 1) {
             $limit = 100;
         }
         if ($offset < 0) {
             $offset = 0;
         }
         $this->appInstance->externalAuthTokens->findWaiting($user_id, $limit, $offset, 'ctime,_id,ip,useragent,intToken', function ($cursor) {
             $result = [];
             foreach ($cursor->items as $item) {
                 $item['id'] = (string) $item['_id'];
                 $result[] = $item;
             }
             $this->req->setResult($result);
             $cursor->destroy();
         });
     });
 }
All Usage Examples Of PHPDaemon\Request\Generic::getInteger