示例#1
0
Deficient::boot("./");
## burp,  move it somewhere
route_get('page/(\\d+)', array('as' => 'page', function ($page) {
    Zofe\Burp\BurpEvent::queue('dataset.page', array($page));
}));
//define some general purpose events on query-string
route_query('ord=(-?)(\\w+)', array('as' => 'orderby', function ($direction, $field) {
    $direction = $direction == '-' ? "DESC" : "ASC";
    Zofe\Burp\BurpEvent::queue('dataset.sort', array($direction, $field));
}))->remove('page');
## test routes
route_get('^/{page?}$', array('as' => 'datagrid', function () {
    $grid = DataGrid::source(new User());
    $grid->add('id', 'ID', true)->style('width:100px');
    $grid->add('name', 'Name', true);
    $grid->paginate(5);
    echo blade('datagrid.tests.datagrid', compact('grid'));
    die;
}));
route_get('^/dataset/{page?}$', array('as' => 'dataset', function () {
    $ds = DataSet::source(new User());
    $ds->paginate(5);
    $ds->build();
    echo blade('datagrid.tests.dataset', compact('ds'));
    die;
}));
route_missing(function () {
    echo blade('datagrid.tests.error', array(), 404);
    die;
});
route_dispatch();
示例#2
0
/**
 * Running application
 *
 * @param string $env
 * @return void
 */
function run($env = null)
{
    if (is_null($env)) {
        $env = env();
    }
    # 0. Set default configuration
    $root_dir = dirname(app_file());
    $base_path = dirname(file_path($env['SERVER']['SCRIPT_NAME']));
    $base_file = basename($env['SERVER']['SCRIPT_NAME']);
    $base_uri = file_path($base_path, $base_file == 'index.php' ? '?' : $base_file . '?');
    $lim_dir = dirname(__FILE__);
    option('root_dir', $root_dir);
    option('base_path', $base_path);
    option('base_uri', $base_uri);
    // set it manually if you use url_rewriting
    option('limonade_dir', file_path($lim_dir));
    option('limonade_views_dir', file_path($lim_dir, 'limonade', 'views'));
    option('limonade_public_dir', file_path($lim_dir, 'limonade', 'public'));
    option('public_dir', file_path($root_dir, 'public'));
    option('views_dir', file_path($root_dir, 'views'));
    option('controllers_dir', file_path($root_dir, 'controllers'));
    option('lib_dir', file_path($root_dir, 'lib'));
    option('error_views_dir', option('limonade_views_dir'));
    option('env', ENV_PRODUCTION);
    option('debug', true);
    option('session', LIM_SESSION_NAME);
    // true, false or the name of your session
    option('encoding', 'utf-8');
    option('x-sendfile', 0);
    // 0: disabled,
    // X-SENDFILE: for Apache and Lighttpd v. >= 1.5,
    // X-LIGHTTPD-SEND-FILE: for Apache and Lighttpd v. < 1.5
    # 1. Set error handling
    ini_set('display_errors', 1);
    set_error_handler('error_handler_dispatcher', E_ALL ^ E_NOTICE);
    # 2. Set user configuration
    call_if_exists('configure');
    # 3. Loading libs
    require_once_dir(option('lib_dir'));
    # 4. Starting session
    if (!defined('SID') && option('session')) {
        if (!is_bool(option('session'))) {
            session_name(option('session'));
        }
        if (!session_start()) {
            trigger_error("An error occured while trying to start the session", E_USER_WARNING);
        }
    }
    # 5. Set some default methods if needed
    if (!function_exists('after')) {
        function after($output)
        {
            return $output;
        }
    }
    if (!function_exists('route_missing')) {
        function route_missing($request_method, $request_uri)
        {
            halt(NOT_FOUND, "({$request_method}) {$request_uri}");
        }
    }
    # 6. Check request
    if ($rm = request_method()) {
        if (request_is_head()) {
            ob_start();
        }
        // then no output
        if (!request_method_is_allowed($rm)) {
            halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented");
        }
        # 6.1 Check matching route
        if ($route = route_find($rm, request_uri())) {
            params($route['params']);
            # 6.2 Load controllers dir
            require_once_dir(option('controllers_dir'));
            if (is_callable($route['function'])) {
                # 6.3 Call before function
                call_if_exists('before');
                # 6.4 Call matching controller function and output result
                if ($output = call_user_func($route['function'])) {
                    echo after(error_notices_render() . $output);
                }
                stop_and_exit();
            } else {
                halt(SERVER_ERROR, "Routing error: undefined function '{$route['function']}'", $route);
            }
        } else {
            route_missing($rm, request_uri());
        }
    } else {
        halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented");
    }
}
示例#3
0
function run($env = null)
{
    if (is_null($env)) {
        $env = env();
    }
    // 0. Set default configuration
    $root_dir = dirname(app_file());
    $lim_dir = dirname(__FILE__);
    $base_path = dirname(file_path($env['SERVER']['SCRIPT_NAME']));
    $base_file = basename($env['SERVER']['SCRIPT_NAME']);
    $base_uri = file_path($base_path, $base_file == 'index.php' ? '?' : $base_file . '?');
    option('dir.root', $root_dir);
    option('dir.limonade', file_path($lim_dir));
    option('dir.limonade.views', file_path($lim_dir, 'limonade', 'views'));
    option('dir.limonade.public', file_path($lim_dir, 'limonade', 'public'));
    option('dir.public', file_path($root_dir, 'public'));
    option('dir.views', file_path($root_dir, 'views'));
    option('dir.controllers', file_path($root_dir, 'controllers'));
    option('dir.lib', file_path($root_dir, 'lib'));
    option('dir.views.errors', option('dir.limonade.views'));
    option('base.path', $base_path);
    option('base.uri', $base_uri);
    # set it manually if you use url_rewriting
    option('env', ENV_PRODUCTION);
    option('debug', true);
    option('session', LIM_SESSION_NAME);
    # true, false or the name of your session
    option('encoding', 'utf-8');
    option('signature', LIM_NAME);
    # X-Limonade header value or false to hide it
    option('gzip', false);
    option('x-sendfile', 0);
    # 0: disabled,
    # X-SENDFILE: for Apache and Lighttpd v. >= 1.5,
    # X-LIGHTTPD-SEND-FILE: for Apache and Lighttpd v. < 1.5
    // 1. Set handlers
    // 1.1 Set error handling
    ini_set('display_errors', 1);
    set_error_handler('error_handler_dispatcher', E_ALL ^ E_NOTICE);
    // 1.2 Register shutdown function
    register_shutdown_function('stop_and_exit');
    // 2. Set user configuration
    call_if_exists('configure');
    // 2.1 Set gzip compression if defined
    if (is_bool(option('gzip')) && option('gzip')) {
        ini_set('zlib.output_compression', '1');
    }
    // 2.2 Set X-Limonade header
    if ($signature = option('signature')) {
        header("X-Limonade: {$signature}");
    }
    // 3. Loading libs
    require_once_dir(option('dir.lib'));
    fallbacks_for_not_implemented_functions();
    // 4. Starting session
    if (!defined('SID') && option('session')) {
        if (!is_bool(option('session'))) {
            session_name(option('session'));
        }
        if (!session_start()) {
            trigger_error("An error occured while trying to start the session", E_USER_WARNING);
        }
    }
    // 5. Set some default methods if needed
    if (!function_exists('after')) {
        function after($output)
        {
            return $output;
        }
    }
    if (!function_exists('route_missing')) {
        function route_missing($request_method, $request_uri)
        {
            halt(NOT_FOUND, "({$request_method}) {$request_uri}");
        }
    }
    call_if_exists('initialize');
    // 6. Check request
    if ($rm = request_method($env)) {
        if (request_is_head($env)) {
            ob_start();
        }
        // then no output
        if (!request_method_is_allowed($rm)) {
            halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented");
        }
        // 6.1 Check matching route
        if ($route = route_find($rm, request_uri($env))) {
            params($route['params']);
            // 6.2 Load controllers dir
            if (!function_exists('autoload_controller')) {
                function autoload_controller($callback)
                {
                    require_once_dir(option('dir.controllers'));
                }
            }
            autoload_controller($route['callback']);
            if (is_callable($route['callback'])) {
                // 6.3 Call before function
                call_if_exists('before', $route);
                // 6.4 Call matching controller function and output result
                $output = call_user_func_array($route['callback'], array_values($route['params']));
                if (is_null($output)) {
                    $output = call_if_exists('autorender', $route);
                }
                echo after(error_notices_render() . $output, $route);
            } else {
                halt(SERVER_ERROR, "Routing error: undefined function '{$route['callback']}'", $route);
            }
        } else {
            route_missing($rm, request_uri($env));
        }
    } else {
        halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented");
    }
}
示例#4
0
/**
 * Running application
 *
 * @param string $env 
 * @return void
 */
function run($env = null)
{
    if (is_null($env)) {
        $env = env();
    }
    # 0. Set default configuration
    $root_dir = dirname(app_file());
    option('root_dir', $root_dir);
    option('limonade_dir', dirname(__FILE__) . '/');
    option('public_dir', $root_dir . '/public/');
    option('views_dir', $root_dir . '/views/');
    option('controllers_dir', $root_dir . '/controllers/');
    option('lib_dir', $root_dir . '/lib/');
    option('env', ENV_PRODUCTION);
    option('debug', true);
    option('encoding', 'utf-8');
    option('x-sendfile', 0);
    // 0: disabled,
    // X-SENDFILE: for Apache and Lighttpd v. >= 1.5,
    // X-LIGHTTPD-SEND-FILE: for Apache and Lighttpd v. < 1.5
    # 1. Set error handling
    ini_set('display_errors', 1);
    set_error_handler('error_handler_dispatcher', E_ALL ^ E_NOTICE);
    # 2. Loading libs
    require_once_dir(option('lib_dir'));
    # 3. Set some default methods if needed
    if (!function_exists('after')) {
        function after($output)
        {
            return $output;
        }
    }
    if (!function_exists('route_missing')) {
        function route_missing($request_method, $request_uri)
        {
            halt(NOT_FOUND, "({$request_method}) {$request_uri}");
        }
    }
    # 4. Set user configuration
    call_if_exists('configure');
    # 5. Check request
    if ($rm = request_method()) {
        # 5.1 Check matching route
        if ($route = route_find($rm, request_uri())) {
            params($route['params']);
            # 5.2 Load controllers dir
            require_once_dir(option('controllers_dir'));
            if (function_exists($route['function'])) {
                # 5.3 Call before function
                call_if_exists('before');
                # 5.4 Call matching controller function and output result
                if ($output = call_user_func($route['function'])) {
                    if (option('debug') && option('env') > ENV_PRODUCTION) {
                        $notices = error_notice();
                        if (!empty($notices)) {
                            foreach ($notices as $notice) {
                                echo $notice;
                            }
                            echo '<hr>';
                        }
                    }
                    echo after($output);
                }
                exit;
            } else {
                halt(SERVER_ERROR, "Routing error: undefined function '{$route['function']}'", $route);
            }
        } else {
            route_missing($rm, request_uri());
        }
    } else {
        halt(SERVER_ERROR, "Unknown request method <code>{$rm}</code>");
    }
}
示例#5
0
/**
 * Running application
 *
 * @param string $env 
 * @return void
 */
function run($env = null)
{
    if (is_null($env)) {
        $env = env();
    }
    # 0. Set default configuration
    $root_dir = dirname(app_file());
    $lim_dir = dirname(__FILE__);
    $base_path = dirname(file_path($env['SERVER']['SCRIPT_NAME']));
    $base_file = basename($env['SERVER']['SCRIPT_NAME']);
    $base_uri = file_path($base_path, $base_file == 'index.php' ? '?' : $base_file . '?');
    option('root_dir', $root_dir);
    //option('limonade_dir',       file_path($lim_dir));
    //option('limonade_views_dir', file_path($lim_dir, 'limonade', 'views'));
    //option('limonade_public_dir',file_path($lim_dir, 'limonade', 'public'));
    option('public_dir', file_path($root_dir, 'public'));
    option('views_dir', file_path($root_dir, 'views'));
    option('controllers_dir', file_path($root_dir, 'controllers'));
    option('lib_dir', file_path($root_dir, 'lib'));
    //option('error_views_dir',    option('limonade_views_dir'));
    //option('base_path',          $base_path);
    option('base_uri', $base_uri);
    // set it manually if you use url_rewriting
    //  option('env',                ENV_PRODUCTION);
    option('debug', true);
    //option('session',            LIM_SESSION_NAME); // true, false or the name of your session
    option('encoding', 'utf-8');
    //option('signature',          LIM_NAME); // X-Limonade header value or false to hide it
    option('gzip', false);
    option('x-sendfile', 0);
    // 0: disabled,
    // X-SENDFILE: for Apache and Lighttpd v. >= 1.5,
    // X-LIGHTTPD-SEND-FILE: for Apache and Lighttpd v. < 1.5
    # 1. Set handlers
    # 1.1 Set error handling
    #ifndef KittenPHP
    ini_set('display_errors', 1);
    #endif
    //set_error_handler('error_handler_dispatcher', E_ALL ^ E_NOTICE);
    # 1.2 Register shutdown function
    register_shutdown_function('stop_and_exit');
    # 2. Set user configuration
    if (!function_exists('configure')) {
        function configure()
        {
        }
    }
    configure();
    # 2.1 Set gzip compression if defined
    if (is_bool(option('gzip')) && option('gzip')) {
        ini_set('zlib.output_compression', '1');
    }
    # 2.2 Set X-Limonade header
    //if($signature = option('signature')) send_header("X-Limonade: $signature");
    # 3. Loading libs
    //fallbacks_for_not_implemented_functions();
    # 4. Starting session
    //if(!defined('SID') && option('session'))
    //  {
    //    if(!is_bool(option('session'))) session_name(option('session'));
    //    if(!session_start()) trigger_error("An error occured while trying to start the session", E_USER_WARNING);
    //  }
    # 5. Set some default methods if needed
    if (!function_exists('route_missing')) {
        function route_missing($request_method, $request_uri)
        {
            halt(NOT_FOUND, "({$request_method}) {$request_uri}");
        }
    }
    if (!function_exists('initialize')) {
        function initialize()
        {
        }
    }
    initialize();
    # 6. Check request
    if ($rm = request_method($env)) {
        if (request_is_head($env)) {
            ob_start();
        }
        // then no output
        if (!request_method_is_allowed($rm)) {
            halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented");
        }
        # 6.1 Check matching route
        if ($route = route_find($rm, request_uri($env))) {
            params($route['params']);
            # 6.3 Call before function
            if (!function_exists('before')) {
                function before($route)
                {
                }
            }
            before($route);
            # 6.4 Call matching controller function and output result
            return $route;
        } else {
            route_missing($rm, request_uri($env));
        }
    } else {
        halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented");
    }
}
示例#6
0
文件: index.php 项目: zofe/deficient
<?php

require_once __DIR__ . '/vendor/autoload.php';
use Zofe\Deficient\Deficient;
Deficient::boot("./");
route_get('^/$', array('as' => 'home', function () {
    echo blade('deficient.hello');
}));
route_get('^/test/(\\w+)$', array('as' => 'test', function ($slug) {
    echo blade('deficient.hello', array('title' => $slug, 'content' => 'Hello ' . $slug));
}));
route_get('^/users$', function () {
    dd(User::all()->toJson());
});
route_missing(function () {
    echo blade('deficient.error', array(), 404);
    die;
});
route_dispatch();
示例#7
0
/**
 * Running application
 *
 * @param string $env 
 * @return void
 */
function run($env = null)
{
    if (is_null($env)) {
        $env = env();
    }
    # 0. Set default configuration
    $root_dir = dirname(app_file());
    option('root_dir', $root_dir);
    option('limonade_dir', dirname(__FILE__) . '/');
    option('limonade_views_dir', dirname(__FILE__) . '/limonade/views/');
    option('limonade_public_dir', dirname(__FILE__) . '/limonade/public/');
    option('public_dir', $root_dir . '/public/');
    option('views_dir', $root_dir . '/views/');
    option('controllers_dir', $root_dir . '/controllers/');
    option('lib_dir', $root_dir . '/lib/');
    option('env', ENV_PRODUCTION);
    option('debug', true);
    option('session', LIM_SESSION_NAME);
    // true, false or the name of your session
    option('encoding', 'utf-8');
    option('x-sendfile', 0);
    // 0: disabled,
    // X-SENDFILE: for Apache and Lighttpd v. >= 1.5,
    // X-LIGHTTPD-SEND-FILE: for Apache and Lighttpd v. < 1.5
    # 1. Set error handling
    ini_set('display_errors', 1);
    set_error_handler('error_handler_dispatcher', E_ALL ^ E_NOTICE);
    # 2. Set user configuration
    call_if_exists('configure');
    # 3. Loading libs
    require_once_dir(option('lib_dir'));
    # 4. Starting session
    if (!defined('SID') && option('session')) {
        if (!is_bool(option('session'))) {
            session_name(option('session'));
        }
        if (!session_start()) {
            trigger_error("An error occured while trying to start the session", E_USER_WARNING);
        }
    }
    # 5. Set some default methods if needed
    if (!function_exists('after')) {
        function after($output)
        {
            return $output;
        }
    }
    if (!function_exists('route_missing')) {
        function route_missing($request_method, $request_uri)
        {
            halt(NOT_FOUND, "({$request_method}) {$request_uri}");
        }
    }
    # 6. Set default routes used for default views
    dispatch(array("/_lim_css/*.css", array('_lim_css_filename')), 'render_limonade_css');
    /**
     * Internal controller that responds to route /_lim_css/*.css
     *
     * @access private
     * @return string
     */
    function render_limonade_css()
    {
        option('views_dir', file_path(option('limonade_public_dir'), 'css'));
        $fpath = file_path(params('_lim_css_filename') . ".css");
        return css($fpath);
    }
    dispatch(array("/_lim_public/**", array('_lim_public_file')), 'render_limonade_file');
    /**
     * Internal controller that responds to route /_lim_public/**
     *
     * @access private
     * @return void
     */
    function render_limonade_file()
    {
        $fpath = file_path(option('limonade_public_dir'), params('_lim_public_file'));
        return render_file($fpath, true);
    }
    # 7. Check request
    if ($rm = request_method()) {
        if (!request_method_is_allowed($rm)) {
            halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented");
        }
        # 5.1 Check matching route
        if ($route = route_find($rm, request_uri())) {
            params($route['params']);
            # 5.2 Load controllers dir
            require_once_dir(option('controllers_dir'));
            if (function_exists($route['function'])) {
                # 5.3 Call before function
                call_if_exists('before');
                # 5.4 Call matching controller function and output result
                if ($output = call_user_func($route['function'])) {
                    echo after(error_notices_render() . $output);
                }
                if (defined('SID')) {
                    session_write_close();
                }
                exit;
            } else {
                halt(SERVER_ERROR, "Routing error: undefined function '{$route['function']}'", $route);
            }
        } else {
            route_missing($rm, request_uri());
        }
    } else {
        halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented");
    }
}