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())
{
// You'll want to change this to whatever makes the most sense for you.
$this->pluginDir = isset($config['plugin_dir']) ? $config['plugin_dir'] : '';
// ...
}
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)
{
return isset(static::$run_actions[$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.