* mu-webapp * * LICENSE * * The BSD 2-Clause License is applied on this source-file. For * further information please refer to * http://www.opensource.org/licenses/BSD-2-Clause or send an * email to andre.moelle@gmail.com. */ include '../classes/Transfer.php'; include '../classes/Template.php'; include '../classes/Dispatcher.php'; include '../classes/Application.php'; include '../application/code/MyApp.php'; header('X-Powered-By: mu-webapp 0.1.3-dev'); if (!isset($_SESSION)) { session_start(); } $self = dirname($_SERVER['PHP_SELF']); $uri = $_SERVER['REQUEST_URI']; if (($pos = strpos($uri, '?')) !== false) { $uri = substr($uri, 0, $pos); } $uri = $self == '/' ? $uri : substr($uri, strlen($self)); $app = new MyApp('../application/', new Transfer()); $app->getTransfer()->setSession($_SESSION)->setCookies($_COOKIE)->setGet($_GET)->setPost($_POST)->setServer($_SERVER); $transfer = $app->run($uri == '/' ? '/index' : $uri); if (!$transfer->wasDispatched()) { $transfer = $app->run('/error/404'); } $_SESSION = $transfer->getSession();
$app->error(function (\Exception $e, $code) use($app) { # use default debug handler if ($app['debug']) { return; } switch ($code) { case 401: $message = '401 - Unauthorized'; break; case 402: $message = '402 - Payment Required'; break; case 403: $message = '403 - Forbidden'; break; case 404: $message = '404 - Not Found'; break; case 405: $message = '405 - Method Not Allowed'; break; case 500: $message = '500 - Internal Server Error'; break; default: $message = 'We are sorry, but something went terribly wrong.'; } return new Response($message); }); $app->run();
<?php /** * Thin is a swift Framework for PHP 5.4+ * * @package Thin * @version 1.0 * @author Gerald Plusquellec * @license BSD License * @copyright 1996 - 2015 Gerald Plusquellec * @link http://github.com/schpill/thin */ namespace Thin; $ini = parse_ini_file(__DIR__ . '/../.env'); defined('FRAMEWORK_DIR') || define('FRAMEWORK_DIR', isset($ini['FRAMEWORK_DIR']) ? $ini['FRAMEWORK_DIR'] : __DIR__ . DIRECTORY_SEPARATOR . '../fwk'); defined('APPLICATION_ENV') || define('APPLICATION_ENV', isset($ini['APPLICATION_ENV']) ? $ini['APPLICATION_ENV'] : 'production'); defined('SITE_NAME') || define('SITE_NAME', isset($ini['SITE_NAME']) ? $ini['SITE_NAME'] : 'project'); defined('LOCAL_DIR') || define('LOCAL_DIR', isset($ini['LOCAL_DIR']) ? $ini['LOCAL_DIR'] : ''); defined('STORAGE_DIR') || define('STORAGE_DIR', isset($ini['STORAGE_DIR']) ? $ini['STORAGE_DIR'] : __DIR__ . '/../app/storage'); require_once FRAMEWORK_DIR . DIRECTORY_SEPARATOR . 'public/init.php'; require_once APPLICATION_PATH . DS . 'Bootstrap.php'; require_once __DIR__ . DS . '../vendor/autoload.php'; require_once __DIR__ . DS . '../app' . DS . 'Bootstrap.php'; Timer::start(); Bootstrap::cli(true); if (!session_id()) { session_start(); } MyApp::run();
} public function registerRoutes() { $this->get('/', function () { return ' <html> <head><title>Demo</title></head> <body> <form method="post" action="foo"> <input type="text" name="v"> <input type="submit"> </form> </body> </html> '; }); $this->post('/foo', function (Request $request) { $v = $request->getPostParameter('v'); if (null === $v) { throw new BadRequestException('parameter "v" missing'); } $response = new JsonResponse(201); $response->setBody(array('status' => 'ok')); return $response; }); } } // run the app and send the response $m = new MyApp(); $m->run()->send();