Skip to content

Bug: Superglobals does not fully support actions #9392

Open
@neznaika0

Description

@neznaika0
Contributor

PHP Version

8.3

CodeIgniter4 Version

4.6

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

Linux

Which server did you use?

cli-server (PHP built-in webserver)

What happened?

At the moment, Superglobals looks like a stub. There are no necessary actions:

  1. There is no getting all the values as an array. For example, to replace it in the Router: $this->globals['server'] = $_SERVER;

    if ($host !== null) {
    $request = service('request');
    $_SERVER = $request->getServer();
    $_SERVER['HTTP_HOST'] = $host;
    $request->setGlobal('server', $_SERVER);
    }

  2. The server() method can return not only a string, but also string|int|float|array. Array for argv, float for REQUEST_TIME

    public function server(string $key): ?string

  3. Keys cannot be deleted as unset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])

    unset($_ENV['CI_ENVIRONMENT'], $_SERVER['CI_ENVIRONMENT']);

  4. Something important is in the process..

To upgrade to Superglobals, you need to check the all code. Because in many places, $_SERVER is overwritten. I'll try to get started.

I could send a PR, but I need to understand what to do. Is the function that I described enough for this?

I'm really sorry, this is more of a feature request. But I have problems accessing the forum.

Activity

added
bugVerified issues on the current code behavior or pull requests that will fix them
on Jan 9, 2025
mergeable

mergeable commented on Jan 9, 2025

@mergeable
neznaika0

neznaika0 commented on Jan 9, 2025

@neznaika0
ContributorAuthor

@paulbalandan @samsonasik Has a policeman appeared? 😄

samsonasik

samsonasik commented on Jan 9, 2025

@samsonasik
Member

@paulbalandan it seems due to mergeable PR:

@neznaika0 let's reopen

michalsn

michalsn commented on Jan 10, 2025

@michalsn
Member

From what I see, the Superglobals class was created with the intention to handle all superglobals, so I guess the idea of using it is fine. However, currently, it's used only with the SiteURIFactory class and is handling only these superglobals used for URL manipulation.

We can ask @kenjis if there was a reason we didn't pursue this further. He is definitely the best-oriented person in this area (as the author) so his opinion can save us some time.

michalsn

michalsn commented on Jan 10, 2025

@michalsn
Member

@neznaika0 What exactly are the problems with accessing the forum?

neznaika0

neznaika0 commented on Jan 10, 2025

@neznaika0
ContributorAuthor

@kenjis has been very busy for a long time. We could first describe the interface and then implement the methods. It seems to me that it would be possible to extend ArrayObject or Iterable... The task is to hide the array in an object

I opened a topic in the Lounge on the forum. Cloudflare Encrypted Client Hello (ECH) was banned in my country. I'm 50/50% open to a forum or a long wait. Sometimes it opens normally

removed
bugVerified issues on the current code behavior or pull requests that will fix them
on Jan 11, 2025
neznaika0

neznaika0 commented on Jan 22, 2025

@neznaika0
ContributorAuthor

@kenjis can I say a few words about the development of the service?
I see it differently.

Add a new Parameters class to replace the array with the get(), set(), has(), count() and other methods. It can be extended to InputParameters and ServerParameters. Because they have restrictions on the scalar type of the value.

Replace $_SERVER, $_POST, $_GET, $_REQUEST (may be $_COOKIE) with the Parameters object.

Extends Superglobals. So that the parameters are saved during the request. Most likely as a static object (Services function)

Do I still need to think about rewriting $_***. Only in Request or otherwise?

kenjis

kenjis commented on Jan 22, 2025

@kenjis
Member

From what I see, the Superglobals class was created with the intention to handle all superglobals, so I guess the idea of using it is fine. However, currently, it's used only with the SiteURIFactory class and is handling only these superglobals used for URL manipulation.

Yes, it was created with the intention to handle all superglobals ($_***).
So we should use it in all places.

Now it's used only with the SiteURIFactory class, because replacing all the code base was too big task.

neznaika0

neznaika0 commented on Jan 22, 2025

@neznaika0
ContributorAuthor

If there's time, I'll try to show you a draft with an update. This substitution will improve testability. But there are doubts about $_ENV.
I've studied Symfony a bit, I think it will be possible to implement it in CI.

changed the title [-]Bug: Supeglobals does not fully support actions[/-] [+]Bug: Superglobals does not fully support actions[/+] on Mar 4, 2025
linked a pull request that will close this issue on Mar 9, 2025
linked a pull request that will close this issuefeat: Improve `Superglobals` service #9482on Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @kenjis@michalsn@samsonasik@neznaika0

      Issue actions

        Bug: Superglobals does not fully support actions · Issue #9392 · codeigniter4/CodeIgniter4