[enh] Bootstrap PHP interface

This commit is contained in:
kload
2014-11-08 14:31:48 +01:00
parent 2de9bf3b2c
commit 0cc34124bd
33 changed files with 13802 additions and 0 deletions

View File

@@ -0,0 +1,193 @@
<?php
/**
* Abstract methods that might be redefined by user
* Do not include this file in your app: it only aims to provide documentation
* about those functions.
*
* @package limonade
* @subpackage abstract
*/
/**
* It will be called when app is launched (at the begining of the run function).
* You can define options inside it, a connection to a database ...
*
* @abstract this function might be redefined by user
* @return void
*/
function configure()
{
return;
}
/**
* Called in run() just after session start, and before checking request method
* and output buffer start.
*
* @abstract this function might be redefined by user
* @return void
*/
function initialize()
{
return;
}
/**
* Called in run() just after the route matching, in order to load controllers.
* If not specfied, the default function is called:
*
* <code>
* function autoload_controller($callback)
* {
* require_once_dir(option('controllers_dir'));
* }
* </code>
*
*
* @param string $callback the callback defined in matching route
* @return void
*/
function autoload_controller($callback)
{
return;
}
/**
* Called before each request.
* This is very useful to define a default layout or passing common variables
* to the templates.
*
* @abstract this function might be redefined by user
* @param array() $route array (like returned by {@link route_build()},
* with keys "method", "pattern", "names", "callback", "options")
* @return void
*/
function before($route)
{
}
/**
* An `after` output filter
*
* Called after each request and can apply a transformation to the output
* (except for `render_file` outputs which are sent directly to the output buffer).
*
* @abstract this function might be redefined by user
* @param string $output
* @param array() $route array (like returned by {@link route_find()},
* with keys "method", "pattern", "names", "callback", "params", "options")
* @return string
*/
function after($output, $route)
{
# Call functions...
# .. modifies $output...
return $output;
}
/**
* Not found error output
*
* @abstract this function might be redefined by user
* @param string $errno
* @param string $errstr
* @param string $errfile
* @param string $errline
* @return string "not found" output string
*/
function not_found($errno, $errstr, $errfile=null, $errline=null)
{
}
/**
* Server error output
*
* @abstract this function might be redefined by user
* @param string $errno
* @param string $errstr
* @param string $errfile
* @param string $errline
* @return string "server error" output string
*/
function server_error($errno, $errstr, $errfile=null, $errline=null)
{
}
/**
* Called when a route is not found.
*
*
* @abstract this function might be redefined by user
* @param string $request_method
* @param string $request_uri
* @return void
*/
function route_missing($request_method, $request_uri)
{
halt(NOT_FOUND, "($request_method) $request_uri"); # by default
}
/**
* Called before stoppping and exiting application.
*
* @abstract this function might be redefined by user
* @param boolean exit or not
* @return void
*/
function before_exit($exit)
{
}
/**
* Rendering prefilter.
* Useful if you want to transform your views before rendering.
* The first three parameters are the same as those provided
* to the `render` function.
*
* @abstract this function might be redefined by user
* @param string $content_or_func a function, a file in current views dir or a string
* @param string $layout
* @param array $locals
* @param array $view_path (by default <code>file_path(option('views_dir'),$content_or_func);</code>)
* @return array with, in order, $content_or_func, $layout, $locals vars
* and the calculated $view_path
*/
function before_render($content_or_func, $layout, $locals, $view_path)
{
# transform $content_or_func, $layout, $locals or $view_path…
return array($content_or_func, $layout, $locals, $view_path);
}
/**
* Called only if rendering $output is_null,
* like in a controller with no return statement.
*
* @abstract this function might be defined by user
* @param array() $route array (like returned by {@link route_build()},
* with keys "method", "pattern", "names", "callback", "options")
* @return string
*/
function autorender($route)
{
# process output depending on $route
return $output;
}
/**
* Called if a header is about to be sent
*
* @abstract this function might be defined by user
* @param string the headers that limonade will send
* @return void
*/
function before_sending_header($header)
{
}

View File

@@ -0,0 +1,173 @@
<?php
/**
* @package tests
* @subpackage assertions
*/
# ============================================================================ #
# ASSERTIONS #
# ============================================================================ #
/**
* assert_true
*
* @param string $value
* @param string $message
* @return boolean
*/
function assert_true($value, $message = '<1> should be TRUE')
{
test_run_assertion();
return assert('$value === TRUE; //'.$message);
}
function assert_false($value, $message = '<1> should be FALSE')
{
test_run_assertion();
return assert('$value === FALSE; //'.$message);
}
function assert_null($value, $message = '<1> should be NULL')
{
test_run_assertion();
return assert('$value === NULL; //'.$message);
}
function assert_not_null($value, $message = '<1> should not be NULL')
{
test_run_assertion();
return assert('$value !== NULL; //'.$message);
}
function assert_empty($value, $message = '<1> should be empty')
{
test_run_assertion();
return assert('empty($value); //'.$message);
}
function assert_not_empty($value, $message = '<1> should not be empty')
{
test_run_assertion();
return assert('!empty($value); //'.$message);
}
function assert_equal($expected, $value, $message = '<1> should be equal to <2>')
{
test_run_assertion();
return assert('$expected == $value; //'.$message);
}
function assert_not_equal($expected, $value, $message = '<1> should not equal to <2>')
{
test_run_assertion();
return assert('$expected != $value; //'.$message);
}
function assert_identical($expected, $value, $message = '<1> should be identical to <2>')
{
test_run_assertion();
return assert('$expected === $value; //'.$message);
}
function assert_not_identical($expected, $value, $message = '<1> should not be identical to <2>')
{
test_run_assertion();
return assert('$expected !== $value; //'.$message);
}
function assert_match($pattern, $string, $message = '<2> expected to match regular expression <1>') {
test_run_assertion();
return assert('preg_match($pattern, $string); //'.$message);
}
function assert_no_match($pattern, $string, $message = '<2> expected to not match regular expression <1>') {
test_run_assertion();
return assert('!preg_match($pattern, $string); //'.$message);
}
function assert_type($type, $value, $message = '<1> is not of type <2>') {
test_run_assertion();
$predicate = 'is_' . strtolower(is_string($type) ? $type : gettype($type));
return assert('$predicate($value); //'.$message);
}
function assert_instance_of($class, $object, $message = '<2> is not an instance of class <1>') {
test_run_assertion();
return assert('$object instanceof $class; //'.$message);
}
function assert_length_of($value, $length, $message = '<1> expected to be of length <2>') {
test_run_assertion();
$count = is_string($value) ? 'strlen' : 'count';
return assert('$count($value) == $length; //'.$message);
}
function assert_trigger_error($callable, $args = array(), $message = '<1> should trigger an error') {
test_run_assertion();
$trigger_errors = count($GLOBALS["limonade"]["test_errors"]);
set_error_handler("test_error_handler");
$result = call_user_func_array($callable, $args);
restore_error_handler();
return assert('$trigger_errors < count($GLOBALS["limonade"]["test_errors"]); //'.$message);
}
# TODO add web browser assertions assert_http_get, assert_http_response... as in SimpleTest (http://www.simpletest.org/en/web_tester_documentation.html)
function assert_header($response, $expected_name, $expected_value = null, $message = "expected header '%s' to be equal to '%s' but received '%s: %s'")
{
test_run_assertion();
# see assert_header in http://github.com/fnando/voodoo-test/blob/f3b0994ef138a6ba94d5e7cef6c1fb1720797a86/lib/assertions.php
$headers = preg_split("/^\s*$/ms", $response);
//var_dump($headers);
$headers = preg_replace("/\s*$/sm", "", $headers[0]);
//var_dump($headers);
$regex_header = str_replace("/", "\\/", $expected_name);
$regex_header = str_replace(".", "\\.", $regex_header);
$header = $expected_name;
# from http://www.faqs.org/rfcs/rfc2616
# Field names are case-insensitive
if ($expected_value) {
$regex = "/^{$regex_header}:(.*?)$/ism";
$header .= ": {$expected_value}";
} else {
$regex = "/^{$regex_header}(:.*?)?$/ism";
}
$has_header = preg_match($regex, $headers, $matches);
$sent_header = trim((string)$matches[1]);
if(empty($sent_header))
{
if(is_null($expected_value))
{
$message = "expected header '%s' but header has not been sent";
}
else
{
$message = "expected header '%s' to be equal to '%s' but header has not been sent";
}
$message = sprintf($message, $expected_name, $expected_value);
return assert("false; //".$message);
}
else if($expected_value)
{
$message = sprintf($message, $expected_name, $expected_value, $expected_name, $sent_header);
return assert('$expected_value && $sent_header == $expected_value; //'.$message);
}
return assert("true; //");
}
function assert_status($response, $expected_status, $message = "expected status code to be equal to '%s' but received '%s'")
{
$lines = explode('\n', trim($response));
if (preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)/i', $lines[0], $matches))
{
$status = $matches[2];
return assert('$expected_status == $status; //'.sprintf($message, $expected_status, $status));
}
return assert("false; //no status code returned in this response string");
}

View File

@@ -0,0 +1,220 @@
/* -----------------------------------------------------------------------
Blueprint CSS Framework 0.8
http://blueprintcss.org
* Copyright (c) 2007-Present. See LICENSE for more info.
* See README for instructions on how to use Blueprint.
* For credits and origins, see AUTHORS.
* This is a compressed file. See the sources in the 'src' directory.
----------------------------------------------------------------------- */
/* reset.css */
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, em, img, q, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {margin:0;padding:0;border:0;font-weight:inherit;font-style:inherit;font-size:100%;font-family:inherit;vertical-align:baseline;}
body {line-height:1.5;}
table {border-collapse:separate;border-spacing:0;}
caption, th, td {text-align:left;font-weight:normal;}
table, td, th {vertical-align:middle;}
blockquote:before, blockquote:after, q:before, q:after {content:"";}
blockquote, q {quotes:"" "";}
a img {border:none;}
/* typography.css */
body {font-size:75%;color:#222;background:#fff;font-family:"Helvetica Neue", Arial, Helvetica, sans-serif;}
h1, h2, h3, h4, h5, h6 {font-weight:normal;color:#111;}
h1 {font-size:3em;line-height:1;margin-bottom:0.5em;}
h2 {font-size:2em;margin-bottom:0.75em;}
h3 {font-size:1.5em;line-height:1;margin-bottom:1em;}
h4 {font-size:1.2em;line-height:1.25;margin-bottom:1.25em;}
h5 {font-size:1em;font-weight:bold;margin-bottom:1.5em;}
h6 {font-size:1em;font-weight:bold;}
h1 img, h2 img, h3 img, h4 img, h5 img, h6 img {margin:0;}
p {margin:0 0 1.5em;}
p img.left {float:left;margin:1.5em 1.5em 1.5em 0;padding:0;}
p img.right {float:right;margin:1.5em 0 1.5em 1.5em;}
a:focus, a:hover {color:#000;}
a {color:#009;text-decoration:underline;}
blockquote {margin:1.5em;color:#666;font-style:italic;}
strong {font-weight:bold;}
em, dfn {font-style:italic;}
dfn {font-weight:bold;}
sup, sub {line-height:0;}
abbr, acronym {border-bottom:1px dotted #666;}
address {margin:0 0 1.5em;font-style:italic;}
del {color:#666;}
pre {margin:1.5em 0;white-space:pre;}
pre, code, tt {font:1em 'andale mono', 'lucida console', monospace;line-height:1.5;}
li ul, li ol {margin:0 1.5em;}
ul, ol {margin:0 1.5em 1.5em 1.5em;}
ul {list-style-type:disc;}
ol {list-style-type:decimal;}
dl {margin:0 0 1.5em 0;}
dl dt {font-weight:bold;}
dd {margin-left:1.5em;}
table {margin-bottom:1.4em;width:100%;}
th {font-weight:bold;}
thead th {background:#c3d9ff;}
th, td, caption {padding:4px 10px 4px 5px;}
tr.even td {background:#e5ecf9;}
tfoot {font-style:italic;}
caption {background:#eee;}
.small {font-size:.8em;margin-bottom:1.875em;line-height:1.875em;}
.large {font-size:1.2em;line-height:2.5em;margin-bottom:1.25em;}
.hide {display:none;}
.quiet {color:#666;}
.loud {color:#000;}
.highlight {background:#ff0;}
.added {background:#060;color:#fff;}
.removed {background:#900;color:#fff;}
.first {margin-left:0;padding-left:0;}
.last {margin-right:0;padding-right:0;}
.top {margin-top:0;padding-top:0;}
.bottom {margin-bottom:0;padding-bottom:0;}
/* forms.css */
label {font-weight:bold;}
fieldset {padding:1.4em;margin:0 0 1.5em 0;border:1px solid #ccc;}
legend {font-weight:bold;font-size:1.2em;}
input.text, input.title, textarea, select {margin:0.5em 0;border:1px solid #bbb;}
input.text:focus, input.title:focus, textarea:focus, select:focus {border:1px solid #666;}
input.text, input.title {width:300px;padding:5px;}
input.title {font-size:1.5em;}
textarea {width:390px;height:250px;padding:5px;}
.error, .notice, .success {padding:.8em;margin-bottom:1em;border:2px solid #ddd;}
.error {background:#FBE3E4;color:#8a1f11;border-color:#FBC2C4;}
.notice {background:#FFF6BF;color:#514721;border-color:#FFD324;}
.success {background:#E6EFC2;color:#264409;border-color:#C6D880;}
.error a {color:#8a1f11;}
.notice a {color:#514721;}
.success a {color:#264409;}
.box {padding:1.5em;margin-bottom:1.5em;background:#E5ECF9;}
hr {background:#ddd;color:#ddd;clear:both;float:none;width:100%;height:.1em;margin:0 0 1.45em;border:none;}
hr.space {background:#fff;color:#fff;}
.clearfix:after, .container:after {content:"\0020";display:block;height:0;clear:both;visibility:hidden;overflow:hidden;}
.clearfix, .container {display:block;}
.clear {clear:both;}
/* -----------------------------------------------------------------------
LIMONADE
Design and logo by <a href="http://www.minimau.com">Minimau</a>
----------------------------------------------------------------------- */
html {
background-color: #b4a689;
text-align: center;
}
body {
width: auto; /* 16 col */
margin: 0 20px;
text-align: left;
/*background: #fff url(blueprint/src/grid.png);*/
font-family: Verdana, Geneva, sans-serif;
color: #303030;
}
a, a:hover, a:visited {
color: #4596cd;
}
a:hover {
text-decoration: none;
}
#header, h1, h2, h3, h4 {
font-family: "Arial Black", Gadget, sans-serif;
}
h1 {
color: #b4a689;
font-size: 2em;
line-height: 2;
border-bottom: 7px solid #000;
margin-bottom: 0.75em;
margin-top:0;
}
h2 {
font-size: 1.5em;
color: #cddb12;
margin-top: 2em;
line-height: 0.8;
margin-bottom: 1.2em;
}
h3 {
font-size: 1.33em;
line-height: 0.89;
margin-top: 2.66em;
margin-bottom: 1.33em;
color:#95b383;
}
pre {
background-color: #cddb12;
font-size: 12px;
padding: 1.5em;
margin-bottom: 1.5em;
overflow: auto;
}
code {
font: 10px Monaco, "Courier New", Courier, monospace;
color: #0d562a;
}
#header {
/*position:relative;*/
height: 187px; /* 12 lines */
background: #fff url(<?=url_for('/_lim_public/img/bg_header.png')?>) no-repeat 0 0;
margin-top: 10px;
padding:0;
}
#header h1 {
position: absolute;
left:-9999px;
margin:0;
}
#footer {
padding: 0 55px;
background-color: #1a1818;
color: #999;
height: 2em;
line-height: 2em;
text-align: right;
}
#footer a {
color: #a3d8de;
text-decoration: none;
}
#footer a:hover {
color: #fff;
}
#content {
background-color: #fff;
padding: 0 55px;
min-height: 400px;
}
p.bt {
text-align:right;
}
p.bt a {
text-decoration:none;
padding: 2px 4px;
}
p.bt a:hover {
background-color: #4596cd;
color: #fff;
}
#debug-menu {
position: fixed;
top: 0px;
right:20px;
background-color: rgba(100,100,100, 0.7);
padding:5px;
}
#debug-menu a {
color: #fff;
font-size: 90%;
text-decoration:none;
}
#debug-menu a:hover {
text-decoration: underline;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@@ -0,0 +1,350 @@
<?php
/**
* @package tests
*/
# ============================================================================ #
# TESTS #
# ============================================================================ #
/**
* load assertions
*/
require_once dirname(__FILE__)."/assertions.php";
/**
* Constants and globals
*/
if(!defined('DS')) define("DS", DIRECTORY_SEPARATOR);
if(!array_key_exists("limonade", $GLOBALS))
$GLOBALS["limonade"] = array();
if(!array_key_exists("test_cases", $GLOBALS["limonade"]))
$GLOBALS["limonade"]["test_cases"] = array();
if(!array_key_exists("test_errors", $GLOBALS["limonade"]))
$GLOBALS["limonade"]["test_errors"] = array();
if(!array_key_exists("test_case_current", $GLOBALS["limonade"]))
$GLOBALS["limonade"]["test_case_current"] = NULL;
if(!array_key_exists("test_suites", $GLOBALS["limonade"]))
$GLOBALS["limonade"]["test_suites"] = NULL;
ini_set("display_errors", true);
error_reporting(E_ALL ^ (E_USER_WARNING | E_NOTICE | E_USER_NOTICE));
// error_reporting(E_ALL | E_STRICT);
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_BAIL, 0);
assert_options(ASSERT_QUIET_EVAL, 0);
assert_options(ASSERT_CALLBACK, 'test_assert_failure');
# TODO: separate display from logic
# TODO: clean results output
# TODO: add all tests results
/**
* Starts a test suite
*
* @param string $name
* @return void
*/
function test_suite($name)
{
$GLOBALS["limonade"]["test_suites"] = $name;
echo test_cli_format("===========================================================\n", 'white');
echo test_cli_format(">>>> START $name tests suites\n", 'white');
echo test_cli_format("-----------------------------------------------------------\n", 'white');
}
/**
* Ends the last group of test suites
*
* @return void
*/
function end_test_suite()
{
$name = $GLOBALS["limonade"]["test_suites"];
$failures = 0;
$tests = 0;
$passed_tests = 0;
$assertions = 0;
foreach($GLOBALS["limonade"]["test_cases"] as $test)
{
$failures += $test['failures'];
$assertions += $test['assertions'];
if(empty($test['failures'])) $passed_tests++;
$tests++;
}
echo ">> ENDING $name tests suites\n ";
echo $failures > 0 ? test_cli_format("|FAILED!|", "red") : test_cli_format("|PASSED|", "green");;
echo " Passes ".$passed_tests."/".$tests.", ";
echo " {$failures} failures for {$assertions} assertions.\n";
echo test_cli_format("===========================================================\n", 'white');
}
/**
* Starting a new test case
*
* @param string $name
* @return void
*/
function test_case($name)
{
$name = strtolower($name); // TODO: normalize name
if(!array_key_exists($name, $GLOBALS["limonade"]["test_cases"]))
{
$GLOBALS["limonade"]["test_cases"][$name] = array(
"name" => $name,
"assertions" => 0,
"failures" => 0,
"description" => NULL
);
$GLOBALS["limonade"]["test_case_current"] = $name;
}
else
{
}
}
/**
* Displays and ending the current tests suite
*
* @return void
*/
function end_test_case()
{
$name = $GLOBALS["limonade"]["test_case_current"];
echo "## ".strtoupper($name)."\n";
$desc = test_case_describe();
if(!is_null($desc)) echo $desc."\n";
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
test_case_execute_current();
if(!is_null($name))
{
$test = $GLOBALS["limonade"]["test_cases"][$name];
// closing previous test
echo "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
echo $test['failures'] > 0 ? test_cli_format("|FAILED!|", "red") : test_cli_format("|PASSED|", "green");
echo " Test case '$name' finished: ";
echo count(test_case_all_func())." tests, ";
echo " {$test['failures']} failures for {$test['assertions']} assertions.\n";
echo "-----------------------------------------------------------\n";
}
$GLOBALS["limonade"]["test_case_current"] = null;
}
/**
* Describes the current tests suite
*
* @param string $msg
* @return string tests description
*/
function test_case_describe($msg = NULL)
{
$test =& test_case_current();
if(!is_null($msg))
{
$test["description"] = $msg;
}
//var_dump($test["description"]);
return $test["description"];
}
/**
* Returns all user test case functions
*
* @access private
* @return void
*/
function test_case_all_func()
{
$functions = get_defined_functions();
$functions = $functions['user'];
$tests = array();
$name = $GLOBALS["limonade"]["test_case_current"];
while ($func = array_shift($functions)) {
$regexp = "/^test_{$name}_(.*)$/";
if(!preg_match($regexp, $func)) continue;
if($func == test_before_func_name()) continue;
// TODO: adding break for all test api methods
$tests[] = $func;
}
return $tests;
}
/**
* Execute current test case
*
* @access private
* @return void
*/
function test_case_execute_current()
{
$tests = test_case_all_func();
while($func = array_shift($tests))
{
test_call_func(test_before_func_name());
call_user_func($func);
}
}
function &test_case_current()
{
$name = $GLOBALS["limonade"]["test_case_current"];
return $GLOBALS["limonade"]["test_cases"][$name];
}
function test_before_func_name()
{
$test = test_case_current();
$func = "before_each_test_in_".$test["name"];
return $func;
}
function test_before_assert_func_name()
{
$test = test_case_current();
$func = "before_each_assert_in_$name".$test["name"];
return $func;
}
function test_run_assertion()
{
$name = $GLOBALS["limonade"]["test_case_current"];
$GLOBALS["limonade"]["test_cases"][$name]['assertions']++;
test_call_func(test_before_assert_func_name());
}
/**
* Calls a function if exists
*
* @param string $func the function name
* @param mixed $arg,.. (optional)
* @return mixed
*/
function test_call_func($func)
{
if(empty($func)) return;
$args = func_get_args();
$func = array_shift($args);
if(function_exists($func)) return call_user_func_array($func, $args);
return;
}
/**
* Error handler
*
* @access private
* @return boolean true
*/
function test_error_handler($errno, $errstr, $errfile, $errline)
{
if($errno < E_USER_ERROR || $errno > E_USER_NOTICE)
echo test_cli_format("!!! ERROR", "red") . " [$errno], $errstr in $errfile at line $errline\n";
$GLOBALS["limonade"]["test_errors"][] = array($errno, $errstr, $errfile, $errline);
return true;
}
/**
* Assert callback
*
* @access private
* @param string $script
* @param string $line
* @param string $message
* @return void
*/
function test_assert_failure($script, $line, $message)
{
// Using the stack trace, find the outermost assert*() call
$stacktrace = array_slice(debug_backtrace(), 1); // skip self
$assertion = reset($stacktrace);
while ($stackframe = array_shift($stacktrace)) {
if (!preg_match('/^assert/', $stackframe['function']))
break;
$assertion = $stackframe;
}
extract($assertion, EXTR_PREFIX_ALL, 'assert');
$code = explode("\n", file_get_contents($assert_file));
$code = trim($code[$assert_line - 1]);
list($assert_code, $message) = explode("//", $message);
echo test_cli_format("Assertion failed", "yellow");
echo " in script *{$assert_file}* (line {$assert_line}):\n";
echo " * assertion: $code\n";
echo " * message: $message\n";
$name = $GLOBALS["limonade"]["test_case_current"];
$GLOBALS["limonade"]["test_cases"][$name]['failures']++;
}
function test_cli_format($text, $format) {
$formats = array(
"blue" => 34,
"bold" => 1,
"green" => 32,
"highlight" => 7,
"light_blue" => 36,
"purple" => 35,
"red" => 31,
"underline" => 4,
"white" => 37,
"yellow" => 33
);
if (array_key_exists($format, $formats)) $format = $formats[$format];
return chr(27) . "[01;{$format} m{$text}" . chr(27) . "[00m";
}
/**
* Do HTTP request and return the response content.
*
* @param string $url
* @param string $method
* @param bool $include_header
* @return string
* @author Nando Vieira
*/
function test_request($url, $method="GET", $include_header=false, $post_data=array(), $http_header=array()) {
$method = strtoupper($method);
$allowed_methods = array("GET", "PUT", "POST", "DELETE", "HEAD");
if(!in_array($method, $allowed_methods))
{
$message = "The requested method '$method' is not allowed";
return assert('false; //'.$message);
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, $include_header);
curl_setopt($curl, CURLOPT_HTTPHEADER, $http_header);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
if($method == 'POST' || $method == 'PUT')
{
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
}
if($method == 'HEAD')
{
curl_setopt($curl, CURLOPT_NOBODY, true);
}
$response = curl_exec($curl);
curl_close($curl);
return $response;
}

View File

@@ -0,0 +1,37 @@
<?php if(option('env') > ENV_PRODUCTION && option('debug')): ?>
<?php if(!$is_http_error): ?>
<p>[<?php echo error_type($errno)?>]
<?php echo $errstr?> (in <strong><?php echo $errfile?></strong> line <strong><?php echo $errline?></strong>)
</p>
<?php endif; ?>
<?php if($debug_args = set('_lim_err_debug_args')): ?>
<h2 id="debug-arguments">Debug arguments</h2>
<pre><code><?php echo h(print_r($debug_args, true))?></code></pre>
<?php endif; ?>
<h2 id="limonade-options">Options</strong></h2>
<pre><code><?php echo h(print_r(option(), true))?></code></pre>
<p class="bt top"><a href="#header">[ &#x2191; ]</a></p>
<h2 id="environment">Environment</h2>
<pre><code><?php echo h(print_r(env(), true))?></code></pre>
<p class="bt top"><a href="#header">[ &#x2191; ]</a></p>
<h2 id="debug-backtrace">Backtrace</h2>
<pre><code><?php echo h(print_r(debug_backtrace(), true))?></code></pre>
<p class="bt top"><a href="#header">[ &#x2191; ]</a></p>
<div id="debug-menu">
<?php if($debug_args = set('_lim_err_debug_args')): ?>
<a href="#debug-arguments">Debug arguments</a> |
<?php endif; ?>
<a href="#limonade-options">Options</a> |
<a href="#environment">Environment</a> |
<a href="#debug-backtrace">Backtrace</a> |
<a href="#header">[ &#x2191; ]</a>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,15 @@
<?php if(!empty($notices)): ?>
<div class="lim-debug lim-notices">
<h4> &#x2192; Notices and warnings</h4>
<dl>
<?php $cpt = 1; foreach($notices as $notice): ?>
<dt>[<?php echo $cpt.'. '.error_type($notice['errno'])?>]</dt>
<dd>
<?php echo $notice['errstr']?> in <strong><code><?php echo $notice['errfile']?></code></strong>
line <strong><code><?php echo $notice['errline']?></code></strong>
</dd>
<?php $cpt++; endforeach; ?>
</dl>
<hr>
</div>
<?php endif; ?>

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Limonade, the fizzy PHP micro-framework</title>
<link rel="stylesheet" href="<?php echo url_for('/_lim_css/screen.css');?>" type="text/css" media="screen">
</head>
<body>
<div id="header">
<h1>Limonade</h1>
</div>
<div id="content">
<?php echo error_notices_render(); ?>
<div id="main">
<?php echo $content;?>
<hr class="space">
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,6 @@
<h1><?php echo h(error_http_status($errno));?></h1>
<?php if($is_http_error): ?>
<p><?php echo h($errstr)?></p>
<?php endif; ?>
<?php echo render('_debug.html.php', null, $vars); ?>