Autoloader idea
-
Andreas Flack
Autoloader idea
Fri October 03 2008 16:36:08 UTCHi!
While trying to sort out openpsa's dependency problems, I thought about
a way to load libraries less often: Since they generally have a file
called main.php, which includes a class named like the component, we
could load the library automatically when the main class is called,
which should allow us to remove a couple (or even all)
autoload_libraries entries.
The patch looks like this:
Index: midcom/midcom.core/midcom.php
===================================================================
--- midcom/midcom.core/midcom.php (revision 17897)
+++ midcom/midcom.core/midcom.php (working copy)
@@ -171,6 +171,12 @@
debug_add("Autoloader got '{$original_path}' and tried
{$path} but neither was not found, aborting");
return;
}
+ else
+ {
+ // This is the main class of a purecode component, try to
load it
+ $component = str_replace("_", ".", $class_name);
+ $_MIDCOM->load_library($component);
+ }
}
require($path);
I just tested this on my server, and it works as intended. The only
drawback when compared to loading at component initialization I
encountered was that add_link_head calls do not work when the library is
loaded from within a style element, but this should be easily fixable by
changing the affected handler code.
I don't know if I missed anything, but if not, I'd like to check this in
next week
Bye,
Andreas
_______________________________________________
dev mailing list
dev@lists.midgard-project.org
http://lists.midgard-project.org/mailman/listinfo/dev
