Skip to content

Instantly share code, notes, and snippets.

@lucasmezencio
Created April 25, 2012 13:12
Show Gist options
  • Save lucasmezencio/2489606 to your computer and use it in GitHub Desktop.
Save lucasmezencio/2489606 to your computer and use it in GitHub Desktop.
Command Interpreter Example
<?php
require_once __DIR__.'/functions.php';
$commands = array(
'hello' => array(
'params' => array('name')
),
'dump' => array(
'params' => array('var')
)
);
if (isset($_POST['command']) && $_POST['command'] != '') {
if (in_array($_POST['command'])) {
call_user_func($_POST['command'], $_POST['param']);
}
}
<?php
/**
* @author Lucas Mezêncio <lucas.mezencio@gmail.com>
*
* @param string $name
*/
function hello($name) {
echo 'Hello, '.$name;
}
/**
* @author Lucas Mezêncio <lucas.mezencio@gmail.com>
*
* @param mixed $name
*/
function dump($var) {
var_dump($var);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment