<commit_before><?php
/**
 * ErrorPage holds the content for the page of an error response.
 * Renders the page on each publish action into a static HTML file
 * within the assets directory, after the naming convention
 * /assets/error-<statuscode>.html.
 * This enables us to show errors even if PHP experiences a recoverable error.
 * ErrorPages
 * 
 * @see Debug::friendlyError()
 * 
 * @package cms
 */
class ErrorPage extends Page {

	static $db = array(
		"ErrorCode" => "Int",
	);

	static $defaults = array(
		"ShowInMenus" => 0,
		"ShowInSearch" => 0
	);
	
	static $icon = array("sapphire/javascript/tree/images/page", "file");
	
	protected static $static_filepath = ASSETS_PATH;
	
	/**
	 * Get a {@link SS_HTTPResponse} to response to a HTTP error code if an {@link ErrorPage} for that code is present.
	 *
	 * @param int $statusCode
	 * @return SS_HTTPResponse
	 */
	public static function response_for($statusCode) {
		// first attempt to dynamically generate the error page
		if($errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = $statusCode")) {
			return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''));
		}
		
		// then fall back on a cached version
		$cachedPath = self::get_filepath_for_errorcode(
			$statusCode, 
			class_exists('Translatable') ? Translatable::get_current_locale() : null
		);
		
		if(file_exists($cachedPath)) {
			$response = new SS_HTTPResponse();	
			
			$response->setStatusCode($statusCode);
			$response->setBody(file_get_contents($cachedPath));<commit_msg>MINOR Disallow nested ErrorPage instances via canAddChildren()<commit_after><?php
/**
 * ErrorPage holds the content for the page of an error response.
 * Renders the page on each publish action into a static HTML file
 * within the assets directory, after the naming convention
 * /assets/error-<statuscode>.html.
 * This enables us to show errors even if PHP experiences a recoverable error.
 * ErrorPages
 * 
 * @see Debug::friendlyError()
 * 
 * @package cms
 */
class ErrorPage extends Page {

	static $db = array(
		"ErrorCode" => "Int",
	);

	static $defaults = array(
		"ShowInMenus" => 0,
		"ShowInSearch" => 0
	);
	
	static $icon = array("sapphire/javascript/tree/images/page", "file");
	
	protected static $static_filepath = ASSETS_PATH;
	
	public function canAddChildren($member = null) { return false; }
	
	/**
	 * Get a {@link SS_HTTPResponse} to response to a HTTP error code if an {@link ErrorPage} for that code is present.
	 *
	 * @param int $statusCode
	 * @return SS_HTTPResponse
	 */
	public static function response_for($statusCode) {
		// first attempt to dynamically generate the error page
		if($errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = $statusCode")) {
			return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''));
		}
		
		// then fall back on a cached version
		$cachedPath = self::get_filepath_for_errorcode(
			$statusCode, 
			class_exists('Translatable') ? Translatable::get_current_locale() : null
		);
		
		if(file_exists($cachedPath)) {
			$response = new SS_HTTPResponse();	
			
			$response->setStatusCode($statusCode);
			$response->setBody(file_get_contents($cachedPath));
{'fraction_non_alphanumeric': 0.12109012078042737, 'fraction_numerical': 0.0012387736141220192, 'mean_word_length': 4.338842975206612, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5596049', 'n_tokens_mistral': 1036, 'n_tokens_neox': 941, 'n_words': 287}