/** * @param IfwPsn_Wp_Plugin_Manager $pm */ public static function load(IfwPsn_Wp_Plugin_Manager $pm) { if (!$pm->getEnv()->isCli()) { // die if not command line accessed die('Invalid access'); } $args = $_SERVER['argv']; $command = $args[1]; $args = array_slice($args, 2); $executable = 'script'; if ($pm->getEnv()->isWindows()) { $executable .= '.bat'; } else { $executable .= '.sh'; } try { // try to execute a command $cliCommand = IfwPsn_Wp_Plugin_Cli_Factory::getCommand($command, $args, $pm); $cliCommand->setExecutable($executable); $cliCommand->execute(); } catch (IfwPsn_Wp_Plugin_Cli_Factory_Exception $e) { echo 'Initialization error: ' . $e->getMessage(); } catch (IfwPsn_Wp_Plugin_Cli_Command_Exception_MissingOperand $e) { // fetch MissingOperand exception echo $executable . ' ' . $command . ': missing operand'; echo PHP_EOL; echo $e->getMessage(); } catch (IfwPsn_Wp_Plugin_Cli_Exception $e) { // fetch generell cli exception echo $e->getMessage(); } }
/** * @param IfwPsn_Wp_Plugin_Manager $pm */ protected static function _loadCliCommand($command, IfwPsn_Wp_Plugin_Manager $pm) { $headline = '### %s %s CLI ###' . PHP_EOL . PHP_EOL; printf($headline, $pm->getEnv()->getName(), $pm->getEnv()->getVersion()); $args = $_SERVER['argv']; $args = array_slice($args, 2); $executable = 'script'; if ($pm->getEnv()->isWindows()) { $executable .= '.bat'; } else { $executable .= '.sh'; } try { // try to execute a command $cliCommand = IfwPsn_Wp_Plugin_Cli_Factory::getCommand($command, $args, $pm); $cliCommand->setExecutable($executable); // load the cli command after WP is completely loaded add_action('wp_loaded', array($cliCommand, 'execute')); } catch (IfwPsn_Wp_Plugin_Cli_Factory_Exception $e) { echo 'Initialization error: ' . $e->getMessage(); } catch (IfwPsn_Wp_Plugin_Cli_Command_Exception_MissingOperand $e) { // fetch MissingOperand exception echo $executable . ' ' . $command . ': missing operand'; echo PHP_EOL; echo $e->getMessage(); } catch (IfwPsn_Wp_Plugin_Cli_Exception $e) { // fetch generell cli exception echo $e->getMessage(); } }