Skip to content

Instantly share code, notes, and snippets.

@Darkflib
Created December 16, 2011 20:20
Show Gist options
  • Save Darkflib/1487788 to your computer and use it in GitHub Desktop.
Save Darkflib/1487788 to your computer and use it in GitHub Desktop.
plugins in php
<?php
print_r($_SERVER);
define('PLUGINDIR','./plugin.d/');
foreach (glob(PLUGINDIR."*.php") as $filename) {
require_once($filename);
$basename=substr($filename,strlen(PLUGINDIR),-4);
$funcname='plugin_'.$basename;
$result[$basename]=$funcname();
}
$jsonresult = json_encode($result);
echo $jsonresult."\n";
?>
//...and a plugin...
<?php
function plugin_mike() {
$foo=array();
for ($i=1;$i<=20;$i++) {
$foo[]=md5($i);
}
return array('aardvarks' => "mike", 'foo' => $foo);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment