Created
January 14, 2014 04:51
-
-
Save itsananderson/8413220 to your computer and use it in GitHub Desktop.
Look up commands by name and invoke the associated function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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