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

Automatic proxy generation does not work for AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED #11418

Open
dlebech opened this issue Apr 18, 2024 · 0 comments

Comments

@dlebech
Copy link

dlebech commented Apr 18, 2024

Bug Report

Q A
BC Break don't know
Version 3.1.1

Summary

The AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED setting for setAutoGenerateProxyClasses does not update the proxy files.

The bug is here.

The bug is due to the order of the switch cases in the loadProxyClass function in the ProxyFactory.php file.

When the the file has changed, the code falls through to the second case which just checks if the file exists and then breaks, so it never reached the final case.

I have annotated the troublesome code below with "[BUG Explanation]":

switch ($this->autoGenerate) {
    case self::AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED:
        if (file_exists($fileName) && filemtime($fileName) >= filemtime($class->getReflectionClass()->getFileName())) {
            break;
        }
        // [BUG Explanation]: It correctly falls through here to the next case, when the file has changed
    case self::AUTOGENERATE_FILE_NOT_EXISTS:
        if (file_exists($fileName)) {
            // [BUG Explanation]: It reaches this point, because the files exists
            break;
        }
    case self::AUTOGENERATE_ALWAYS:
        // [BUG explanation] It never reaches this point and so the proxy is not generated.
        $this->generateProxyClass($class, $fileName, $proxyClassName);
        break;
}

Again, the code is here.

Current behavior

The proxy classes are not updated automatically, even when their Entity class files are updated, due to the error outlined above.

How to reproduce

  1. Create basic config $config
  2. Set AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED
    • $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS_OR_CHANGED)
  3. Change a model file.
  4. Observe the file does not change.

Expected behavior

The proxy file is updated when the entity class file has changed.

Thank you.

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

No branches or pull requests

1 participant