PHPDaemon\Clients\HTTP\Pool::buildUrl PHP Method

buildUrl() public static method

Builds URL from array
public static buildUrl ( string $mixed ) : string | false
$mixed string
return string | false
    public static function buildUrl($mixed)
    {
        if (is_string($mixed)) {
            return $mixed;
        }
        if (!is_array($mixed)) {
            return false;
        }
        $url = '';
        $buf = [];
        $queryDelimiter = '?';
        $mixed[] = '';
        foreach ($mixed as $k => $v) {
            if (is_int($k) || ctype_digit($k)) {
                if (sizeof($buf) > 0) {
                    if (mb_orig_strpos($url, '?') !== false) {
                        $queryDelimiter = '&';
                    }
                    $url .= $queryDelimiter . http_build_query($buf);
                    $queryDelimiter = '';
                }
                $url .= $v;
            } else {
                $buf[$k] = $v;
            }
        }
        return $url;
    }

Usage Example

Exemplo n.º 1
0
 public function perform()
 {
     $hash = Request::getString($_REQUEST['x']);
     if (!strlen($hash) || base64_decode($hash, true) === false) {
         $this->req->setResult(['success' => false, 'error' => 'Wrong format of extTokenHash']);
         return;
     }
     $this->appInstance->externalAuthTokens->findByExtTokenHash($hash, function ($result) use($hash) {
         if ($result) {
             $this->req->setResult(['success' => false, 'error' => 'This token was already used.']);
             return;
         }
         $ip = $this->req->getIp();
         $intToken = Crypt::hash(Daemon::uniqid() . "" . $ip . "" . Crypt::randomString());
         $this->appInstance->externalAuthTokens->save(['extTokenHash' => $hash, 'intToken' => $intToken, 'ip' => $ip, 'useragent' => Request::getString($_SERVER['HTTP_USER_AGENT']), 'ctime' => microtime(true), 'status' => 'new'], function ($lastError) use($intToken) {
             if (!isset($lastError['n']) || $lastError['n'] === 0) {
                 $this->req->setResult(['success' => false, 'errors' => ['code' => 'Sorry, internal error.']]);
                 return;
             }
             $type = Request::getString($_REQUEST['type']);
             if ($type === 'email') {
                 // send email....
             } elseif ($type === 'redirect') {
                 $this->req->redirectTo(HTTPClient::buildUrl(['/' . $this->req->locale . '/account/extauth', 'i' => $intToken]), false);
             }
             $this->req->setResult(['success' => true, 'intToken' => $intToken]);
         });
     });
 }
All Usage Examples Of PHPDaemon\Clients\HTTP\Pool::buildUrl