コード例 #1
0
function test_inertia_default_response_()
{
    $html = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" . "<html>\n<head>\n<title>Inertia Test Page</title>\n</head>\n<body>\n<h1>Inertia Test Page</h1>\n" . "<p><a href=\"http://sandeepshetty.github.com/inertia/\">Inertia</a> has been successfully installed on this system!</p>" . "<p><a href=\"tests/retest.php\">Run all tests</a> and confirm everything passes before you proceed.</p>\n</body>\n</html>";
    should_return(response_(STATUS_OK, array('content-type' => 'text/html'), $html), when_passed('/', ''));
    $html = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" . "<html>\n<head>\n<title>404 Not Found</title>\n</head>\n<body>\n<h1>Not Found</h1>\n<p>The requested URL /foo was not found on this server.</p>\n</body>\n</html>";
    should_return(response_(STATUS_NOT_FOUND, array('content-type' => 'text/html'), $html), when_passed('/foo', '/foo'));
}
コード例 #2
0
function default_request_($handler, $method, $path, $query, $headers, $body)
{
    if (handler_exists_($handler)) {
        load_handler_($handler);
        if ($handler_function = function_exists_(handler_function_($handler))) {
            $params = array($method, $path, $query, $headers, $body);
            $response = call_user_func_array($handler_function, $params);
            return $response;
        }
    }
    return response_(STATUS_NOT_FOUND);
}
コード例 #3
0
function valid_response($response)
{
    if (!is_valid_response($response)) {
        $status_code = STATUS_OK;
        $headers = array();
        if (is_array($response)) {
            if (isset($response['status_code'])) {
                $status_code = $response['status_code'];
                unset($response['status_code']);
            }
            if (isset($response['headers']) and is_array($response['headers'])) {
                $headers = $response['headers'];
                unset($response['headers']);
            }
        }
        $response = response_($status_code, $headers, $response);
    }
    return $response;
}
コード例 #4
0
function valid_response_($response)
{
    $handler_function_without_explicit_return = is_null($response);
    if ($handler_function_without_explicit_return) {
        $response = '';
    }
    if (response_is_valid_($response)) {
        $content_type_exists = array_key_exists('content-type', $response['headers']);
        if (!$content_type_exists) {
            $response['headers']['content-type'] = 'application/x-php-value';
        } else {
            $is_serialized_php = is_equal_($response['headers']['content-type'], 'application/x-serialized-php');
            if ($is_serialized_php) {
                $response['body'] = unserialize($response['body']);
                $response['headers']['content-type'] = 'application/x-php-value';
            }
        }
    } else {
        $response = response_(STATUS_OK, array('content-type' => 'application/x-php-value'), $response);
    }
    return $response;
}
コード例 #5
0
ファイル: bootstrap.php プロジェクト: notmaintained/inertia
function inertia_default_response_($path, $relative_uri)
{
    if (is_equal_('/', $path)) {
        return response_(STATUS_OK, array('content-type' => 'text/html'), inertia_test_page_());
    } else {
        return response_(STATUS_NOT_FOUND, array('content-type' => 'text/html'), inertia_404_not_found_($relative_uri));
    }
}
コード例 #6
0
function testhelper_response_returned_by_request_($status_code, $headers = array(), $body = '')
{
    return valid_response_(response_($status_code, $headers, $body));
}
コード例 #7
0
ファイル: glue.lib.php プロジェクト: notmaintained/oboxapps
function glue_response($req, $response)
{
    $template_vars = is_array($response) ? array_merge($req, $response) : array_merge($req, array('content' => $response));
    $headers = array_merge(array('content-type' => 'text/html'), response_headers($response));
    if (isset($template_vars['template'])) {
        list($handler, $template) = template_resolver($template_vars['template']);
        unset($template_vars['template']);
        //TODO: feels liks a ugly hack to assume func from template but works well for handler-less (template-only) routes
        if (!isset($template_vars['handler'])) {
            $template_vars['handler'] = $handler;
        }
        if (!isset($template_vars['func'])) {
            $template_vars['func'] = $template;
        }
        if (template_file_exists(handler_template($handler, $template))) {
            if (isset($template_vars['layout'])) {
                $layout = $template_vars['layout'];
                unset($template_vars['layout']);
                if (is_equal(false, $layout)) {
                    return response_(response_status_code($template_vars), $headers, template_render(handler_template($handler, $template), $template_vars));
                } else {
                    list($layout_handler, $layout_template) = template_resolver($layout);
                    return response_(response_status_code($template_vars), $headers, template_compose(handler_template($handler, $template), $template_vars, handler_template($layout_handler, $layout_template), $template_vars));
                }
            } else {
                return response_(response_status_code($template_vars), $headers, template_compose(handler_template($handler, $template), $template_vars, handler_layout($handler), $template_vars));
            }
        }
    }
    return _200_plain(print_r($response, true));
}
コード例 #8
0
function test_dispatch_request_()
{
    $handler = 'testhandler' . rand();
    should_return(valid_response_(response_(STATUS_NOT_FOUND)), when_passed($handler, METHOD_GET, '/', array(), array(), ''));
    testhelper_create_handler_($handler);
    testhelper_write_handler_function_($handler);
    should_return(valid_response_(response_(STATUS_OK)), when_passed($handler, METHOD_GET, '/', array(), array(), ''));
    testhelper_remove_handler_($handler);
}
コード例 #9
0
function http_request_($handler, $method, $path, $query, $headers, $body)
{
    return response_(STATUS_INTERNAL_SERVER_ERROR, array(), 'HTTP wrapper support coming soon...');
}