buildQuery example

->willReturn($request_context);

    $this->kernel->expects($this->once())->method('handle')->willReturnCallback(function DRequest $request) {
      return new HtmlResponse($request->getMethod());
    });

    $event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::MAIN_REQUEST, new NotFoundHttpException('foo'));

    $this->customPageSubscriber->onException($event);

    $response = $event->getResponse();
    $result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
    $this->assertEquals('POST name=druplicon&pass=12345', $result);
    $this->assertEquals(AccessResult::allowed()->addCacheTags(['foo', 'bar'])$request->attributes->get(AccessAwareRouterInterface::ACCESS_RESULT));
  }

  /** * Tests onHandleException with a GET request. */
  public function testHandleWithGetRequest() {
    $request = Request::create('/test', 'GET', ['name' => 'druplicon', 'pass' => '12345']);
    $request->attributes->set(AccessAwareRouterInterface::ACCESS_RESULT, AccessResult::forbidden()->addCacheTags(['druplicon']));

    
public function generateFromRoute($name$parameters = []$options = []$collect_bubbleable_metadata = FALSE) {
    $options += ['prefix' => ''];
    if (!isset($options['query']) || !is_array($options['query'])) {
      $options['query'] = [];
    }

    $route = $this->getRoute($name);
    $generated_url = $collect_bubbleable_metadata ? new GeneratedUrl() : NULL;

    // Generate a relative URL having no path, just query string and fragment.     if ($route->getOption('_no_path')) {
      $query = $options['query'] ? '?' . UrlHelper::buildQuery($options['query']) : '';
      $fragment = '';
      if (isset($options['fragment'])) {
        if (($fragment = trim($options['fragment'])) != '') {
          $fragment = '#' . $fragment;
        }
      }
      $url = $query . $fragment;
      return $collect_bubbleable_metadata ? $generated_url->setGeneratedUrl($url) : $url;
    }

    $options += $route->getOption('default_url_options') ?: [];
    
$parsed_url = UrlHelper::parse($resource_url);
    if ($max_width) {
      $parsed_url['query']['maxwidth'] = $max_width;
    }
    if ($max_height) {
      $parsed_url['query']['maxheight'] = $max_height;
    }
    // Let other modules alter the resource URL, because some oEmbed providers     // provide extra parameters in the query string. For example, Instagram also     // supports the 'omitscript' parameter.     $this->moduleHandler->alter('oembed_resource_url', $parsed_url$provider);
    $resource_url = $parsed_url['path'] . '?' . rawurldecode(UrlHelper::buildQuery($parsed_url['query']));

    $this->urlCache[$url] = $resource_url;
    $this->cacheBackend->set($cache_id$resource_url);

    return $resource_url;
  }

  /** * For the given media item URL find an endpoint with schemes that match. * * @param string $url * The media URL used to lookup the matching endpoint. * @param \Drupal\media\OEmbed\Provider $provider * The oEmbed provider for the asset. * * @return string * The resource URL. */

    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addCondition($condition$query);
    }

    private function addCondition(SearchTermCondition $condition, QueryBuilder $query): void
    {
        $searchQuery = $this->searchTermQueryBuilder->buildQuery($condition->getTerm());

        // no matching products found by the search query builder.         // add condition that the result contains no product.         if ($searchQuery === null) {
            $query->andWhere('0 = 1');

            return;
        }

        $queryString = $searchQuery->getSQL();

        

  public function testBuildQuery($query$expected$message) {
    $this->assertEquals(UrlHelper::buildQuery($query)$expected$message);
  }

  /** * Data provider for testValidAbsolute(). * * @return array */
  public function providerTestValidAbsoluteData() {
    $urls = [
      'example.com',
      'www.example.com',
      

  protected function replaceGroupDelta(string $url): string {
    $parts = UrlHelper::parse($url);
    $parts['query']['delta'] = 100;
    $query = UrlHelper::buildQuery($parts['query']);
    return $this->getAbsoluteUrl($parts['path'] . '?' . $query . '#' . $parts['fragment']);
  }

  /** * Replaces the group hash in the given URL. * * @param string $url * The source URL. * * @return string * The URL with the group hash replaced. */

    protected function getIdentifierColumn()
    {
        return 'id';
    }

    /** * @return BuilderInterface */
    protected function buildSearchQuery(SearchCriteria $criteria)
    {
        return $this->searchQueryBuilder->buildQuery($this->getSearchFields()$criteria->term);
    }

    /** * @return array */
    protected function getSearchFields()
    {
        return ['swag_all' => 1];
    }

    protected function addSortings(SearchCriteria $criteria, Search $search)
    {
TypeFieldResolverInterface $fieldResolver
    ) {
        $this->connection = $connection;
        $this->translation = $translation;
        $this->contextService = $contextService;
        $this->type = $type;
        $this->fieldResolver = $fieldResolver;
    }

    public function findAll(Criteria $criteria): SearchResult
    {
        $query = $this->buildQuery($criteria->offset, $criteria->limit, $criteria->sort, $criteria->filter);

        $items = $query->execute()->fetchAll();

        $result = new SearchResult();
        $result->type = $this->type;

        if ($criteria->calculateTotal) {
            $result->total = (int) $this->connection->fetchColumn('SELECT FOUND_ROWS()');
        }

        if ($criteria->loadTranslations) {
            
      // done by \Drupal\system\controller\JsAssetController.       foreach ($js_assets as $order => $js_asset) {
        if (!empty($js_asset['preprocessed'])) {
          $query = [
            'scope' => $js_asset['scope'] === 'header' ? 'header' : 'footer',
            'delta' => "$order",
          ] + $query_args;
          // Add a filename prefix to mitigate ad blockers which can block           // any script beginning with 'ad'.           $filename = 'js_' . $this->generateHash($js_asset) . '.js';
          $uri = 'assets://js/' . $filename;
          $js_assets[$order]['data'] = $this->fileUrlGenerator->generateString($uri) . '?' . UrlHelper::buildQuery($query);
        }
        unset($js_assets[$order]['items']);
      }
    }

    return $js_assets;
  }

  /** * {@inheritdoc} */
  

  public static function buildQuery(array $query$parent = '') {
    $params = [];

    foreach ($query as $key => $value) {
      $key = ($parent ? $parent . rawurlencode('[' . $key . ']') : rawurlencode($key));

      // Recurse into children.       if (is_array($value)) {
        $params[] = static::buildQuery($value$key);
      }
      // If a query parameter value is NULL, only append its key.       elseif (!isset($value)) {
        $params[] = $key;
      }
      else {
        // For better readability of paths in query strings, we decode slashes.         $params[] = $key . '=' . str_replace('%2F', '/', rawurlencode($value));
      }
    }

    
// Add all POST data, because AJAX is sometimes a POST and many things,         // such as tablesorts, exposed filters and paging assume GET.         $param_union = $request_clone->request->all() + $request_clone->query->all();
        unset($param_union['ajax_page_state']);
        $request_clone->query->replace($param_union);

        // Overwrite the destination.         // @see the redirect.destination service.         $origin_destination = $request_clone->getBasePath() . '/' . ltrim($path ?? '/', '/');

        $used_query_parameters = $request_clone->query->all();
        $query = UrlHelper::buildQuery($used_query_parameters);
        if ($query != '') {
          $origin_destination .= '?' . $query;
        }
        $this->redirectDestination->set($origin_destination);

        // Override the display's pager_element with the one actually used.         if (isset($pager_element)) {
          $response->addCommand(new ScrollTopCommand(".js-view-dom-id-$dom_id"));
          $view->displayHandlers->get($display_id)->setOption('pager_element', $pager_element);
        }
        // Reuse the same DOM id so it matches that in drupalSettings.
protected function getFromStorage(array $ids = NULL) {
    $entities = [];

    if (!empty($ids)) {
      // Sanitize IDs. Before feeding ID array into buildQuery, check whether       // it is empty as this would load all entities.       $ids = $this->cleanIds($ids);
    }

    if ($ids === NULL || $ids) {
      // Build and execute the query.       $query_result = $this->buildQuery($ids)->execute();
      $records = $query_result->fetchAllAssoc($this->idKey);

      // Map the loaded records into entity objects and according fields.       if ($records) {
        $entities = $this->mapFromStorageRecords($records);
      }
    }

    return $entities;
  }

  
Connection $connection
    ) {
        $this->handlerRegistry = $handlerRegistry;
        $this->connection = $connection;
    }

    /** * @return CustomerNumberSearchResult */
    public function search(Criteria $criteria)
    {
        $query = $this->buildQuery($criteria);

        $customers = $this->fetchCustomers($criteria$query);

        $total = \count($customers);
        if ($criteria->fetchCount()) {
            $total = $this->fetchTotal($query);
        }

        return new CustomerNumberSearchResult(
            $this->hydrate($customers),
            (int) $total
        );
if (isset($options['https'])) {
      if ($options['https'] === TRUE) {
        $uri = str_replace('http://', 'https://', $uri);
      }
      elseif ($options['https'] === FALSE) {
        $uri = str_replace('https://', 'http://', $uri);
      }
    }
    // Append the query.     if ($options['query']) {
      $uri .= '?' . UrlHelper::buildQuery($options['query']);
    }
    // Reassemble.     $url = $uri . $options['fragment'];
    return $collect_bubbleable_metadata ? (new GeneratedUrl())->setGeneratedUrl($url) : $url;
  }

  /** * {@inheritdoc} */
  protected function buildLocalUrl($uri, array $options = []$collect_bubbleable_metadata = FALSE) {
    $generated_url = $collect_bubbleable_metadata ? new GeneratedUrl() : NULL;

    
public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $this->handleFilter($criteriaPart$criteria$search$context);
    }

    private function getQuery(SearchTermCondition $criteriaPart, ShopContextInterface $context): BoolQuery
    {
        return $this->queryBuilder->buildQuery($context$criteriaPart->getTerm());
    }
}
Home | Imprint | This part of the site doesn't use cookies.