Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Initial implementation of WhoopsPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hassankhan committed Feb 2, 2014
1 parent a91db24 commit 6aca303
Showing 1 changed file with 56 additions and 37 deletions.
93 changes: 56 additions & 37 deletions plugins/WhoopsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@

class WhoopsPlugin implements \Zepto\PluginInterface {

public function after_plugins_load($container)
public function after_plugins_load()
{
$container["whoopsPrettyPageHandler"] = $container->share(
$container = func_get_arg(0);

// Add Whoops handlers
$container['whoopsPrettyPageHandler'] = $container->share(
function() {
return new PrettyPageHandler();
}
);

$container["whoopsJsonResponseHandler"] = $container->share(
$container['whoopsJsonResponseHandler'] = $container->share(
function() {
$handler = new JsonResponseHandler();
$handler->onlyForAjaxRequests(true);
Expand All @@ -32,76 +34,93 @@ function() {
);

$container["whoopsSlimInfoHandler"] = $container->protect(
function($container) {
// Do a test to see if page failed

$current_url_clean = $container['router']->get_current_route();
$current_url_dirty = $container['router']->get_current_route(false);

$headers = apache_request_headers();
function() use ($container) {

$content_type = $headers["CONTENT_TYPE"];
// Check to see if there is a current route, otherwise
// ignore because router isn't set up yet
try{
$current_route = $container['router']->current_route();
}
catch (\Exception $e) {
return;
}

$route_details = array();

$container['whoopsPrettyPageHandler']->setPageTitle('Shit hit the fan!');
$container['whoopsPrettyPageHandler']->setEditor('sublime');

if ($current_route !== null) {
$route_details = array(
"Route URL" => $current_route,
"Route Pattern" => ''
'Route URL' => $current_route->url(),
'Route Pattern' => $current_route->pattern()
);
}

$container["whoopsPrettyPageHandler"]->addDataTable(
'Zepto Application',
array_merge(array(
"Charset" => $headers["ACCEPT_CHARSET"],
"Locale" => $content_type['charset']
'Charset' => $container['request']->headers->get("Accept-Charset"),
'Locale' => $container['request']->getCharsets()
), $route_details)
);

$container["whoopsPrettyPageHandler"]->addDataTable(
'Request Information',
array_merge(array(
"URI" => $current_url_dirty,
"Request URI" => $current_url_clean

), $route_details)
array(
'URI' => $container['request']->getUri(),
'Request URI' => $container['request']->getRequestUri(),
'Path' => $container['request']->getPathInfo(),
'Query String' => $container['request']->getQueryString(),
'HTTP Method' => $container['request']->getMethod(),
'Script Name' => $container['request']->getScriptName(),
'Base URL' => $container['request']->getBaseUrl(),
'Scheme' => $container['request']->getScheme(),
'Port' => $container['request']->getPort(),
'Host' => $container['request']->getHost()
)
);
}
);

// $whoops_editor = get from config
$container["whoops"] = $container->share(
function() {
$run = new Run();
$run->pushHandler($container["whoopsPrettyPageHandler"]);
$run->pushHandler($container["whoopsJsonResponseHandler"]);
$run->pushHandler($container["whoopsSlimInfoHandler"]);

return $run;
}
);
$container['whoops'] = $container->share(
function($container) {
$run = new Run();
$run->pushHandler($container['whoopsPrettyPageHandler']);
$run->pushHandler($container['whoopsJsonResponseHandler']);
$run->pushHandler($container['whoopsSlimInfoHandler']);
return $run;
}
);
// echo __CLASS__ . '::after_plugins_load';

// Try to register Whoops handler, and set the callback function
try {
$container['whoops']->register();
$container['router']->error(array($container['whoops'], Run::EXCEPTION_HANDLER));
} catch (\Exception $e) {
return;
}
}

public function before_config_load(&$settings)
{
echo __CLASS__ . '::before_config_load';
// echo __CLASS__ . '::before_config_load';
}

public function before_file_load(&$content_dir)
{
echo __CLASS__ . '::before_file_load';
// echo __CLASS__ . '::before_file_load';
}

public function after_file_load(&$content)
{
echo __CLASS__ . '::after_file_load';
// $this->container['router']->error(array($container['whoops'], Run::EXCEPTION_HANDLER));
// echo __CLASS__ . '::after_file_load';
}

public function request_url(&$url)
{
echo __CLASS__ . '::request_url';
// echo __CLASS__ . '::request_url';
}

}
Expand Down

0 comments on commit 6aca303

Please sign in to comment.