CodyKochmann
5/9/2017 - 8:08 PM

This is a server that imports all neighboring php files in the same directory that it sits and offers all functions found in those files as

This is a server that imports all neighboring php files in the same directory that it sits and offers all functions found in those files as xmlrpc services.

<?php

/* @Name:    microservices.php
 * @Author:  Cody Kochmann
 * @Date:    2017-05-09 15:54:10
 * @Description:
 *
 *     This is a server that imports all neighboring
 *     php files in the same directory that it sits
 *     and offers all functions found in those files
 *     as xmlrpc services.
 */

# include all php files in the directory other than this
foreach (scandir('./') as $file) {
    if ((substr($file, -strlen('.php'))==='.php') && $file != basename(__FILE__)){
        include_once $file;
    }
}

# this is a built in service that returns a list of
# all of the services offered from this xmlrpc server
function list_services(){
    return get_defined_functions()['user'];
}

#=================================================
#               Server code below
#=================================================
# create the server
$server = xmlrpc_server_create();
# register every defined function as a xmlrpc_service
foreach (get_defined_functions()['user'] as $f) {
    xmlrpc_server_register_method($server,$f,$f);
}
# set the content type to xml
header('Content-Type: text/xml');
# run the service and return the output through print
print xmlrpc_server_call_method($server, file_get_contents("php://input"), array());

?>