Programming Language PHP

Namespace Oro\Component\PhpUtils

Class QueryStringUtil

Total Examples 8

8 code examples of PHP Oro\Component\PhpUtils\QueryStringUtil extracted from open source projects

Was this example useful?
0
                                                    public function testBuildQueryStringWithObjectParameterValue()
    {
        $this->expectException(\UnexpectedValueException::class);
        $this->expectExceptionMessage('Expected string value for the parameter "prm1", given "stdClass".');

        QueryStringUtil::buildQueryString(['prm1' => new \stdClass()]);
    }
                                            
Was this example useful?
0
                                                    public function testBuildQueryStringWithArrayParameterValue()
    {
        $this->expectException(\UnexpectedValueException::class);
        $this->expectExceptionMessage('Expected string value for the parameter "prm1", given "array".');

        QueryStringUtil::buildQueryString(['prm1' => []]);
    }
                                            
Was this example useful?
0
                                                    public function testBuildQueryStringWithNotStringScalarParameterValue()
    {
        $this->expectException(\UnexpectedValueException::class);
        $this->expectExceptionMessage('Expected string value for the parameter "prm1", given "integer".');

        QueryStringUtil::buildQueryString(['prm1' => 0]);
    }
                                            
Was this example useful?
0
                                                    public function testBuildQueryStringWithNullParameterValue()
    {
        $this->expectException(\UnexpectedValueException::class);
        $this->expectExceptionMessage('Expected string value for the parameter "prm1", given "NULL".');

        QueryStringUtil::buildQueryString(['prm1' => null]);
    }
                                            
Was this example useful?
0
                                                    /**
     * @inheritdoc
     */
    public function getHref(DataAccessorInterface $dataAccessor): ?string
    {
        $pageNumber = null;
        if (!$dataAccessor->tryGetValue(ConfigUtil::PAGE_NUMBER, $pageNumber)) {
            // the pagination is not supported
            return null;
        }
        if ($pageNumber <= 1) {
            // the link to the previous page is not needed
            return null;
        }

        $prevPageNumber = $pageNumber - 1;
        $baseUrl = parent::getHref($dataAccessor);
        $queryString = null !== $this->queryStringAccessor
            ? $this->queryStringAccessor->getQueryString()
            : '';
        if ($prevPageNumber > 1) {
            $queryString = QueryStringUtil::addParameter(
                $queryString,
                $this->pageNumberFilterName,
                (string) $prevPageNumber
            );
        } else {
            $queryString = QueryStringUtil::removeParameter($queryString, $this->pageNumberFilterName);
        }

        return QueryStringUtil::addQueryString($baseUrl, $queryString);
    }
                                            
Was this example useful?
0
                                                    /**
     * @inheritdoc
     */
    public function getHref(DataAccessorInterface $dataAccessor): ?string
    {
        if (!$this->hasMoreRecords($dataAccessor)) {
            return null;
        }

        $pageNumber = null;
        if (!$dataAccessor->tryGetValue(ConfigUtil::PAGE_NUMBER, $pageNumber)
            && null !== $this->queryStringAccessor
        ) {
            // the pagination is not supported
            return null;
        }
        if (null === $pageNumber) {
            $pageNumber = 1;
        }

        $nextPageNumber = $pageNumber + 1;
        $baseUrl = parent::getHref($dataAccessor);
        $queryString = null !== $this->queryStringAccessor
            ? $this->queryStringAccessor->getQueryString()
            : '';
        $queryString = QueryStringUtil::addParameter(
            $queryString,
            $this->pageNumberFilterName,
            (string) $nextPageNumber
        );

        return QueryStringUtil::addQueryString($baseUrl, $queryString);
    }
                                            
Was this example useful?
0
                                                    /**
     * @inheritdoc
     */
    public function getHref(DataAccessorInterface $dataAccessor): ?string
    {
        $pageNumber = null;
        if (!$dataAccessor->tryGetValue(ConfigUtil::PAGE_NUMBER, $pageNumber)) {
            // the pagination is not supported
            return null;
        }
        if ($pageNumber <= 1) {
            // the link to the first page is not needed
            return null;
        }

        $baseUrl = parent::getHref($dataAccessor);
        $queryString = null !== $this->queryStringAccessor
            ? $this->queryStringAccessor->getQueryString()
            : '';
        $queryString = QueryStringUtil::removeParameter($queryString, $this->pageNumberFilterName);

        return QueryStringUtil::addQueryString($baseUrl, $queryString);
    }
                                            
Was this example useful?
0
                                                    /**
     * @inheritdoc
     */
    public function getQueryString(): string
    {
        $this->ensureInitialized();

        $params = [];
        foreach ($this->groups as $group => $items) {
            /** @var FilterValue $item */
            foreach ($items as $item) {
                if (!$item->getSourceKey()) {
                    continue;
                }

                $path = $item->getPath();
                if ($path !== $group) {
                    $path = $group . '[' . implode('][', explode('.', $path)) . ']';
                }
                $operator = $item->getOperator();
                if ('eq' !== $operator) {
                    $path .= '[' . $operator . ']';
                }
                $params[$path] = $item->getSourceValue();
            }
        }

        return QueryStringUtil::buildQueryString($params);
    }
                                            
QueryStringUtil's Other Methods
QueryStringUtil's Other Methods