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

Add $_GET['q'] #113

Merged
merged 7 commits into from
Dec 20, 2023
Merged

Add $_GET['q'] #113

merged 7 commits into from
Dec 20, 2023

Conversation

darrenoh
Copy link
Contributor

@darrenoh darrenoh commented Nov 17, 2023

Fixes #111.

@darrenoh darrenoh force-pushed the fix-get_q branch 2 times, most recently from 72f1d8a to 78c3c8d Compare November 22, 2023 21:26
@mglaman mglaman changed the title Add $_GET['q']. Fixes #111. Add $_GET['q'] Nov 23, 2023
@mglaman
Copy link
Collaborator

mglaman commented Nov 23, 2023

From RouteProvider:

    $cid = $this->getRouteCollectionCacheId($request);
    if ($cached = $this->cache->get($cid)) {
      $this->currentPath->setPath($cached->data['path'], $request);
      $request->query->replace($cached->data['query']);
      return $cached->data['routes'];
    }
    else {
      // Just trim on the right side.
      $path = $request->getPathInfo();
      $path = $path === '/' ? $path : rtrim($request->getPathInfo(), '/');
      $path = $this->pathProcessor->processInbound($path, $request);
      $this->currentPath->setPath($path, $request);

So the current path is set when the route collection is resolved for the request. So we should remove the constructor logic.

Comment on lines 22 to 28
public function getPath(?Request $request = null): string
{
if (!isset($request)) {
$request = $this->requestStack->getCurrentRequest();
}
if (!isset($this->paths[$request])) {
$this->paths[$request] = ['path' => $request->getPathInfo()];
}
return $this->paths[$request]['path'];
}

public function setPath($path, ?Request $request = null): static
{
if (!isset($request)) {
$request = $this->requestStack->getCurrentRequest();
}
$this->paths[$request] = ['path' => $path];

return $this;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the same logic as the parent, isn't it? It seems more likely that we just need setPath to be

$_GET['q'] = $request->getPathInfo();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not the same logic as the parent. Here we are working with a reference to $_GET['q'] so if D7 code changes $_GET['q'] it will also change D10’s current path.

@darrenoh darrenoh force-pushed the fix-get_q branch 4 times, most recently from 729e34a to 5d5b9af Compare November 24, 2023 05:20
Copy link
Collaborator

@mglaman mglaman left a comment

Choose a reason for hiding this comment

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

A question, just making sure I understand. Is the complexity to allow manipulating $_GET['q] by reference in code? I thought the PR would entail just overriding setPath to do $_GET['q'] = $path

src/Path/CurrentPathStack.php Show resolved Hide resolved
@mglaman mglaman merged commit 8a9e897 into retrofit-drupal:main Dec 20, 2023
3 checks passed
@darrenoh darrenoh deleted the fix-get_q branch December 20, 2023 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing $_GET['q']
2 participants