public function testServe() { $routes = Erdiko::getRoutes(); $_SERVER['REQUEST_METHOD'] = 'get'; ob_start(); Toro::serve($routes); $out = ob_get_contents(); ob_end_clean(); //echo "Printing buffer............."; //var_dump($out); //Remove header $pos = strrpos($out, "</header>"); $out = substr($out, $pos + 9); //Remove footer $pos = strrpos($out, '<footer id="footer">'); $out = substr($out, 0, $pos); //var_dump($out); /* $header = file_get_contents($themeFolder.'/templates/page/header.php'); $pos = strrpos($header, 'navbar-brand'); $header = substr($header, 0, $pos); $find = strrpos($return, $header); $this->assertTrue($find != false); */ }
<?php require_once dirname(__FILE__) . '/vendor/autoload.php'; $ok = @session_start(); if (!$ok) { session_regenerate_id(true); session_start(); } $local = new Model_LocalConfig(); if ($local->getHideExceptions()) { ini_set('display_errors', 'Off'); } else { error_reporting(-1); ini_set('display_errors', 'On'); } try { Toro::serve(array("/" => "Controller_PostList", "/available" => "Controller_Available", "/tag/:number/:alpha" => "Controller_Tag", "/login" => "Controller_Login", "/logout" => "Controller_Logout", "/posts" => "Controller_PostList", "/posts/new" => "Controller_PostNew", "/posts/:number/edit" => "Controller_PostEdit", "/posts/:number/notify-comment" => "Controller_PostCommentNotify", "/posts/:number" => "Controller_Post", "/posts/:number/upvote" => "Controller_PostUpvote", "/posts/:number/:alpha" => "Controller_Post", "/profile" => "Controller_Profile", "/users" => "Controller_UserList", "/users-fragment/:number" => "Controller_UserListFragment", "/user/:number/upvote" => "Controller_UserUpvote", "/:string/posts" => "Controller_UserPosts", "/(.*)" => "Controller_UserProfile", "/map" => "Controller_Map", "/map/users" => "Controller_MapUsers", "/search" => "Controller_Search", "/feed" => "Controller_Feed")); } catch (Exception $e) { if ($local->getHideExceptions()) { mail("*****@*****.**", "MageHero Exception: " . $e->getMessage(), $e->getTraceAsString()); die("Uh-oh. Something's not right. Heroes have been deployed to fix it."); } else { throw $e; } }
$link = mysql_connect('localhost', 'root', 'root'); mysql_select_db('db_test_extra', $link); mysql_query('set names utf8'); Toro::serve(array("/hello" => "HelloHandler", "/java/(.*)" => "JavaHandler", "/login/(.*)" => "LoginHandler", "/api/data/(.*)" => "ApiDataHandler", "/api/picasa/(.*)" => "ApiPicasaHandler", "/api/(.*)" => "ApiHandler", "/tpl/admin/(.*)" => "TplAdminHandler", "/tpl/(.*)" => "TplHandler", "/(.*)" => "DefaultHandler")); } else { if ($_SERVER["HTTP_HOST"] == "test02.tmp0230.ml" || $_SERVER["HTTP_HOST"] == "test02.vlan") { define('PATCHPATH', EXTRAPATH . 'patch4the7/'); require_once COMMONPATH . 'init.php'; require_once PATCHPATH . 'patch.php'; //$mydb = new ezSQL_mysql(MYDB_USER, MYDB_PASSWORD, MYDB_NAME, MYDB_HOST); $mydb = new ezSQL_mysql('root', 'root', 'db_test_extra2', 'localhost'); Toro::serve(array("/hello" => "HelloHandler", "/tpl/admin/(.*)" => "TplAdminHandler", "/(.*)" => "DefaultHandler")); } else { if ($_SERVER["HTTP_HOST"] == "test03.tmp0230.ml" || $_SERVER["HTTP_HOST"] == "test03.vlan") { define('PATCHPATH', EXTRAPATH . 'patch4mall/'); require_once COMMONPATH . 'init.php'; require_once PATCHPATH . 'patch.php'; //$mydb = new ezSQL_mysql(MYDB_USER, MYDB_PASSWORD, MYDB_NAME, MYDB_HOST); $mydb = new ezSQL_mysql('root', 'root', 'db_test_extra3', 'localhost'); Toro::serve(array("/tpl/admin/(.*)" => "TplAdminHandler", "/(.*)" => "DefaultHandler")); } } } // patch , for fix the bug tha wordpress cannot been require in functions ----20150715 if ($wp_flag) { require_once "wp-index.php"; } // patch end ?>
<?php session_start(); define("VERSION", "0.3.9"); define("_LOG_COUNT_MAX_", 20); date_default_timezone_set('UTC'); require_once 'system/Toro.php'; require_once 'system/classes.php'; require_once 'system/statusreturn.php'; require_once 'system/simple_html_dom.php'; require_once 'system/sitemaps.php'; ToroHook::add("404", function () { echo json_encode(StatusReturn::E404('404 Not Found!!'), JSON_NUMERIC_CHECK); }); ToroHook::add("404Web", function () { include_once '404.html'; }); Toro::serve(array('/admin/' => 'Init', '/login/' => 'Login', '/logout/' => 'Logout', '/dash/' => 'Dashboard', '/logs/' => 'Logs', '/nav/' => 'Nav', '/nav/update/' => 'Nav', '/footer/' => 'Footer', '/footer/update/' => 'Footer', '/settings/' => 'Settings', '/settings/update/' => 'Settings', '/analytics/' => 'Analytics', '/analytics/update/' => 'Analytics', '/media/' => 'Media', '/media/update/' => 'Media', '/blog/' => 'Blog', '/blog/:alpha/:string/' => 'BlogPost', '/blog/:alpha/' => 'BlogPost', '/dash/:alpha/' => 'Dashboard', '/page/:alpha/' => 'Pages', '/page/:alpha/update/' => 'Pages', '/page/:alpha/desc/' => 'Description', '/page/:alpha/repeat/:key/' => 'Repeat', '/page/:alpha/repeat/:key/update/' => 'Repeat', '/page/:alpha/repeat-dup/:key/:number/' => 'RepeatDup', '/page/:alpha/repeat-del/:key/:number/' => 'RepeatDel'));
public function route(array $mappings) { // Routing \Toro::serve($mappings); }
<?php require 'Helpers.php'; require 'DBase.php'; require 'Toro.php'; // Require all files in Logic folder foreach (glob('Logic' . DIRECTORY_SEPARATOR . '*.php') as $file) { require $file; } ToroHook::add("404", function () { new Error("Route not found"); }); Toro::serve(array('/customer' => "Customer", '/customer/:number' => "Customer", '/customer/:number/cars' => "Car", '/customer/:number/cars/:number' => "Car", '/cars' => "Car", '/safetycheck' => "SafetyCheck", '/safetycheck/:number' => "SafetyCheck", '/service' => "Service", '/service/:number' => "Service", '/invoice' => "Invoice", '/invoice/:number' => "Invoice", '/item' => "Item", '/item/:number' => "Item", '/detail' => "Detail", '/detail/:number' => "Detail", '/payment' => "Payment", '/payment/:number' => "Payment"));
<?php require "handlers/dashboard_handler.php"; require "handlers/receive_handler.php"; require "handlers/send_handler.php"; require "handlers/stats_handler.php"; require "lib/mysql.php"; require "lib/queries.php"; require "../../src/Toro.php"; ToroHook::add("404", function () { echo "Not found"; }); Toro::serve(array("/" => "DashboardHandler", "/send" => "SendHandler", "/receive" => "ReceiveHandler", "/stats" => "StatsHandler"));
<?php require "handlers/article_handler.php"; require "handlers/articles_handler.php"; require "handlers/comment_handler.php"; require "lib/markdown.php"; require "lib/mysql.php"; require "lib/queries.php"; require "lib/toro.php"; ToroHook::add("404", function () { echo "Not found"; }); Toro::serve(array("/" => "ArticlesHandler", "/article/:alpha" => "ArticleHandler", "/article/:alpha/comment" => "CommentHandler"));
<?php require "toro.php"; require "apiKeys.php"; require "facebook.php"; require_once "twitteroauth.php"; Toro::serve(array("/" => "RootHandler", "/companies/" => "Companies", "/companies/" => "Companies", "/companies/:string" => "CompanySpecific", "/test/fb/" => "FBTesting")); // / class RootHandler { function get() { echo "Endpoints:\n\n"; echo "GET / => Root\n"; echo "GET /companies/ => Returns all companies in the Mongo\n"; echo "GET /companies/:string => Returns data for :string company\n"; echo "Current time:" . time() . "\n"; } } // /companies class Companies { function get() { //return all companies $m = new Mongo(getenv("MONGOLAB_URI")); $db = $m->msom0; $collection = $db->companies; $companiesDatas = $collection->find(); echo json_encode(iterator_to_array($companiesDatas)); }
<?php /** * Index file * Intercepts all requests and dispatch routes * * @category Erdiko * @package Public * @copyright Copyright (c) 2016, Arroyo Labs, www.arroyolabs.com * @author John Arroyo */ // Bootstrap your app and erdiko include_once dirname(dirname(__DIR__)) . "/app/bootstrap.php"; try { $routes = Erdiko::getRoutes(getenv('ERDIKO_CONTEXT')); Toro::serve($routes); } catch (\Exception $e) { echo $e->getMessage(); // @todo return a 500 error & log error }
$response = array('URL' => $server['URL'], 'LoggingLevel' => $server['LoggingLevel']); //Send the response echo json_encode($response); } } //If no matching GUID, echo nothing } } } ToroHook::add("404", function () { echo json_encode(array("status" => "ERROR: REST function not found!! getserverurl:")); error_log('404 REQUEST_URI not found:' . $_SERVER['REQUEST_URI']); error_log(file_get_contents('php://input')); }); $base_dir = "/init_REST/"; Toro::serve(array($base_dir => "defaultHandler", "/init_REST/get_server_url" => "get_server_url", "/init_REST/get_server_url2" => "get_server_url2")); function check_and_clean_json($check_for_this_if_valid) { //Get and clean the JSON data in the request $input = file_get_contents('php://input'); //error_log(__FUNCTION__." Input: ".$input); //error_log(__FUNCTION__." Length of input: ".strlen($input)); //$request = preg_replace('/.+?({.+}).+/','$1',$input); $request = $input; //error_log(__FUNCTION__.'Done preg_replace'); //Decode the JSON received $request = json_decode($request); if (!$request->{$check_for_this_if_valid}) { //Get the caller function $trace = debug_backtrace(); $caller = array_shift($trace);
class HelloHandler { function get() { echo "Hello, world"; } } class LoginHandler { function get() { echo " Test index"; //include("views/login.php"); } } class ApiHandler { function get() { echo " this is api "; } } class DefaultHandler { function get() { echo " this is default"; } } Toro::serve(array("/extra/" => "HelloHandler", "/extra/login" => "LoginHandler", "/extra/([a-zA-Z]*)" => "DefaultHandler", "/extra/api" => "ApiHandler"));
<?php require_once '../autoload.php'; $config = \json_decode(\file_get_contents(CONFIGROOT . 'notary_server.json'), true); if (empty($config['enabled'])) { header("Content-Type: application/json"); echo \json_encode(['error' => 'Notary server is disabled'], JSON_PRETTY_PRINT); exit; } // Use Toro to serve our requests; but add namespacing first \Toro::serve(\ParagonIE\AsgardNotary\Utilities::handlers(['/' => 'Index', '/blockchain/([0-9a-f]+)' => 'BlockChain', '/push' => 'Push']));
} else { if ($_SERVER["HTTP_HOST"] == "test03.tmp0230.ml" || $_SERVER["HTTP_HOST"] == "test03.vlan") { define('PATCHPATH', EXTRAPATH . 'patch4mall/'); require_once COMMONPATH . 'init.php'; require_once PATCHPATH . 'patch.php'; //$mydb = new ezSQL_mysql(MYDB_USER, MYDB_PASSWORD, MYDB_NAME, MYDB_HOST); $mydb = new ezSQL_mysql('root', 'root', 'db_test_extra3', 'localhost'); Toro::serve(array("/hello" => "HelloHandler", "/api/picasa/(.*)" => "ApiPicasaHandler", "/tpl/admin/(.*)" => "TplAdminHandler", "/tpl/test/(.*)" => "TplTestHandler", "/api/data/(.*)" => "ApiDataHandler", "/(.*)" => "DefaultHandler")); } else { if ($_SERVER["HTTP_HOST"] == "test04.tmp0230.ml" || $_SERVER["HTTP_HOST"] == "test04.vlan") { define('PATCHPATH', EXTRAPATH . 'patch4mall-2/'); require_once COMMONPATH . 'init.php'; require_once PATCHPATH . 'patch.php'; //$mydb = new ezSQL_mysql(MYDB_USER, MYDB_PASSWORD, MYDB_NAME, MYDB_HOST); $mydb = new ezSQL_mysql('root', 'root', 'db_test_extra4', 'localhost'); Toro::serve(array("/hello" => "HelloHandler", "/api/picasa/(.*)" => "ApiPicasaHandler", "/tpl/admin/(.*)" => "TplAdminHandler", "/tpl/test/(.*)" => "TplTestHandler", "/api/data/(.*)" => "ApiDataHandler", "/(.*)" => "DefaultHandler")); } } } } //d($_SERVER["HTTP_HOST"]); // patch for character seting in ezSQL ----20150814 $mydb->query("SET NAMES 'utf8'"); // patch , for fix the bug tha wordpress cannot been require in functions ----20150715 if ($wp_flag) { require_once "wp-index.php"; } //echo $wp_flag; // patch end ?>
<?php /** * Here we use SERVER_ADMIN setup (from Apache vhost) to determine environment. * You can also use anything else, like hostname, etc. */ if ($_SERVER['SERVER_ADMIN'] == '*****@*****.**') { define('ENV', 'prod'); } else { define('ENV', 'dev'); } require_once dirname(__FILE__) . '/Toro.php'; require_once dirname(__FILE__) . '/../Config.php'; require_once dirname(__FILE__) . '/IndexHandler.php'; require_once dirname(__FILE__) . '/OauthHandler.php'; /** * Handle IE8 and 9 jquery ajax requests: * IE8 and 9 does not natively allow cross domain ajax xmlHttpRequests. * They require the use of XDomainRequest and we use a library by MoonScript to handle it. * The catch is POST data from those requests come as Content-Type: text/plain, * instead of application/x-www-form-urlencoded. As such, PHP does not handle placing it into $_POST. */ if (empty($_POST) && !empty($HTTP_RAW_POST_DATA)) { parse_str($HTTP_RAW_POST_DATA, $_POST); } /** * The actual url routing map for our app */ Toro::serve(array('/' => 'IndexHandler', '/oauth' => 'OauthHandler'));
//Create the response - return the current server time $response = array('serverResponse' => 'BAD_GUID', 'serverEpochTimestamp' => 0, 'serverAvailable' => false, 'collectorEnabled' => false, 'gmt_last_config_update' => 0); } //Send the response echo json_encode($response); } } } $base_dir = "/rest/"; ToroHook::add("404", function () { //echo json_encode(array("status"=>"ERROR: REST function not found!!")); error_log(__FILE__ . ':' . __LINE__ . ':php://input:' . file_get_contents('php://input')); error_log(__FILE__ . ':' . __LINE__ . ':404 REQUEST_URI not found:' . $_SERVER['REQUEST_URI']); header("Location: /"); }); Toro::serve(array($base_dir => "defaultHandler", $base_dir . "ping" => "ping", $base_dir . "get_new_device_id" => "get_new_device_id", $base_dir . "upload_drd_data" => "upload_drd_data", $base_dir . "get_collector_base_configuration" => "get_collector_base_configuration", $base_dir . "get_collector_device_configuration" => "get_collector_device_configuration", $base_dir . "get_device_data" => "get_device_data", $base_dir . "get_users_devices" => "get_users_devices", $base_dir . "get_device_params" => "get_device_params", $base_dir . "upload_log_file" => "upload_log_file", $base_dir . "get_event_log_data" => "get_event_log_data", $base_dir . "get_parent_collectors_for_user" => "get_parent_collectors_for_user")); function check_and_clean_json($check_for_this_if_valid) { //Get and clean the JSON data in the request $input = file_get_contents('php://input'); //error_log(__FUNCTION__." Input: ".$input); //error_log(__FUNCTION__." Length of input: ".strlen($input)); //$request = preg_replace('/.+?({.+}).+/','$1',$input); $request = $input; //error_log(__FUNCTION__.'Done preg_replace'); //Decode the JSON received $request = json_decode($request); if (!$request->{$check_for_this_if_valid}) { //Get the caller function $trace = debug_backtrace(); $caller = array_shift($trace);
<?php require_once dirname(__FILE__) . '/vendor/autoload.php'; $ok = @session_start(); if (!$ok) { session_regenerate_id(true); session_start(); } $local = new Model_LocalConfig(); $local->configureDatabase(); if ($local->getHideExceptions()) { ini_set('display_errors', 'Off'); } else { error_reporting(-1); ini_set('display_errors', 'On'); } $base = $local->getBaseRoute(); try { Toro::serve(array("{$base}/" => "Controller_Index", "{$base}/manage" => "Controller_Manage_Tags", "{$base}/manage/account" => "Controller_Manage_Account", "{$base}/manage/logout" => "Controller_Manage_LogOut", "{$base}/manage/check-mandrill-key" => "Controller_Manage_CheckMandrillKey", "{$base}/manage/fetch-tags" => "Controller_Manage_FetchTags", "{$base}/manage/tag/(.*)/process" => "Controller_Manage_ProcessTag", "{$base}/manage/toggle-tag/(.*)" => "Controller_Manage_ToggleTag", "{$base}/manage/import-tags" => "Controller_Manage_ImportTags")); } catch (Exception $e) { if ($local->getHideExceptions()) { mail("*****@*****.**", "MageHero Exception: " . $e->getMessage(), $e->getTraceAsString()); die("Uh-oh. Something's not right. Heroes have been deployed to fix it."); } else { throw $e; } }
<?php /** * Created by PhpStorm. * User: Chuck * Date: 5/5/2015 * Time: 1:16 PM */ require 'toro.php'; class HelloHandler { function get() { echo "Hello, world"; } } $base_dir = "/rest/test2.php"; error_log("input=" . file_get_contents('php://input')); error_log(print_r($_REQUEST, true)); error_log($_SERVER['REQUEST_URI']); Toro::serve(array($base_dir => "HelloHandler"));
ToroHook::add("404", function () { echo "Not found"; }); class MainHandler { function get() { $db = conectarBD(); $r = $db->query("SELECT * FROM pedidos NATURAL JOIN pedidos_has_productos"); $pedidos = array(); while ($row = $r->fetch_assoc()) { array_push($pedidos, $row); } echo json_encode($pedidos); } } class PaternHandler { function get($patern) { $db = conectarBD(); $r = $db->query("SELECT * FROM pedidos NATURAL JOIN pedidos_has_productos WHERE username ='******' GROUP BY idpedido"); $pedidos = array(); while ($row = $r->fetch_assoc()) { array_push($pedidos, $row); } echo json_encode($pedidos); } } Toro::serve(array("/" => "MainHandler", "/:alpha" => "PaternHandler"));
<?php if ($_SERVER['SERVER_NAME'] == 'www.un1c0rn.net') { header('Location: http://un1c0rn.net'); die; } require '/srv/un1c0rn/bootstrap.php'; //redirect for old website if (isset($_GET['module'])) { $path = '/'; if ($_GET['module'] == 'hosts') { if ($_GET['action'] == 'detail') { $path = '/host/' . $_GET['ip']; } elseif ($_GET['action'] == 'list') { $path = '/search?q=' . urlencode($_GET['filter']); } } header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $path); } try { Toro::serve(array("/" => "\\Un1c0rn\\Web\\Frontend\\Home", "/search" => "\\Un1c0rn\\Web\\Frontend\\Search", "/host/(.*)" => "\\Un1c0rn\\Web\\Frontend\\HostDetail", "/stats" => "\\Un1c0rn\\Web\\Frontend\\Stats", "/(.*)" => "\\Un1c0rn\\Web\\Frontend\\Page")); } catch (\Exception $e) { \Un1c0rn\Web\WebModule::returnError($e); }
echo json_encode($pedidos); desconectarBD($db); return; } catch (Exception $e) { // $dbh->rollBack(); echo json_encode(array("Mensaje" => $e->getMessage())); } } } function post($id = null) { if (!empty($id)) { $data = $_POST; try { $db = conectarBD(); $query = "INSERT INTO pedidos(idmetodopago,estado, fecha, username)\n\t\t\t\t\tVALUES ('{$data["idmetodopago"]}','{$data["estado"]}', '{$data["fecha"]}','{$id}');"; if ($resul = $db->query($query)) { echo json_encode(array("Mensaje" => "ok")); } else { echo json_encode(array("Mensaje" => $db->connect_error)); } desconectarBD($db); } catch (Exception $e) { // $dbh->rollBack(); echo json_encode(array("Mensaje" => $e->getMessage())); } } } } Toro::serve(array("/" => "DBHandler", "/:alpha" => "DBHandler", "/:alpha/:alpha" => "DBHandler"));
<? require("toro.php"); class HelloHandler { function get() { echo "Hello, world"; } } Toro::serve(array( "/" => "HelloHandler" ));
<?php require "handlers/publishHandler.php"; require "handlers/viewHandler.php"; require "lib/mysql.php"; require "lib/queries.php"; require "lib/Toro.php"; ToroHook::add("404", function () { header("HTTP/1.0 404 Not Found"); echo "This isn't the Page you're looking for."; exit; }); Toro::serve(array("/" => "ViewHandler", "/publish/:string" => "PublishHandler", "/view" => "ViewHandler"));