private function include_library() { require_once Config::get('plugin_functions') . '/system.php'; require_once_dir(Config::get('plugin_functions')); require_once_dir(Config::get('plugin_classes')); require_once_dir(Config::get('conf_dir')); if (file_exists(Config::get('ctrl_dir') . '/application_controller.class.php')) { require_once Config::get('ctrl_dir') . '/application_controller.class.php'; } if (file_exists(Config::get('help_dir') . '/application.php')) { require_once Config::get('help_dir') . '/application.php'; } }
/** * Configuration of the limonade framework. Automatically called by run() */ function configure() { option('session', 'filez'); // specific session name option('views_dir', option('root_dir') . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR); // Layout settings error_layout('layout' . DIRECTORY_SEPARATOR . 'error.html.php'); layout('layout' . DIRECTORY_SEPARATOR . 'default.html.php'); require_once_dir(option('lib_dir')); // error handling set_error_handler('fz_php_error_handler', E_ALL ^ E_NOTICE); // Log every error set_exception_handler('fz_exception_handler'); // also handle uncatched excpeptions }
/** * 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"); } }
function autoload_controller($callback) { require_once_dir(option('controllers_dir')); }
<?php require_once_dir(dirname(__FILE__) . '/lemon_tree');
<?php // include system init require_once dirname(__FILE__) . '/../config/init.php'; // include all migration files require_once_dir(Config::get('migr_dir')); // init default tables require_once dirname(__FILE__) . '/install.php'; // init $INTEND_VERSION = isset($argv[1]) ? $argv[1] : '99991231235959'; // functions function print_migration_status($direction, $classname, $version) { echonl('================================================================================'); echonl($classname . '.' . strtolower($direction) . '() is executed.'); echonl('Schema version is ' . $version . ' now.'); } // connect db connection $db = Context::get('db'); $db->connect(); $schema_version = new SchemaVersion(); if ($schema_version->count() == 0) { $schema_version->version = 0; $schema_version->save(); } $schema_version = $schema_version->find(); // read migration files... $files = get_files(Config::get('migr_dir')); if ($INTEND_VERSION >= $schema_version->version) { sort($files); $direction = 'UP';
/** * 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>"); } }
function test_main_require_once_dir() { $root = dirname(dirname(__FILE__)); ob_start(); assert_empty(require_once_dir($root)); $files = require_once_dir($root, "AUTHORS"); assert_empty(ob_get_contents()); ob_clean(); assert_length_of($files, 1); assert_match('/AUTHORS$/', $files[0]); ob_start(); $files = require_once_dir($root, "CHANGES", false); assert_not_empty(ob_get_contents()); ob_clean(); $lib = $root.'/lib'; // pb because it loads abstract.php that conflict with tests that use abstracts // $limonade = $lib.'/limonade'; // // $files = require_once_dir($limonade); // assert_not_empty($files); $tests_lib = $root.'/tests/data/lib0'; $libs = array('a', 'b', 'c'); foreach($libs as $lib) assert_false(defined('TEST_LIB_'.strtoupper($lib))); $files = require_once_dir($tests_lib); assert_not_empty($files); assert_length_of($files, 3); foreach($libs as $lib) assert_true(defined('TEST_LIB_'.strtoupper($lib))); assert_empty(require_once_dir($root.'/tests/data/')); assert_true(is_array(require_once_dir($root.'/tests/data/'))); assert_empty(require_once_dir($root.'/tests/data/unknown_dir')); assert_true(is_array(require_once_dir($root.'/tests/data/unknown_dir'))); }
function test_main_require_once_dir() { $root = dirname(dirname(__FILE__)); ob_start(); assert_empty(require_once_dir($root)); $files = require_once_dir($root, "AUTHORS"); ob_clean(); assert_length_of($files, 1); assert_match('/AUTHORS$/', $files[0]); $lib = $root . '/lib'; $limonade = $lib . '/limonade'; $files = require_once_dir($limonade); assert_not_empty($files); $tests_lib = $root . '/tests/data/lib0'; $libs = array('a', 'b', 'c'); foreach ($libs as $lib) { assert_false(defined('TEST_LIB_' . strtoupper($lib))); } $files = require_once_dir($tests_lib); assert_not_empty($files); assert_length_of($files, 3); foreach ($libs as $lib) { assert_true(defined('TEST_LIB_' . strtoupper($lib))); } assert_empty(require_once_dir($root . '/tests/data/')); assert_true(is_array(require_once_dir($root . '/tests/data/'))); assert_empty(require_once_dir($root . '/tests/data/unknown_dir')); assert_true(is_array(require_once_dir($root . '/tests/data/unknown_dir'))); }
/** * 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"); } }