The following warnings occurred: | ||||||||||||||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Autoload Classes - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29) +--- Thread: Autoload Classes (/showthread.php?tid=634) Pages:
1
2
|
Autoload Classes - firestorm - 07-07-2017 I've implemented autoloading classes, drop your class file into classes folder and away you go, see gist below which has a readme.txt and class.autoloader.php, just put the class file into classes folder, open init and remove all classes called with require_once() and in their place require the class.autoloader.php file: Code: require_once ABS_TR_ROOT.TR_URL_ROOT.'users/classes/class.autoloader.php'; thats it, classes will be required only when they are needed, we have only one require rather than multiple reducing overhead. try it out by placing Code: bold("<br><br> Hoorah my class is included !"); https://gist.github.com/Firestorm-Graphics/98f80b2b45c591d107c35c5f7e5c8632 NOTE: chunk6.php is only for userspice installation files Autoload Classes - mudmin - 07-09-2017 This is cool. I will check it out. We had autoload when we used composer but when I took away composer, some of the other autoloading techniques gave people fits. I'll give this one a whirl. Autoload Classes - firestorm - 07-09-2017 so far its autoloading userspice classes fine, not ran into any problems so far, im also working on a hooks & filters class ( it works exactly like wordpress's hooks & filters ) so we can register a hook to place in the header for example: <pre> Code: function my_header { then we can create our header function to output meta tags for example: <pre> Code: function my_meta { the beauty of this is we can use filters or remove the action especially usefull in custom functions in usersc folder, we can use it for menu's, headers, footers etc its realy is unlimited Autoload Classes - mudmin - 07-09-2017 I like it. Autoload Classes - firestorm - 07-09-2017 paving the way for extentions Autoload Classes - firestorm - 07-13-2017 After testing I've found we need to have autoload required BEFORE session_start(); all current us classes loaded up fine but the hooks class I'm working on wouldnt load unless before session_start() and i suspect that could happen with classes in the future, so it will be best to NOT include in chunk6.php in stall files but instead require at the top of init.php BEFORE session_start(); i have updated the gist Code: require_once 'classes/class.autoloader.php'; will open new thread regarding hooks & filters Autoload Classes - mudmin - 07-13-2017 So that's one of those things we have to decide how we're going to handle since everyone would have to edit their init files. If some people have auto-loaded classes and some don't, we won't be able to make assumptions going forward that if we drop in a class (which I have a few coming out) that everyone will have them loaded properly. Autoload Classes - firestorm - 07-13-2017 well thats where its quite cool, the autoload class loads only if not loaded, I've tested the autoload required at the top of init.php along with the classes manual required at the same time and all good not issues, in an update we can have a patch file that works like your db patch files which will hold this which places the require to the top of init.php: <pre> Code: <?php Autoload Classes - karsen - 07-15-2017 I like this better than my super-simple autoloader I put in place. I'll see about adding this in to my project sometime this week. I also agree with making a patch file for it; anyone who has modified their init.php should be skilled enough to make the changes listed on Firestorm's git page to add this in without disrupting their init changes (hopefully!). Autoload Classes - mudmin - 07-15-2017 A lot of these changes will be rolling out into the main project next week for those who don't want to patch manually. Thanks for everyone holding down the fort over the summer! |