Skip to content

Commit

Permalink
o Updated how 500 errors are generated. Updated URI Helper, added so…
Browse files Browse the repository at this point in the history
…me view-specific stuff to make it more useful.
  • Loading branch information
simensen committed Oct 19, 2010
1 parent 5c153a0 commit 9d3d5d5
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 15 deletions.
15 changes: 11 additions & 4 deletions lib/halo_Dispatcher.php
Expand Up @@ -69,18 +69,25 @@ public function doServiceErrorHandler($buffer) {
self::$LOGGER->fatal('SOMETHING MAJOR HAPPENED');
self::$LOGGER->fatal($error['message'] . ' in ' . $error['file'] . ' on line ' . $error['line']);
}
$buffer = $this->triggerInternalServerError();
}
return $buffer;
}

protected function triggerInternalServerError() {
header('HTTP/1.1 500 Internal Server Error');
$content = '';
$content .= '<strong>500 Internal Server Error</strong><br />';
$content .= 'An internal error has occurred.';
return $content;
}

/**
* Handle internal server error
*/
protected function handleInternalServerError() {
// TODO: Can we find a way to customize 500 error?
header('HTTP/1.1 500 Internal Server Error');
echo '<strong>500 Internal Server Error</strong><br />';
echo 'An internal error has occurred.';
echo $this->triggerInternalServerError();
}

/**
Expand All @@ -93,7 +100,7 @@ public function doService(halo_HttpRequest $httpRequest, halo_HttpResponse $http
$didCatchException = false;
$exception = null;

ob_start(array($this, 'doServiceErrorHandler'));;
ob_start(array($this, 'doServiceErrorHandler'));

try {
$this->doServiceInternal($httpRequest, $httpResponse);
Expand Down
78 changes: 77 additions & 1 deletion lib/halo_helper_UriHelper.php
@@ -1,3 +1,79 @@
<?php
class halo_helper_UriHelper {

require_once('dd_uri_Uri.php');

class halo_helper_UriHelper extends dd_uri_Uri {

/**
* Print an HTML escaped URI
* @see dd_uri_Uri::get()
*/
public function p() {
$args = func_get_args();
print htmlspecialchars(call_user_func_array(array($this, 'get'), $args));
}

/**
* Print a URI
* @see dd_uri_Uri::get()
*/
public function pRaw() {
$args = func_get_args();
print call_user_func_array(array($this, 'get'), $args);
}

/**
* Print an HTML escaped site URI
* @see dd_uri_Uri::getSite()
*/
public function pSite() {
$args = func_get_args();
print htmlspecialchars(call_user_func_array(array($this, 'getSite'), $args));
}

/**
* Print a site URI
* @see dd_uri_Uri::getSite()
*/
public function pSiteRaw() {
$args = func_get_args();
print call_user_func_array(array($this, 'getSite'), $args);
}

/**
* Get an HTML escaped URI
* @see dd_uri_Uri::get()
*/
public function g() {
$args = func_get_args();
return htmlspecialchars(call_user_func_array(array($this, 'get'), $args));
}

/**
* Get a URI
* @see dd_uri_Uri::get()
*/
public function gRaw() {
$args = func_get_args();
return call_user_func_array(array($this, 'get'), $args);
}

/**
* Get an HTML escaped site URI
* @see dd_uri_Uri::getSite()
*/
public function gSite() {
$args = func_get_args();
return htmlspecialchars(call_user_func_array(array($this, 'getSite'), $args));
}

/**
* Get a site URI
* @see dd_uri_Uri::getSite()
*/
public function gSiteRaw() {
$args = func_get_args();
return call_user_func_array(array($this, 'getSite'), $args);
}

}
20 changes: 10 additions & 10 deletions lib/halo_helper_UriHelperFactory.php
@@ -1,18 +1,18 @@
<?php

require_once('halo_IRequestHelperFactory.php');
require_once('dd_configuration_IConfiguration.php');
require_once('dd_uri_Uri.php');
require_once('dd_uri_UriConfiguration.php');
require_once('halo_helper_UriHelper.php');
require_once('halo_HttpRequest.php');
require_once('halo_HttpResponse.php');

class halo_helper_UriHelperFactory implements halo_IRequestHelperFactory {

/**
* Configuration
* @var dd_configuration_IConfiguration
* @var dd_uri_UriConfiguration
*/
protected $configuration;
protected $uriConfiguration;

/**
* Prefix
Expand All @@ -34,10 +34,10 @@ class halo_helper_UriHelperFactory implements halo_IRequestHelperFactory {

/**
* Constructor
* @param $configuration
* @param $uriConfiguration
*/
public function __construct(dd_configuration_IConfiguration $configuration = null) {
$this->configuration = $configuration;
public function __construct(dd_uri_UriConfiguration $uriConfiguration = null) {
$this->uriConfiguration = $uriConfiguration;
}

public function setPrefix($prefix) {
Expand All @@ -57,10 +57,10 @@ public function supports($name) {
}

public function helper($name, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {
$uri = new dd_uri_Uri(
$this->configuration,
$uri = new halo_helper_UriHelper(
$this->uriConfiguration,
$httpRequest->scriptPathRoot(),
false,
( $httpRequest->scriptPathRoot() and $httpRequest->scriptPathRoot() != '/' ) ? true : false,
$httpRequest->envExport()
);
if ( $this->prefix ) $uri->setPrefix($this->prefix);
Expand Down

0 comments on commit 9d3d5d5

Please sign in to comment.