Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!! TASK: Refactor uri helpers #3336

Merged
merged 6 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
TASK: Followup #3316 merge UriHelper's
  • Loading branch information
mhsdesign committed Mar 28, 2024
commit 69d942c01cd40ce01e0ecaf878dfbdb902722bdb
29 changes: 28 additions & 1 deletion Neos.Flow/Classes/Http/Helper/UriHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
* source code.
*/

use Neos\Utility\Arrays;
use Psr\Http\Message\UriInterface;

/**
* Helper to extract information from Uris.
*/
abstract class UriHelper
final class UriHelper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally prefer the other helper, this Helper namespace seems rather pointless.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but there are already a few helpers inside: https://github.com/neos/flow-development-collection/tree/9.0/Neos.Flow/Classes/Http/Helper

and it would be a little less breaking (though I think no one uses the helper)

The other helper (from the merge yesterday) resided directly in the http namespace but at that point I was unaware of the other helpers

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t exactly love the namespace either but idk it does no harm as well.

Btw you added the uri helper as part of the psr7 migration in this place ;) so better keep that location?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I guess better keep the older one, I also just realized that. Shame on me for creating that useless namespace, although back then I planned for more helpers to support using PSR-7 in Flow (but pretty much everything else exists in guzzle so no need for them). tl;dr; kk lets keep this.

{
// this class only has static helpers
private function __construct()
{
}

/**
* @var array
*/
Expand Down Expand Up @@ -105,6 +111,27 @@ public static function uriWithArguments(UriInterface $uri, array $arguments): Ur
return $uri->withQuery($query);
}

/**
* Merges recursively into the current {@see UriInterface::getQuery} these additional query parameters.
*
* @param array $queryParameters
* @return UriInterface A new instance with the additional query.
*/
public static function withAdditionalQueryParameters(UriInterface $uri, array $queryParameters): UriInterface
{
if ($queryParameters === []) {
return $uri;
}
if ($uri->getQuery() === '') {
$mergedQuery = $queryParameters;
} else {
$queryParametersFromUri = [];
parse_str($uri->getQuery(), $queryParametersFromUri);
$mergedQuery = Arrays::arrayMergeRecursiveOverrule($queryParametersFromUri, $queryParameters);
}
return $uri->withQuery(http_build_query($mergedQuery, '', '&'));
}

/**
* @param string $scheme
* @return int|null
Expand Down
37 changes: 0 additions & 37 deletions Neos.Flow/Classes/Http/UriHelper.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Neos\Flow\Tests\Unit\Http;
namespace Neos\Flow\Tests\Unit\Http\Helper;

/*
* This file is part of the Neos.Flow package.
Expand All @@ -12,7 +12,7 @@
*/

use GuzzleHttp\Psr7\Uri;
use Neos\Flow\Http\UriHelper;
use Neos\Flow\Http\Helper\UriHelper;
use Neos\Flow\Tests\UnitTestCase;

class UriHelperTest extends UnitTestCase
Expand Down