<?php require_once __DIR__ . '/vendor/autoload.php'; $router = new \Bramus\Router\Router(); $router->get('/', function () { // do something clever if (file_exists("index.html")) { echo file_get_contents("index.html"); } else { echo "index file not found."; } }); $router->get('/js/index.js', function () { // do something clever if (file_exists("index.js")) { echo file_get_contents("index.js"); } else { echo "index.js file not found."; } return $response; }); $router->post('/post/url', function () { $serviceName = filter_input(INPUT_POST, "sel-service"); $longUrl = filter_input(INPUT_POST, "longUrl"); if (isset($serviceName) && isset($longUrl)) { $key = file_get_contents("auth/key.txt"); $key = json_decode($key, true); if ($serviceName === "goo.gl") { $config = array('service-name' => $serviceName, 'longUrl' => $longUrl, 'apiKey' => $key[$serviceName]); } else { if ($serviceName === "bit.ly") {
public function testSubrouteMouting() { // Create Router $router = new \Bramus\Router\Router(); $router->mount('/movies', function () use($router) { $router->get('/', function () { echo 'overview'; }); $router->get('/(\\d+)', function ($id) { echo htmlentities($id); }); }); // Test the /movies route ob_start(); $_SERVER['REQUEST_URI'] = '/movies'; $router->run(); $this->assertEquals('overview', ob_get_contents()); // Test the /hello/bramus route ob_clean(); $_SERVER['REQUEST_URI'] = '/movies/1'; $router->run(); $this->assertEquals('1', ob_get_contents()); // Cleanup ob_end_clean(); }
} return $arh; } } // Require composer autoloader require __DIR__ . '/vendor/autoload.php'; // Read .env try { $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); } catch (InvalidArgumentException $ex) { // Ignore if no dotenv } $app = new \App\Main(); // Create Router instance $router = new \Bramus\Router\Router(); // Activate CORS function sendCorsHeaders() { header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: Authorization"); header("Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE"); } $router->options('/.*', function () { sendCorsHeaders(); }); sendCorsHeaders(); // Check JWT on /secured routes $router->before('GET', '/secured/.*', function () use($app) { $requestHeaders = apache_request_headers(); if (!isset($requestHeaders['Authorization'])) {
<?php // Require composer autoloader require __DIR__ . '/vendor/autoload.php'; require 'controller/controller.php'; // Create Router instance $router = new \Bramus\Router\Router(); $router->before('GET', '/.*', function () { header('X-Powered-By: router'); }); $router->get('/', function () { echo "Welcome to beautyUniversity JSON api"; }); $router->get('/v1/school/(\\w+)/analytic/(\\w+)', function ($name, $bool) { header('Content-Type: application/json; charset=utf-8'); ob_start("ob_gzhandler"); $req = htmlentities($name); $check = htmlentities($bool); $controller = new myController($req); if ($check === "true") { echo $controller->indexAction("colleges_" . $req); } if ($check === "false") { echo $controller->indexAction("school_" . $req); } }); $router->set404(function () { header('HTTP/1.1 404 Not Found'); echo "invalid request url"; }); $router->run();
<?php // In case one is using PHP 5.4's built-in server $filename = __DIR__ . preg_replace('#(\\?.*)$#', '', $_SERVER['REQUEST_URI']); if (php_sapi_name() === 'cli-server' && is_file($filename)) { return false; } // Include the Router class require_once __DIR__ . '/core/Router.php'; // Include configuration and models require_once __DIR__ . '/includes/config.php'; require_once __DIR__ . '/core/Model.php'; require_once __DIR__ . '/model/Post.php'; require_once __DIR__ . '/model/FeedSource.php'; // Create a Router $router = new \Bramus\Router\Router(); // Custom 404 Handler $router->set404(function () { header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); echo '404, route not found!'; }); // Before Router Middleware $router->before('GET', '/.*', function () { header('Content-Type: application/json'); }); // // Static route: / (homepage) // $router->get('/', function () { // echo ''; // }); $router->mount('/post', function () use($router) { // Route: /posts (fetch all posts)
<?php // In case one is using PHP 5.4's built-in server $filename = __DIR__ . preg_replace('#(\\?.*)$#', '', $_SERVER['REQUEST_URI']); if (php_sapi_name() === 'cli-server' && is_file($filename)) { return false; } // Include the Router class // @note: it's recommended to just use the composer autoloader when working with other packages too require_once __DIR__ . '/../src/Bramus/Router/Router.php'; // Create a Router $router = new \Bramus\Router\Router(); // Custom 404 Handler $router->set404(function () { header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); echo '404, route not found!'; }); // Before Router Middleware $router->before('GET', '/.*', function () { header('X-Powered-By: bramus/router'); }); // Static route: / (homepage) $router->get('/', function () { echo '<h1>bramus/router</h1><p>Try these routes:<p><ul><li>/hello/<em>name</em></li><li>/blog</li><li>/blog/<em>year</em></li><li>/blog/<em>year</em>/<em>month</em></li><li>/blog/<em>year</em>/<em>month</em>/<em>day</em></li><li>/movies</li><li>/movies/<em>id</em></li></ul>'; }); // Static route: /hello $router->get('/hello', function () { echo '<h1>bramus/router</h1><p>Visit <code>/hello/<em>name</em></code> to get your Hello World mojo on!</p>'; }); // Dynamic route: /hello/name $router->get('/hello/(\\w+)', function ($name) {
<?php require 'vendor/autoload.php'; /** * Let the provisioner automatically intervene and reconfigure Apache. This only * happens when users try to access a domain that Apache isn't aware off yet and * the provisioner will then - just in time - install vhost files and reload. */ \LXC\VirtualHost\ApacheProvisioner::check('root', 'root', 'templates/rebuilding.html', 'templates/vhost.conf'); /** * Configure the router. */ $router = new \Bramus\Router\Router(); $t = new \h2o(); # ROUTE /: index listing. $router->get('/', function () use($t) { $t->loadTemplate('templates/listing.html'); print $t->render(array('lxc' => \LXC\Container\Variables::get(), 'vhosts' => \LXC\VirtualHost\Listing::get(), 'hostsoutdated' => \LXC\VirtualHost\Listing::are_hosts_outdated(), 'logfiles' => \LXC\Logging\Files::get(), 'hostname' => gethostname())); }); # ROUTE /php: PHP information. $router->get('/php', function () { phpinfo(); }); # ROUTE /$LOGFILE: tail -f style log viewer. foreach (\LXC\Logging\Files::get() as $logfile) { $path = '/' . $logfile->name; $router->get($path, function () use($t, $logfile) { $t->loadTemplate('templates/logtail.html'); print $t->render(array('file' => $logfile, 'lxc' => \LXC\Container\Variables::get(), 'hostname' => gethostname())); }); $router->get($path . '/(\\d+)', function ($from_line) use($t, $logfile) {
<?php /** * Include required sources from composer. */ require __DIR__ . '/../vendor/autoload.php'; /** * Create simple router to check the request url. */ $router = new \Bramus\Router\Router(); /** * This to validate secure requests and set user permissions. */ $router->before('GET|POST', '(log.*|save.*|imgs.*|google.*)', function () { global $events; global $user; /** * Validate Apache authorization hader with token. */ $requestHeaders = apache_request_headers(); $authorizationHeader = isset($requestHeaders['Authorization']) ? $requestHeaders['Authorization'] : null; if ($authorizationHeader == null) { header('HTTP/1.0 401 Unauthorized'); /** * No authorization header sent. */ $events['auth0']['method'] = 'secure'; $events['auth0']['authorized'] = false; $events['auth0']['api'] = true; $events['auth0']['user'] = false; $events['auth0']['message'] = 'No authorization header sent.';
<?php // CORS when your origin is not localhost you are going to need this or else it will not work. // if you are using it outside of your home network please reconsider the * of allow origin header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: POST, PUT, DELETE, GET, OPTIONS"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, auth, user"); header("Access-Control-Max-Age: 1728000"); // Load the composer autoloader require __DIR__ . '/../../vendor/autoload.php'; \Rhonda\Config::load_file("config", "../../etc/config.json"); // Create Router instance $router = new \Bramus\Router\Router(); // Define controllers include 'modules/gpio/controller.gpio.php'; include 'modules/rfid/controller.rfid.php'; include 'modules/switch/controller.switch.php'; include 'modules/i2c/controller.i2c.php'; include 'modules/onkyo/controller.onkyo.php'; // Define models include 'modules/gpio/model.gpio.php'; include 'modules/rfid/model.rfid.php'; include 'modules/i2c/model.i2c.php'; include 'modules/onkyo/model.onkyo.php'; // Define routes require 'routes.php'; header('Content-Type: application/json'); // Run it! $router->run();