PHPDaemon\Request\Generic::getString PHP Method

getString() public static method

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

Usage Example

 public function init()
 {
     $this->req->components->Account->onAuth(function ($result) {
         if (isset($this->req->attrs->request['email'])) {
             $email = Request::getString($this->req->attrs->request['email']);
         } else {
             if (!$this->req->account['logged']) {
                 $this->req->redirectToLogin();
                 return;
             }
             $email = $this->req->account['email'];
         }
         $this->assign('status', 'standby');
         if (!isset($this->req->attrs->request['code'])) {
             $this->runTemplate();
             return;
         }
         $this->req->appInstance->accounts->confirmAccount(array('email' => $email, 'confirmationcode' => trim($this->req->attrs->request['code'])), function ($result) use($email) {
             if ($result['updatedExisting']) {
                 $this->success();
             } else {
                 $this->req->appInstance->accounts->getAccountByEmail($email, function ($account) {
                     $this->assign('status', isset($account['confirmationcode']) ? 'incorrectCode' : ($account ? 'alreadyConfirmed' : 'accountNotFound'));
                     $this->runTemplate();
                 });
             }
         });
     });
 }
All Usage Examples Of PHPDaemon\Request\Generic::getString