function trx_handle() { switch ($_SERVER['REQUEST_METHOD']) { case 'GET': return !empty($_GET['id']) ? showAction() : listAction(); case 'POST': return createAction(); case 'PUT': parse_str(file_get_contents('php://input'), $data); $_POST = $data; return saveAction(); case 'DELETE': return deleteAction(); } return false; }
if ($argc == 1) { printUsage(); } elseif ($argv[1] == '--help') { printHelp(); } else { $scriptName = array_shift($argv); $commandName = array_shift($argv); switch ($commandName) { case 'create:app': createApp($argv); break; case 'create:module': createModule($argv); break; case 'create:action': createAction($argv); break; default: printUsage(); break; } } function printUsage() { print 'Usage: php generator.php [params]' . PHP_EOL; print ' --help for help' . PHP_EOL; } function printHelp() { printUsage(); print ' [params] can be one of the following:' . PHP_EOL;
<?php error_reporting(E_ALL); require_once 'controllers.php'; // Route if ($_SERVER['REQUEST_URI'] === '/new' && $_SERVER['REQUEST_METHOD'] === 'GET') { $response = newAction(); } else { if ($_SERVER['REQUEST_URI'] === '/new' && $_SERVER['REQUEST_METHOD'] === 'POST') { $response = createAction($_POST); } else { // 404; not implemented exit; } } // Send response // Assumes response in the form of ['headers' => [...], 'body' => ...]. foreach ($response['headers'] as $header) { header($header); } echo $response['body'];