Skip to content

Commit

Permalink
bug #29833 [DebugClassLoader] expose proxyfied findFile() method (fan…
Browse files Browse the repository at this point in the history
…cyweb)

This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #29833).

Discussion
----------

[DebugClassLoader] expose proxyfied findFile() method

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

As bad as it is, some third party libraries expect that at least one autoload function will be the Composer one and have behaviors that relies on the public `findFile` method.

When the `DebugClassLoader` wraps the Composer `ClassLoader`, the function `findFile` is currently lost. So it becomes impossible to use the `DebugClassLoader` with these libraries.

This is for example the case in Drupal 😢 (cf https://github.com/drupal/core/blob/83bc30ac4030ed163e1919ca5e12b338a22c87dd/lib/Drupal/Component/ClassFinder/ClassFinder.php).

Fixing these bad implementations in third party libraries can take forever as things move way slower than in Symfony. This is why I think supporting this case directly in Symfony is better. It's easy and will make the `DebugClassLoader` compatible with more cases.

What could be done to go further in this direction would be to proxify any method implementend by wrapped class loaders.

Commits
-------

4f690a3 [DebugClassLoader] Readd findFile() method
  • Loading branch information
fabpot committed Jan 13, 2019
2 parents 78e6f28 + 4f690a3 commit 37c6ae8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Debug/DebugClassLoader.php
Expand Up @@ -124,6 +124,11 @@ public static function disable()
}
}

public function findFile($class): ?string
{
return $this->isFinder ? $this->classLoader[0]->findFile($class) ?: null : null;
}

/**
* Loads the given class or interface.
*
Expand Down

0 comments on commit 37c6ae8

Please sign in to comment.