Closed (outdated)
Project:
Chaos Tool Suite (ctools)
Version:
7.x-1.x-dev
Component:
Plugins system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
2 Oct 2015 at 15:00 UTC
Updated:
20 Jul 2026 at 17:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
xanoComment #3
donquixote commentedI imagine there could be cases where the class_exists() is not reliable.
E.g. it can happen that the class file was already included for the current request, but maybe this was because it was previously in the registry.
I propose instead to check for namespace separators in the class name.
Currently the registry does not detect such classes anyway. So there is no point in adding the class file in hook_registry_files_alter().
(The Registry autoload module does in fact use the core registry for namespaced classes. But it does not use hook_registry_files_alter(). Instead it writes the mappings directly into the database.)
This aside, I do support the direction of this change.
Comment #4
donquixote commentedThis would mean the second more verbose structure with ['class'], ['file'] and ['path'] does not make much sense if ['class'] has namespaces. Maybe we want to warn the user? But maybe for a start it is good enough to just ignore the file and path in this case.
Comment #5
xanoThe reason I went for this particular solution, is that it not only solves my particular problem (using PSR-4 through xautoload), but generally prevents Ctools from enforcing its own approach if that's not actually needed for whatever reason.
Is it possible for a class to be loaded by the registry and then disappear from that same registry during a single request?
Why not? One can use namespaces, but not follow PSR-0 or PSR-4.
Comment #6
donquixote commentedNo.
What I imagine can happen is the following:
So the class files flip-flop between being in the registry and not being in the registry.
I assume not what you intended :)
Using class_exists while building a new registry is bound to be fragile, because it depends on the old registry.
Comment #7
donquixote commentedBecause adding a file with namespaces to the list of files to scan does not really do anything.
Drupal just fails to detect the classes in these files.
Modules with namespaced plugin classes, even if they don't use PSR-0 or PSR-4, already now need their own technique of having these classes autoloaded. They cannot rely on the registry class discovery.
(And again, registry_autoload works in a different way)
Comment #8
xanoI understand, and I think I just ran into this issue.
I'm not sure if this is the best way to check for namespaces in FQNs, but this patch does not seem to collide with the registry, and it prevents namespaced classes from being added to the registry by Ctools itself. It does not fix the problem for non-namespaced classes that do not want to use Ctools registry magic, though. This includes plugin class files that are defined in
*.infofiles.Comment #9
donquixote commentedstrpos() === FALSEseems fine to me.What about checking for
$plugin_definition[$class_key]['file'] === FALSE?So developers can set this to FALSE to suppress the magic.
Comment #10
b-prod commentedThis patch is a mix between the one in comment #8 and the comment of donquixote.
So:
FALSEfor thefilekey.This patch should not cause trouble neither with existing code nor with plugin declared by contributed modules, so it is safe to use.
Comment #11
chris matthews commentedThe 2 year old patch in #10 to registry.inc applied cleanly to the latest ctools 7.x-1.x-dev, but still needs to be reviewed and tested.
Comment #12
japerryDrupal 7 is no longer supported, closing.