This issue will implement the runtime environment setup and cleanup for CLI requests. This will utilise the Runtime_Environment_Setup class to setup the WP environment before checks are run, and cleanup the environment once all checks are complete.
Acceptance Criteria
- Add a new
before_wp_load hook with WP_CLI::add_hook() to implement the object-cache.php drop-in file.
- The hook will manually (not using the WP filesystem) add the object-cache.php drop-in file to the wp-content folder.
- Create a
cli.php file in the plugin root.
- This file will be used to setup the
Plugin_Check_Command both early and late in the WordPress load process.
- The file will first check if the
Plugin_Check_Command class exists.
- If it does not this file is running before WordPress has loaded and the command will need to be setup manually.
- This is done by loading the plugin autoload file so the class is available.
- A new
Plugin_Context for the plugin checker is created and passed to the Plugin_Check_Command constructor.
- The
Plugin_Check_Command is then registered to the WordPress CLI.
- If the
Plugin_Check_Command class does exist.
- A check is made to see if the
$context variable exists, which will be set in the Plugin_Main::add_hooks() method.
- A new instance of the
Plugin_Check_Command is created passing the $context to the constructor.
- The
Plugin_Check_Command is then registered to the WordPress CLI.
- Update the
Plugin_Main::add_hooks() method to require_once the cli.php file, instead of adding the command directly to WP_CLI.
- Update the
wp plugin check to run the Runtime_Environment_Setup::setup() method at the start of the commands run process if any runtime check is to be performed. This is to setup the database tables required for runtime checks.
- Update the
wp plugin check to run the Runtime_Environment_Setup::cleanup() method at the end of the commands run process. This will remove the database tables and object-cache.php drop-in file if they exists.
- When running the
wp plugin check command the --require flag can be used to include the cli.php file early to create the object-cache.php file and register the command.
This issue will implement the runtime environment setup and cleanup for CLI requests. This will utilise the
Runtime_Environment_Setupclass to setup the WP environment before checks are run, and cleanup the environment once all checks are complete.Acceptance Criteria
before_wp_loadhook withWP_CLI::add_hook()to implement the object-cache.php drop-in file.cli.phpfile in the plugin root.Plugin_Check_Commandboth early and late in the WordPress load process.Plugin_Check_Commandclass exists.Plugin_Contextfor the plugin checker is created and passed to thePlugin_Check_Commandconstructor.Plugin_Check_Commandis then registered to the WordPress CLI.Plugin_Check_Commandclass does exist.$contextvariable exists, which will be set in thePlugin_Main::add_hooks()method.Plugin_Check_Commandis created passing the$contextto the constructor.Plugin_Check_Commandis then registered to the WordPress CLI.Plugin_Main::add_hooks()method torequire_oncethecli.phpfile, instead of adding the command directly to WP_CLI.wp plugin checkto run theRuntime_Environment_Setup::setup()method at the start of the commands run process if any runtime check is to be performed. This is to setup the database tables required for runtime checks.wp plugin checkto run theRuntime_Environment_Setup::cleanup()method at the end of the commands run process. This will remove the database tables and object-cache.php drop-in file if they exists.wp plugin checkcommand the--requireflag can be used to include thecli.phpfile early to create the object-cache.php file and register the command.