当前位置: 首页>>代码示例>>PHP>>正文


PHP Flight::map方法代码示例

本文整理汇总了PHP中Flight::map方法的典型用法代码示例。如果您正苦于以下问题:PHP Flight::map方法的具体用法?PHP Flight::map怎么用?PHP Flight::map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Flight的用法示例。


在下文中一共展示了Flight::map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: error_reporting

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'flight/flight/Flight.php';
require_once 'ipsp-php/autoload.php';
Flight::set('flight.views.path', 'templates');
Flight::set('layout', 'layout/default');
Flight::set('appname', 'IPSP PHP Examples');
Flight::set('apptitle', 'Api');
Flight::register('ipsp', 'Ipsp_Api', array(new Ipsp_Client(1000, 'test', 'api.oplata.com')));
Flight::map('output', function ($content = NULL) {
    Flight::view()->set('ipsp', Flight::ipsp());
    Flight::render($content, array(), 'content');
    Flight::render(Flight::get('layout'));
});
Flight::route('/', function () {
    Flight::output('pages/frontpage');
});
Flight::route('/page/@page(/@order_id)', function ($page = 'notfound', $order_id = NULL) {
    Flight::view()->set('order_id', $order_id);
    Flight::output(sprintf('pages/%s', $page));
});
Flight::route('/modal/@page', function ($page = 'notfound') {
    Flight::view()->set('ipsp', Flight::ipsp());
    Flight::render(sprintf('modal/%s', $page));
});
Flight::route('/api/checkout', function () {
    $data = Flight::request()->data;
});
Flight::start();
开发者ID:kosatyi,项目名称:ipsp-php-examples,代码行数:31,代码来源:index.php

示例2: init

 public static function init()
 {
     date_default_timezone_set("Etc/GMT");
     if (get_magic_quotes_gpc()) {
         $_GET = self::stripslashesDeep($_GET);
         $_POST = self::stripslashesDeep($_POST);
         $_COOKIE = self::stripslashesDeep($_COOKIE);
     }
     $_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
     Flight::map("db", array(__CLASS__, "db"));
     //Flight::map("cache", array(__CLASS__, "cache"));
     Flight::map("log", array(__CLASS__, "log"));
     Flight::map("curl", array(__CLASS__, "curl"));
     Flight::map("halt", array(__CLASS__, "halt"));
     Flight::map("getRunTime", array(__CLASS__, "getRunTime"));
     Flight::map("returnJson", array(__CLASS__, "returnJson"));
     Flight::map("controller", array(__CLASS__, "getController"));
     Flight::map("model", array(__CLASS__, "getModel"));
     Flight::map("url", array(__CLASS__, "url"));
     Flight::map("connectMysqlDB", array(__CLASS__, "connectMysqlDB"));
     Flight::map("closeMysqlDB", array(__CLASS__, "closeMysqlDB"));
     Flight::map("connectMongoDB", array(__CLASS__, "connectMongoDB"));
     Flight::map("closeMongoDB", array(__CLASS__, "closeMongoDB"));
     Flight::map("connectRedis", array(__CLASS__, "connectRedis"));
     Flight::set('flight.log_errors', true);
     //写一个日志
     //if(Flight::request()->method == "POST") {
     // Flight::log("post-".date("Ymd"))->info(print_r($_POST, TRUE));
     //}
     self::initRoute();
 }
开发者ID:SwiftGGTeam,项目名称:SwiftGGAppServer,代码行数:31,代码来源:Controller.php

示例3: testMap

 function testMap()
 {
     Flight::map('map1', function () {
         return 'hello';
     });
     $result = Flight::map1();
     $this->assertEquals('hello', $result);
 }
开发者ID:NDStudios,项目名称:mc,代码行数:8,代码来源:FlightTest.php

示例4: bootstrap

 /**
  * bootstrap
  * for framework bootstrap.
  */
 public static function bootstrap()
 {
     //route
     require APP_PATH . '/routes.php';
     //set timezone
     $timezone = env('APP_TIMEZONE', 'Asia/Shanghai');
     date_default_timezone_set($timezone);
     //filters
     if (get_magic_quotes_gpc()) {
         $_GET = self::stripslashesDeep($_GET);
         $_POST = self::stripslashesDeep($_POST);
         $_COOKIE = self::stripslashesDeep($_COOKIE);
     }
     $_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
     /*--
       Flight maps start
       --*/
     //log
     Flight::map('log', [__CLASS__, 'log']);
     //db : database
     Flight::map('db', [__CLASS__, 'db']);
     //model
     Flight::map('model', [__CLASS__, 'getModel']);
     //cache
     Flight::map('cache', [__CLASS__, 'cache']);
     //get controller
     Flight::map('controller', [__CLASS__, 'getController']);
     //halt response
     Flight::map("halt", array(__CLASS__, "halt"));
     //404 error
     Flight::map('notFound', function () {
         //Flight::log()->error(Flight::request()->ip.': '.Flight::request()->method.' '.Flight::request()->url.' not Found !');
         Flight::log()->error('404 NOT FOUND !', json_decode(json_encode(Flight::request()), true));
         return self::halt(Flight::view()->fetch('404'), '404');
     });
     /*
     Flight::map('error', function(Exception $ex){
         // Handle error
         Flight::log()->error('500 Error : '.$ex->getTraceAsString());
         echo $ex->getTraceAsString();
     });
     */
     /*--
       Flight maps end
       --*/
 }
开发者ID:ycrao,项目名称:tinyme,代码行数:50,代码来源:TinyMe.php

示例5: function

    Flight::result(401, $result);
});
//forbidden
Flight::map('forbidden', function ($message) {
    $result = new Result();
    $result->Status = Result::ERROR;
    $result->Message = $message;
    Flight::result(403, $result);
});
//notFound
Flight::map('notFound', function ($message) {
    $result = new Result();
    $result->Status = Result::NOTFOUND;
    $result->Message = $message;
    Flight::result(404, $result);
});
// Flight::map('noContent', function($message){
// 	$result = new Result();
// 	$result->Status = Result::ERROR;
// 	$result->Message = $message;
// 	Flight::result(204,$result);
// });
Flight::map('error', function (Exception $exception) {
    $result = new Result();
    $result->Status = Result::ERROR;
    $result->Message = $exception->getMessage();
    Flight::result(501, $result);
});
Flight::map('result', function ($status, $result) {
    Flight::response()->status($status)->header('Access-Control-Allow-Origin', '*')->header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS,PATCH')->header('Access-Control-Allow-Headers', 'Content-Type')->header('Content-Type', 'application/json')->write(utf8_decode(json_encode($result)))->send();
});
开发者ID:rhalf,项目名称:app_track,代码行数:31,代码来源:statuscode.php

示例6: function

            $id = Flight::get('hash')->decode($hash);
            if (!$id) {
                Flight::json(['status' => 0, 'msg' => '短址无法解析']);
            } else {
                $store = Flight::get('db')->select('urls', ['url'], ['id' => $id]);
                if (!$store) {
                    Flight::json(['status' => 0, 'msg' => '地址不存在']);
                } else {
                    Flight::json(['status' => 1, 'url' => $store[0]['url']]);
                }
            }
        }
    }
});
Flight::route('/@hash', function ($hash) {
    $id = Flight::get('hash')->decode($hash);
    if (!$id) {
        Flight::notFound('短址无法解析');
    } else {
        $store = Flight::get('db')->select('urls', ['url'], ['id' => $id]);
        if (!$store) {
            Flight::notFound('地址不存在');
        } else {
            Flight::get('db')->update('urls', ['count[+]' => 1], ['id' => $id]);
            Flight::redirect($store[0]['url'], 302);
        }
    }
});
Flight::map('notFound', function ($message) {
    Flight::response()->status(404)->header('content-type', 'text/html; charset=utf-8')->write('<h1>404 页面未找到</h1>' . "<h3>{$message}</h3>" . '<p><a href="' . Flight::get('flight.base_url') . '">回到首页</a></p>' . str_repeat(' ', 512))->send();
});
开发者ID:npk,项目名称:Ourls,代码行数:31,代码来源:routes.php

示例7: avg

<?php

if (!function_exists('avg')) {
    function avg(array $data)
    {
        return array_sum($data) / count($data);
    }
}
/**
 * Registers a class and set a variable to framework method.
 *
 * @param string $name Method name
 * @param string $class Class name
 * @param array $params Class initialization parameters
 * @param callback $callback Function to call after object instantiation
 * @throws \Exception If trying to map over a framework method
 */
Flight::map('instance', function ($name, $class, array $params = array(), $callback = null) {
    Flight::register($name, $class, $params, $callback);
    Flight::set($name, Flight::$name());
});
开发者ID:npk,项目名称:Ourls,代码行数:21,代码来源:helpers.php

示例8: dirname

<?php

require dirname(__DIR__) . '/vendor/autoload.php';
Flight::route('/', function () {
    echo "OK Route: /";
});
Flight::route('/something', function () {
    echo "OK Route: /something";
});
Flight::map('notFound', function () {
    echo "KO";
});
Flight::start();
开发者ID:Sigill,项目名称:flight-public-docroot,代码行数:13,代码来源:app.php

示例9: array

<?php

Flight::route('/', array('welcomeController', 'welcome'));
\Flight::map('notFound', function () {
    \Flight::render('404', array());
});
开发者ID:CollaByte,项目名称:tbzsn,代码行数:6,代码来源:routes.php

示例10: array

    if (!($plugins = plugins_get_by_tag($tag))) {
        Flight::notFound();
    }
    Flight::render($view, array('tag' => $tag, 'plugins' => $plugins));
});
/**
 * 404
 */
Flight::map('notFound', function () {
    site_title('404 - not found :(');
    $request = Flight::request();
    // see if a page exists
    if ($page_info = page_exists($request->url)) {
        site_title($page_info['title']);
        if (null !== $page_info['description']) {
            site_description($page_info['description']);
        }
        Flight::render($page_info['view']);
        die;
    }
    // see if there's a valid permanent redirect, and if there is send the user to the new location
    if ($redirect_url = redirect_destination($request->url)) {
        Flight::redirect($redirect_url, 301);
        die;
    }
    header('HTTP/1.0 404 Not Found');
    site_header_title('404 :(');
    site_description('<a href="' . path() . '">Visit the homepage <i class="fa fa-arrow-right"></i></a>');
    Flight::render('404.php');
    die;
});
开发者ID:BinaryMoon,项目名称:pro-theme-design,代码行数:31,代码来源:routes.php

示例11: array

// Registering Smarty as template engine
Flight::register('view', 'Smarty', array(), function ($smarty) {
    $smarty->template_dir = Flight::get('flight.views.path') . '/';
    $smarty->compile_dir = __DIR__ . '/../app/cache/smarty_compile/';
    $smarty->config_dir = __DIR__ . '/../app/config/smarty/';
    $smarty->cache_dir = __DIR__ . '/../app/cache/smarty_cache/';
});
Flight::map('render', function ($template, $data) {
    Flight::view()->assign($data);
    Flight::view()->display($template);
});
//personnalizing errors
Flight::map('notFound', function () {
    if (file_exists(Flight::get('flight.views.path') . '/Errors/404.tpl')) {
        Flight::render('Errors/404.tpl', array());
    } else {
        Flight::_notFound();
    }
});
Flight::map('error', function (\Exception $e) {
    $code = http_response_code();
    if ($code == 200) {
        $code = 500;
    }
    if (file_exists(Flight::get('flight.views.path') . '/Errors/' . $code . '.tpl')) {
        Flight::render('Errors/' . $code . '.tpl', array('message' => $e->getMessage(), 'code' => $e->getCode(), 'line' => $e->getLine(), 'file' => $e->getFile(), 'traceString' => $e->getTraceAsString(), 'trace' => $e->getTrace()));
    } else {
        Flight::_error($e);
    }
});
Flight::start();
开发者ID:purplebabar,项目名称:flightpilot,代码行数:31,代码来源:index.php

示例12: function

            $patternSrv->report($id, 1);
            break;
        case '2':
            // view
            echo 2;
            break;
        case '3':
            // report
            echo 3;
            break;
    }
});
// 404 not found Handling
Flight::map('notFound', function () {
    $error = array();
    $error[] = ERROR_404;
    $_SESSION[ERROR] = $error;
    Flight::redirect('/error');
});
// Error Handling
// 	Flight::map('error', function(Exception $ex){
// 		// Handle error
// 		$error = array();
// 		$error[] = SYSTEM_ERROR;
// 		if(OUT_ERROR) {
// 			$error[] = '<pre>'.$ex->getTraceAsString().'</pre>';
// 		}
// 		$_SESSION[ERROR] = $error;
// 		Flight::redirect('/error');
// 	});
Flight::route('/create', function () {
    // 			echo 'create';
开发者ID:quocphu,项目名称:hiragana,代码行数:32,代码来源:index.php

示例13: array

<?php

require_once 'vendor/flight/flight/autoload.php';
require_once 'vendor/flight/flight/Flight.php';
//Connect to database
$dbinfo = array('mysql:host=localhost;dbname=benchmarked', 'root', '');
Flight::register('db', 'PDO', $dbinfo, function ($db) {
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
});
//Error message
Flight::map('errmsg', function ($msg, $show = true) {
    if ($show) {
        return $msg;
    } else {
        return;
    }
});
//Home page
Flight::route('/', function () {
    echo 'Welcome from Flight!';
});
//Put a new result in database
Flight::route('PUT /api/result', function () {
    //Array of named parameters
    $body = Flight::request()->getBody();
    $values = array();
    $nv_strings = explode('&', $body);
    foreach ($nv_strings as $s) {
        $nv = explode('=', $s, 2);
        $name = urldecode($nv[0]);
        $value = isset($nv[1]) ? urldecode($nv[1]) : null;
开发者ID:dimitarnestorov,项目名称:benchmarked,代码行数:31,代码来源:index.php

示例14: function

<?php

require_once 'Config.php';
require_once 'flight/Flight.php';
require_once 'Controller.php';
Controller::connectDB();
Flight::map('error', function (Exception $ex) {
    // Handle error
    echo $ex->getTraceAsString();
});
Flight::route('POST *', function () {
    //Every POST request goes trought a check of the api key
    Controller::check_api_key_post();
    return true;
});
Flight::route('POST /user/create', function () {
    $data = Controller::collect_post_value('email', true);
    $data = Controller::collect_post_value('password', true, $data);
    $data = Controller::collect_post_value('type', false, $data, 'int');
    $data = Controller::collect_post_value('name', false, $data);
    $data = Controller::collect_post_image('avatar', false, $data);
    $data = Controller::collect_post_value('statistics', false, $data, 'json');
    $data = Controller::collect_post_image('photo_1', false, $data);
    $data = Controller::collect_post_image('photo_2', false, $data);
    $data = Controller::collect_post_image('photo_3', false, $data);
    $data = Controller::collect_post_value('founders', false, $data);
    $data = Controller::collect_post_value('website', false, $data);
    $data = Controller::collect_post_value('video', false, $data);
    $data = Controller::collect_post_value('activity', false, $data);
    $data = Controller::collect_post_value('sector_activity', false, $data);
    $data = Controller::collect_post_value('type_activity', false, $data);
开发者ID:smarecha79,项目名称:WLS_standalone,代码行数:31,代码来源:index.php

示例15: Api

<?php

include "vendor/autoload.php";
use calebdre\ApiSugar\Api;
use LikeAPro\Controllers\SubmissionsController;
use LikeAPro\Controllers\UserController;
$api = new Api();
$api->configureDB(['driver' => "mysql", "host" => "localhost", "database" => "likeapro", "username" => "root", "password" => "", "charset" => "utf8", "collation" => "utf8_unicode_ci", "prefix" => ""]);
$api->addClass(new SubmissionsController());
$api->addClass(new UserController());
Flight::map('notFound', function () {
    header("Location " . substr(parse_url($_SERVER['REQUEST_URI'])['path'], 1));
});
$api->execute();
开发者ID:JiYoungP,项目名称:likeapro,代码行数:14,代码来源:index.php


注:本文中的Flight::map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。