Skip to content

Instantly share code, notes, and snippets.

@itsananderson
Created January 14, 2014 04:51
Show Gist options
  • Save itsananderson/8413220 to your computer and use it in GitHub Desktop.
Save itsananderson/8413220 to your computer and use it in GitHub Desktop.
Look up commands by name and invoke the associated function
<?php
class WP_SMS_PLUGIN {
var $commands = array(
'post' => array( __CLASS__, 'post_message' ),
'get' => array( __CLASS__, 'get_recent_posts' )
);
public function add_command( $command, $callback ) {
$commands[$command] = $callback;
}
public function execute_command($parsed_sms){
$command = $parsed_sms[1];
if ( isset( $this->commands[$command] ) ) {
call_user_func( $this->commands[$command], $parsed_sms );
} else {
$this->send_sms("unrecognized command");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment