Closed Raruto closed 4 years ago
BTW, maybe the following would be a better solution?
WP_Dependency_Installer::instance()->register( $config );
WP_Dependency_Installer::instance()->run( __DIR__ );
I don't like passing the JSON into the variable only to decode it. Using this framework implies some amount of capability. Creating an associative array doesn't seem like a huge thing. I think the solution is for better documentation.
I also think moving the load_hook()
from run()
to register()
makes more sense. It would also make the extra call to both, as above, unnecessary.
So if using a JSON file then run( __DIR__ )
and if using an array register( array )
Creating an associative array doesn't seem like a huge thing. I think the solution is for better documentation.
It's just for simplicity, JSON configs are just more practical...
For example, in my other plugin, I had created a bulk action for an easy export / generation of this json file (directly from a live wordpress instance):
and they can also be more error-proof in the case of a manual conversion / generation ...
I think the purpose being able to load a config programmatically is really just for those developers who don't want to create a JSON config file for whatever reason.
In that regard it's probably better to use an optional parameter and continue using the same function as you have in this PR.
So something like.
include_once( __DIR__ . '/vendor/autoload.php' );
// Current workflow:
// WP_Dependency_Installer::instance()->run( __DIR__ );
$config = [
[
'name' => 'Query Monitor',
'host' => 'wordpress',
'slug' => 'query-monitor/query-monitor.php',
'uri' => 'https://wordpress.org/plugins/query-monitor/',
'require' => true,
],
[
'name' => 'Debug Bar',
'host' => 'wordpress',
'slug' => 'debug-bar/debug-bar.php',
'uri' => 'https://wordpress.org/plugins/debug-bar/',
'optional' => true,
],
];
// Alternative workflow?
WP_Dependency_Installer::instance()->run( __DIR__, $config );
Though I guess it really doesn't matter as the user could create the $config
variable in either manner.
Maybe I found a better solution, could you reopen this pull?
// Next major release.
WP_Dependency_Installer::instance( __DIR__ )->register( $config );
WP_Dependency_Installer::instance( __DIR__ )->run();
// Backwards compatibility releases.
WP_Dependency_Installer::instance()->register( $config, __DIR__ );
WP_Dependency_Installer::instance()->run( __DIR__ );
I reverted the merge but not sure that re-opens the PR
Related to https://github.com/afragen/wp-dependency-installer/issues/43, adds an optional second parameter within the
run()
function to allow us to abstract from its contents.Example of usage: