![]() |
Created a Plugin system for CI3, have at it - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7) +--- Forum: Addins (https://forum.codeigniter.com/forumdisplay.php?fid=13) +--- Thread: Created a Plugin system for CI3, have at it (/showthread.php?tid=63094) |
Created a Plugin system for CI3, have at it - jLinux - 09-25-2015 I needed a decent plugin system, I tried this one, and while im sure it was awesome when it first came out, I had some issues with it (Deprecated functions used, Plugins couldn't be OOP, didn't use a model, etc) So I created my own, and thought id share it: https://github.com/jhyland87/CI3_Plugin_System Ill add a better README later, and some demos and instructions, so just bookmark it for meow. Heres an example plugin.. PHP Code: /** Then to use it, just put a bunch of do_action() functions all over.. PHP Code: // Fire off an action And before you go through the code and tear it apart, I'm just gonna say, I'm a Linux Engineer, not a PHP developer, I just do PHP on my free time, and I'm in the middle of a PHP project that I needed this for. Thanks! P.S. Here are some of the main functions and the comments for them, just because PHP Code: /** RE: Created a Plugin system for CI3, have at it - solidcodes - 09-26-2015 +1 for sharing will review them later. RE: Created a Plugin system for CI3, have at it - jLinux - 09-26-2015 (09-26-2015, 02:40 AM)solidcodes Wrote: +1 for sharing Thanks, could use some input. Iprob should have put this sowhere else, perhaps in the Addons. If a Moderator sees this, feel free to move it RE: Created a Plugin system for CI3, have at it - jLinux - 09-26-2015 Oh, and if anyone wants an AWESOME plugin for JS written by WordPress, let me know. I had to do a lot of digging to find it, its open source, but impossible to find... I found it tucked away in a response to a ticket that was like 30 pages deep in a google search, lol. Its not released by WP yet, but it works AWESOME. Supports actions, filters, priorities, etc RE: Created a Plugin system for CI3, have at it - mwhitney - 09-28-2015 Please don't take this the wrong way. I understand you're primarily a Linux engineer, I just want to point out a few things which might make it easier for you to maintain the code in the long run. - If you name your config file the same as your library (though in all lowercase), CI's loader will load the config file and pass it to your library's constructor. If you modified the constructor to get the argument: PHP Code: public function __construct(array $config = array()) Then you wouldn't need to call the config class through the CI instance in set_plugin_dir(). - Your call in set_plugin_dir() requests a different config item ('plugin_path') from the one set in your plugins config ('plugin_dir'). - Your has_run() method doesn't need the if/else: PHP Code: public function has_run($action) - in print_messages() you have the following: PHP Code: if (@empty(static::$messages[strtolower($type)]) || ! isset(static::$messages[ strtolower($type) ])) I can't think of a condition in which !isset($something) would be true if empty($something) was false. Generally, if both are used in the same statement, isset() is called first because it is faster and can prevent errors in empty(). Since you're suppressing errors on empty() and calling empty() first, I'm not sure what the isset() call is doing for you. - It also seems like print_messages() should use get_messages(), so you don't have multiple pieces of code doing the same thing (and one of the reasons for that is evident here, as the code to get the messages isn't the same even though it should be doing the same thing). - The same basic idea could be applied to installing/loading the plugin(s), as you have at least three methods which build a path to a plugin and load the file (two of which have slightly different error messages, but the same basic error handling, the third, which gets the file's contents rather than including it, has no error handling at all when attempting to read the file). I was also going to go into the use of static for all of the properties, but I really just hope you had some specific need for that outside of CI, because I don't really see the point (when CI loads the class as a singleton) unless you just really like the syntax. RE: Created a Plugin system for CI3, have at it - jLinux - 09-28-2015 @solidcodes Thanks for the pointers! Theres no reason for anyone to take input the "wrong way", unless its clear the intention was more to be an ass than to actually help. But you're right, my primary role is a Linux Engineer, I usually just use PHP for quick solutions to things, (automation typically, or Web tools, then Perl/Bash for CLI tools). However, I'm in the middle of a project for a web app that I've wanted to do for a while now, so I'm learning a lot more PHP than I knew before. Most (not all) of the pointers you gave I kinda already knew, they were just left like that as a result of sloppy coding, except for #1, thats going to be a big help! Ill be sure to incorporate all the above into it and update it, and the plugin_dir/path is an obvious mistake I looked over. As for why they are static, it was first because I created this outside of CI, then when I adapted it for CI, I just left it, because I think static properties are easier to use, and it doesnt really make much of a difference. Thanks for the input! Ive been using it on my CI app and it seems to be working great. granted I havent created too many intense plugins. (And I'm surprised that plugin_dir/path hasn't caused a fatal error, obviously theres a logic error somewhere as well) P.S. You totally busted me for some of the little discrepancies that I hound my co-workers about, if they saw this thread, id never hear the end of it, lol RE: Created a Plugin system for CI3, have at it - sampoyigi - 10-04-2015 Thanks for sharing. I'm definitely going to try it and maybe incorporate it into my project (if i may). RE: Created a Plugin system for CI3, have at it - jLinux - 10-04-2015 (10-04-2015, 05:44 AM)sampoyigi Wrote: Thanks for sharing. I'm definitely going to try it and maybe incorporate it into my project (if i may). Absolutely. If you have anything to contribute, go ahead. And also id keep an eye on the repo, ill be doing a lot of updates. Currently, Plugins have the ability to include a "config" page, as well as "Install" and "Uninstall" methods/resources. I got the config page idea from WordPress, where each plugin has its own configuration page. Also, if you dont want to contribute, but have some ideas or input, let me know! Ill be using this heavily in a project im working on, so ill be making some changes. I may end up using the core code of this for a Laravel project as well, (Unless Laravel has something for this already) RE: Created a Plugin system for CI3, have at it - sampoyigi - 10-04-2015 I have my eyes on the repo already ![]() |