Skip to content

refactor: small improvement in loadInNamespace Autoloader #8553

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

Merged
merged 3 commits into from
Feb 21, 2024

Conversation

ddevsr
Copy link
Collaborator

@ddevsr ddevsr commented Feb 16, 2024

Description
Move function call in nested loop to outside.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@ddevsr ddevsr added the refactor Pull requests that refactor code label Feb 16, 2024
@kenjis
Copy link
Member

kenjis commented Feb 17, 2024

I'm not sure, but the code should be like this?

        foreach ($this->prefixes as $namespace => $directories) {
            if (strpos($class, $namespace) === 0) {
                $relativeClassPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace)));

                foreach ($directories as $directory) {
                    $directory = rtrim($directory, '\\/');

                    $filePath = $directory . $relativeClassPath . '.php';
                    $filename = $this->includeFile($filePath);

                    if ($filename) {
                        return $filename;
                    }
                }
            }
        }

@ddevsr
Copy link
Collaborator Author

ddevsr commented Feb 17, 2024

I'm not sure, but the code should be like this?

        foreach ($this->prefixes as $namespace => $directories) {
            if (strpos($class, $namespace) === 0) {
                $relativeClassPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace)));

                foreach ($directories as $directory) {
                    $directory = rtrim($directory, '\\/');

                    $filePath = $directory . $relativeClassPath . '.php';
                    $filename = $this->includeFile($filePath);

                    if ($filename) {
                        return $filename;
                    }
                }
            }
        }

@kenjis Thankyou suggest, l like that cut unused loop directory if not exists class namespace

@kenjis kenjis merged commit cc9ce52 into codeigniter4:develop Feb 21, 2024
@kenjis
Copy link
Member

kenjis commented Feb 21, 2024

@ddevsr Thank you!

@ddevsr ddevsr deleted the perf-load-namespace branch February 21, 2024 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Pull requests that refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants