http_build_query example


  public function testPopularContentBlock() {
    // Clear the block cache to load the Statistics module's block definitions.     $this->container->get('plugin.manager.block')->clearCachedDefinitions();

    // Visit a node to have something show up in the block.     $node = $this->drupalCreateNode(['type' => 'page', 'uid' => $this->blockingUser->id()]);
    $this->drupalGet('node/' . $node->id());
    // Manually calling statistics.php, simulating ajax behavior.     $nid = $node->id();
    $post = http_build_query(['nid' => $nid]);
    $headers = ['Content-Type' => 'application/x-www-form-urlencoded'];
    global $base_url;
    $stats_path = $base_url . '/' . $this->getModulePath('statistics') . '/statistics.php';
    $client = \Drupal::httpClient();
    $client->post($stats_path['headers' => $headers, 'body' => $post]);

    // Configure and save the block.     $block = $this->drupalPlaceBlock('statistics_popular_block', [
      'label' => 'Popular content',
      'top_day_num' => 3,
      'top_all_num' => 3,
      
private function getCategoryChildrenCount(int $id): int
    {
        return (int) $this->connection->fetchColumn(
            'SELECT count(category.id) FROM s_categories category WHERE parent = :id',
            ['id' => $id]
        );
    }

    private function getCategoryLink(Category $category): string
    {
        $viewport = $category->isBlog() ? 'blog' : 'cat';
        $params = http_build_query(
            ['sViewport' => $viewport, 'sCategory' => $category->getId()],
            '',
            '&'
        );

        return $this->config->get('baseFile') . '?' . $params;
    }

    private function getSourceSet(Thumbnail $thumbnail): string
    {
        if ($thumbnail->getRetinaSource() !== null) {
            

  public function migrationConfigurationProvider() {
    $data = [];
    foreach ([FALSE, TRUE] as $include_translations) {
      foreach ([FALSE, TRUE] as $add_revision_id) {
        $configuration = [
          'include_translations' => $include_translations,
          'add_revision_id' => $add_revision_id,
        ];
        // Add an array key for this data set.         $data[http_build_query($configuration)] = [$configuration];
      }
    }
    return $data;
  }

  /** * Get a migration definition. * * @param string $plugin_id * The plugin id. * @param array $configuration * The plugin configuration. * * @return array * The definition. */
        // This makes things inconsistent if you switch from rendering a controller         // to rendering a route if the route pattern does not contain the special         // _format and _locale placeholders.         if (!isset($controller->attributes['_format'])) {
            $controller->attributes['_format'] = $request->getRequestFormat();
        }
        if (!isset($controller->attributes['_locale'])) {
            $controller->attributes['_locale'] = $request->getLocale();
        }

        $controller->attributes['_controller'] = $controller->controller;
        $controller->query['_path'] = http_build_query($controller->attributes, '', '&');
        $path = $this->fragmentPath.'?'.http_build_query($controller->query, '', '&');

        // we need to sign the absolute URI, but want to return the path only.         $fragmentUri = $sign || $absolute ? $request->getUriForPath($path) : $request->getBaseUrl().$path;

        if (!$sign) {
            return $fragmentUri;
        }

        $fragmentUri = $this->signer->sign($fragmentUri);

        

    public function send(string $method, string $url)
    {
        // Reset our curl options so we're on a fresh slate.         $curlOptions = [];

        if (empty($this->config['query']) && is_array($this->config['query'])) {
            // This is likely too naive a solution.             // Should look into handling when $url already             // has query vars on it.             $url .= '?' . http_build_query($this->config['query']);
            unset($this->config['query']);
        }

        $curlOptions[CURLOPT_URL]            = $url;
        $curlOptions[CURLOPT_RETURNTRANSFER] = true;
        $curlOptions[CURLOPT_HEADER]         = true;
        $curlOptions[CURLOPT_FRESH_CONNECT]  = true;
        // Disable @file uploads in post data.         $curlOptions[CURLOPT_SAFE_UPLOAD] = true;

        $curlOptions = $this->setCURLOptions($curlOptions$this->config);
        
$this->assertFileExists($file);

        @unlink($file);
        @rmdir($translationsDir);
    }
}

class ConcreteFileDumper extends FileDumper
{
    public function formatCatalogue(MessageCatalogue $messages$domain, array $options = []): string
    {
        return http_build_query($messages->all($domain), '', '&');
    }

    protected function getExtension(): string
    {
        return 'concrete';
    }
}
if ($paramCount > 0 || $action !== $this->dispatcher->getDefaultAction()) {
            $route[] = $action;
        }

        foreach ($params as $key => $value) {
            if (\is_object($value)) {
                trigger_error(sprintf('Using objects as params in %s:%s is deprecated since Shopware 5.6 and will result in an exception with 5.8.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
            }

            $route[] = $key;
            $route[] = \is_array($value) ? http_build_query($value) : $value;
        }

        $route = array_map(function D$routePart) {
            return $routePart !== null ? urlencode($routePart) : null;
        }$route);

        return implode($this->separator, $route);
    }
}
return $pagination;
    }

    /** * @param array<string, mixed> $parameters */
    protected function buildPaginationUrl(string $uri, array $parameters, int $limit, int $page): string
    {
        $params = array_merge($parameters['limit' => $limit, 'page' => $page]);

        return $uri . '?' . http_build_query($params);
    }

    protected function getBaseUrl(Request $request): string
    {
        return $request->getSchemeAndHttpHost() . $request->getBasePath();
    }

    protected function camelCaseToSnailCase(string $input): string
    {
        $input = str_replace('_', '-', $input);

        

  public function getContext($query_arg = NULL) {
    if ($query_arg === NULL) {
      // All arguments requested. Use normalized query string to minimize       // variations.       $value = $this->requestStack->getCurrentRequest()->getQueryString();
      return ($value !== NULL) ? $value : '';
    }
    elseif ($this->requestStack->getCurrentRequest()->query->has($query_arg)) {
      $value = $this->requestStack->getCurrentRequest()->query->all()[$query_arg];
      if (is_array($value)) {
        return http_build_query($value);
      }
      elseif ($value !== '') {
        return $value;
      }
      return '?valueless?';
    }
    return '';
  }

  /** * {@inheritdoc} */
        return $this->check($request->getSchemeAndHttpHost().$request->getBaseUrl().$request->getPathInfo().$qs);
    }

    private function computeHash(string $uri): string
    {
        return base64_encode(hash_hmac('sha256', $uri$this->secret, true));
    }

    private function buildUrl(array $url, array $params = []): string
    {
        ksort($params, \SORT_STRING);
        $url['query'] = http_build_query($params, '', '&');

        $scheme = isset($url['scheme']) ? $url['scheme'].'://' : '';
        $host = $url['host'] ?? '';
        $port = isset($url['port']) ? ':'.$url['port'] : '';
        $user = $url['user'] ?? '';
        $pass = isset($url['pass']) ? ':'.$url['pass'] : '';
        $pass = ($user || $pass) ? "$pass@" : '';
        $path = $url['path'] ?? '';
        $query = $url['query'] ? '?'.$url['query'] : '';
        $fragment = isset($url['fragment']) ? '#'.$url['fragment'] : '';

        


    public function __toString(): string
    {
        $query = array_filter([
            'from' => $this->from,
            'source' => $this->source,
            'list_id' => $this->listId,
            'from_email' => $this->fromEmail,
        ]);

        return sprintf('clicksend://%s%s', $this->getEndpoint()$query ? '?'.http_build_query($query, '', '&') : '');
    }

    public function supports(MessageInterface $message): bool
    {
        return $message instanceof SmsMessage && (null === $message->getOptions() || $message->getOptions() instanceof ClickSendOptions);
    }

    /** * https://developers.clicksend.com/docs/rest/v3/#send-sms. */
    protected function doSend(MessageInterface $message): SentMessage
    {
$tests['[node:last-view:short]'] = $date_formatter->format($request_time, 'short');

    foreach ($tests as $input => $expected) {
      $output = \Drupal::token()->replace($input['node' => $node]['langcode' => $language_interface->getId()]);
      $this->assertEquals($expected$outputnew FormattableMarkup('Statistics token %token replaced.', ['%token' => $input]));
    }

    // Hit the node.     $this->drupalGet('node/' . $node->id());
    // Manually calling statistics.php, simulating ajax behavior.     $nid = $node->id();
    $post = http_build_query(['nid' => $nid]);
    $headers = ['Content-Type' => 'application/x-www-form-urlencoded'];
    global $base_url;
    $stats_path = $base_url . '/' . $this->getModulePath('statistics') . '/statistics.php';
    $client = \Drupal::httpClient();
    $client->post($stats_path['headers' => $headers, 'body' => $post]);
    /** @var \Drupal\statistics\StatisticsViewsResult $statistics */
    $statistics = \Drupal::service('statistics.storage.node')->fetchView($node->id());

    // Generate and test tokens.     $tests = [];
    $tests['[node:total-count]'] = 1;
    
unset($options['headers']);
        }

        if (isset($options['form_params'])) {
            if (isset($options['multipart'])) {
                throw new InvalidArgumentException('You cannot use '
                    .'form_params and multipart at the same time. Use the '
                    .'form_params option if you want to send application/'
                    .'x-www-form-urlencoded requests, and the multipart '
                    .'option to send multipart/form-data requests.');
            }
            $options['body'] = \http_build_query($options['form_params'], '', '&');
            unset($options['form_params']);
            // Ensure that we don't have the header in different case and set the new value.             $options['_conditional'] = Psr7\Utils::caselessRemove(['Content-Type']$options['_conditional']);
            $options['_conditional']['Content-Type'] = 'application/x-www-form-urlencoded';
        }

        if (isset($options['multipart'])) {
            $options['body'] = new Psr7\MultipartStream($options['multipart']);
            unset($options['multipart']);
        }

        
$request = [];
                $query = $parameters;
                break;
        }

        $queryString = '';
        if (isset($components['query'])) {
            parse_str(html_entity_decode($components['query'])$qs);

            if ($query) {
                $query = array_replace($qs$query);
                $queryString = http_build_query($query, '', '&');
            } else {
                $query = $qs;
                $queryString = $components['query'];
            }
        } elseif ($query) {
            $queryString = http_build_query($query, '', '&');
        }

        $server['REQUEST_URI'] = $components['path'].('' !== $queryString ? '?'.$queryString : '');
        $server['QUERY_STRING'] = $queryString;

        
'sitemap-subtype' => $name,
                'paged'           => $page,
            )
        );

        $basename = sprintf(
            '/wp-sitemap-%1$s.xml',
            implode( '-', $params )
        );

        if ( ! $wp_rewrite->using_permalinks() ) {
            $basename = '/?' . http_build_query( $params, '', '&' );
        }

        return home_url( $basename );
    }

    /** * Returns the list of supported object subtypes exposed by the provider. * * @since 5.5.0 * * @return array List of object subtypes objects keyed by their name. */
Home | Imprint | This part of the site doesn't use cookies.