<?php // Define path to application directory defined('RESOURCE_PATH') || define('RESOURCE_PATH', realpath(dirname(__FILE__) . '/../resources')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array(realpath(realpath(dirname(__FILE__) . '/../../')), get_include_path()))); require '../../../PHPMachine.php'; \PHPMachine\Loader::autoload('MyExample', RESOURCE_PATH, false); \PHPMachine\http_request(dirname(__FILE__) . '/../config/dispatch.conf.php');
<?php namespace PHPMachine; require dirname(__FILE__) . '/src/Loader.php'; \PHPMachine\Loader::autoload(); function http_request($dispatchPath) { $request = new \PHPMachine\Request(); $response = new \PHPMachine\Response(); $response = execute_request($request, $response, $dispatchPath); $response->serve(); } function execute_request(Request $request, Response $response, $dispatchPath) { $dispatchList = (require $dispatchPath); $result = Dispatcher::dispatch($dispatchList, $request); if ($result[0] === false) { $response->set_status_code(404); $body = ErrorHandler::handleError(404, $request, 'Resource was not found'); $response->write($body); return $response; } else { return \PHPMachine\DecisionCore::handleRequest($result[0], $request, $response); } }