[+] Classes: Add PHP exceptions support + handler

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8797 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-09-27 12:10:47 +00:00
parent 7c32b171cd
commit 80e750c4c9
21 changed files with 410 additions and 50 deletions
+25 -16
View File
@@ -192,6 +192,7 @@
'RangeWeight' => 'override/classes/RangeWeight.php',
'ReferrerCore' => 'classes/Referrer.php',
'Referrer' => 'override/classes/Referrer.php',
'RequestSql' => 'classes/RequestSql.php',
'RijndaelCore' => 'classes/Rijndael.php',
'Rijndael' => 'override/classes/Rijndael.php',
'SceneCore' => 'classes/Scene.php',
@@ -230,22 +231,6 @@
'Upgrader' => 'override/classes/Upgrader.php',
'ValidateCore' => 'classes/Validate.php',
'Validate' => 'override/classes/Validate.php',
'WebserviceExceptionCore' => 'classes/WebserviceException.php',
'WebserviceException' => 'override/classes/WebserviceException.php',
'WebserviceKeyCore' => 'classes/WebserviceKey.php',
'WebserviceKey' => 'override/classes/WebserviceKey.php',
'WebserviceOutputBuilderCore' => 'classes/WebserviceOutputBuilder.php',
'WebserviceOutputBuilder' => 'override/classes/WebserviceOutputBuilder.php',
'WebserviceOutputInterface' => 'classes/WebserviceOutputInterface.php',
'WebserviceOutputXMLCore' => 'classes/WebserviceOutputXML.php',
'WebserviceOutputXML' => 'override/classes/WebserviceOutputXML.php',
'WebserviceRequestCore' => 'classes/WebserviceRequest.php',
'WebserviceRequest' => 'override/classes/WebserviceRequest.php',
'WebserviceSpecificManagementImagesCore' => 'classes/WebserviceSpecificManagementImages.php',
'WebserviceSpecificManagementImages' => 'override/classes/WebserviceSpecificManagementImages.php',
'WebserviceSpecificManagementInterface' => 'classes/WebserviceSpecificManagementInterface.php',
'WebserviceSpecificManagementSearchCore' => 'classes/WebserviceSpecificManagementSearch.php',
'WebserviceSpecificManagementSearch' => 'override/classes/WebserviceSpecificManagementSearch.php',
'ZoneCore' => 'classes/Zone.php',
'Zone' => 'override/classes/Zone.php',
'DbCore' => 'classes/db/Db.php',
@@ -258,6 +243,14 @@
'DbQuery' => 'override/classes/db/DbQuery.php',
'MySQLCore' => 'classes/db/MySQL.php',
'MySQL' => 'override/classes/db/MySQL.php',
'PrestashopDatabaseExceptionCore' => 'classes/exception/PrestashopDatabaseException.php',
'PrestashopDatabaseException' => 'override/classes/exception/PrestashopDatabaseException.php',
'PrestashopExceptionCore' => 'classes/exception/PrestashopException.php',
'PrestashopException' => 'override/classes/exception/PrestashopException.php',
'PrestashopModuleExceptionCore' => 'classes/exception/PrestashopModuleException.php',
'PrestashopModuleException' => 'override/classes/exception/PrestashopModuleException.php',
'PrestashopPaymentExceptionCore' => 'classes/exception/PrestashopPaymentException.php',
'PrestashopPaymentException' => 'override/classes/exception/PrestashopPaymentException.php',
'GroupShopCore' => 'classes/shop/GroupShop.php',
'GroupShop' => 'override/classes/shop/GroupShop.php',
'ShopCore' => 'classes/shop/Shop.php',
@@ -279,6 +272,22 @@
'TaxRulesGroup' => 'override/classes/tax/TaxRulesGroup.php',
'TaxRulesTaxManagerCore' => 'classes/tax/TaxRulesTaxManager.php',
'TaxRulesTaxManager' => 'override/classes/tax/TaxRulesTaxManager.php',
'WebserviceExceptionCore' => 'classes/webservice/WebserviceException.php',
'WebserviceException' => 'override/classes/webservice/WebserviceException.php',
'WebserviceKeyCore' => 'classes/webservice/WebserviceKey.php',
'WebserviceKey' => 'override/classes/webservice/WebserviceKey.php',
'WebserviceOutputBuilderCore' => 'classes/webservice/WebserviceOutputBuilder.php',
'WebserviceOutputBuilder' => 'override/classes/webservice/WebserviceOutputBuilder.php',
'WebserviceOutputInterface' => 'classes/webservice/WebserviceOutputInterface.php',
'WebserviceOutputXMLCore' => 'classes/webservice/WebserviceOutputXML.php',
'WebserviceOutputXML' => 'override/classes/webservice/WebserviceOutputXML.php',
'WebserviceRequestCore' => 'classes/webservice/WebserviceRequest.php',
'WebserviceRequest' => 'override/classes/webservice/WebserviceRequest.php',
'WebserviceSpecificManagementImagesCore' => 'classes/webservice/WebserviceSpecificManagementImages.php',
'WebserviceSpecificManagementImages' => 'override/classes/webservice/WebserviceSpecificManagementImages.php',
'WebserviceSpecificManagementInterface' => 'classes/webservice/WebserviceSpecificManagementInterface.php',
'WebserviceSpecificManagementSearchCore' => 'classes/webservice/WebserviceSpecificManagementSearch.php',
'WebserviceSpecificManagementSearch' => 'override/classes/webservice/WebserviceSpecificManagementSearch.php',
'FB' => 'override/classes/fb.php',
'AdminHomeControllerCore' => 'controllers/admin/AdminHomeController.php',
'AdminHomeController' => '',
+4 -2
View File
@@ -78,7 +78,10 @@ class Autoload
public function load($classname)
{
// regenerate the class index if the requested class is not found in the index or if the requested file doesn't exists
if (!isset($this->index[$classname]) || ($this->index[$classname] && !file_exists($this->root_dir.$this->index[$classname])))
if (!isset($this->index[$classname])
|| ($this->index[$classname] && !is_file($this->root_dir.$this->index[$classname]))
|| (isset($this->index[$classname.'Core']) && $this->index[$classname.'Core'] && !is_file($this->root_dir.$this->index[$classname]))
)
$this->generateIndex();
// If $classname has not core suffix (E.g. Shop, Product)
@@ -87,7 +90,6 @@ class Autoload
// If requested class does not exist, load associated core class
if (isset($this->index[$classname]) && !$this->index[$classname])
{
require_once($this->root_dir.$this->index[$classname.'Core']);
if (file_exists($this->root_dir.'override/'.$this->index[$classname.'Core']))
{
+1 -1
View File
@@ -598,7 +598,7 @@ class ToolsCore
*/
public static function d($object, $kill = true)
{
return (self::dieObject($object, $kill = true));
return (self::dieObject($object, $kill));
}
/**
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5.0
*/
class PrestashopDatabaseExceptionCore extends PrestashopException
{
}
+139
View File
@@ -0,0 +1,139 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5.0
*/
class PrestashopExceptionCore extends Exception
{
/**
* This method acts like an error handler, if dev mode is on, display the error else use a better silent way
*/
public function displayMessage()
{
if (_PS_MODE_DEV_)
{
// Display error message
echo '<style>
#psException{font-family: Verdana; font-size: 14px}
#psException h2{color: #F20000}
#psException p{padding-left: 20px}
#psException ul li{margin-bottom: 10px}
#psException a{font-size: 12px; color: #000000}
#psException .psTrace, #psException .psArgs{display: none}
#psException pre{border: 1px solid #236B04; background-color: #EAFEE1; padding: 5px; font-family: Courier; width: 99%; overflow-x: auto; margin-bottom: 30px;}
#psException .psArgs pre{background-color: #F1FDFE;}
#psException pre .selected{color: #F20000; font-weight: bold;}
</style>';
echo '<div id="psException">';
echo '<h2>['.get_class($this).']</h2>';
printf(
'<p><b>%s</b><br /><i>at line </i><b>%d</b><i> in file </i><b>%s</b></p>',
$this->getMessage(),
$this->getLine(),
ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $this->getFile()), '/')
);
// Display debug backtrace
echo '<ul>';
foreach ($this->getTrace() as $id => $trace)
{
$relative_file = ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $trace['file']), '/');
echo '<li>';
echo '<b>'.$trace['class'].$trace['type'].$trace['function'].'</b>';
echo ' - <a href="#" style="font-size: 12px; color: #000000" onclick="document.getElementById(\'psTrace_'.$id.'\').style.display = (document.getElementById(\'psTrace_'.$id.'\').style.display != \'block\') ? \'block\' : \'none\'; return false">[line '.$trace['line'].' - '.$relative_file.']</a>';
if (count($trace['args']))
echo ' - <a href="#" onclick="document.getElementById(\'psArgs_'.$id.'\').style.display = (document.getElementById(\'psArgs_'.$id.'\').style.display != \'block\') ? \'block\' : \'none\'; return false">['.count($trace['args']).' Arguments]</a>';
else
echo ' - <span style="font-size: 12px;">[0 Argument]</a>';
$this->displayFileDebug($trace['file'], $trace['line'], $id);
$this->displayArgsDebug($trace['args'], $id);
echo '</li>';
}
echo '</ul>';
echo '</div>';
}
else
{
// If not in mode dev, launch a http 500 error
header('HTTP/1.1 500 Internal Server Error');
if (file_exists(_PS_ROOT_DIR_.'/error500.html'))
echo file_get_contents(_PS_ROOT_DIR_.'/error500.html');
}
exit;
}
/**
* Display lines around current line
*
* @param string $file
* @param int $line
* @param string $id
*/
protected function displayFileDebug($file, $line, $id)
{
$lines = file($file);
$offset = $line - 6;
$total = 11;
if ($offset < 0)
{
$total += $offset;
$offset = 0;
}
$lines = array_slice($lines, $offset, $total);
echo '<div class="psTrace" id="psTrace_'.$id.'"><pre>';
foreach ($lines as $k => $l)
{
if ($offset + $k == $line - 1)
echo '<span class="selected">'.($offset + $k).'. '.htmlspecialchars($l).'</span>';
else
echo ($offset + $k).'. '.htmlspecialchars($l);
}
echo '</pre></div>';
}
/**
* Display arguments list of traced function
*
* @param array $args List of arguments
* @param string $id ID of argument
*/
protected function displayArgsDebug($args, $id)
{
echo '<div class="psArgs" id="psArgs_'.$id.'"><pre>';
foreach ($args as $arg => $value)
{
echo '<b>Argument ['.$arg."]</b>\n";
print_r($value);
echo "\n";
}
echo '</pre>';
}
}
@@ -1,31 +1,35 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class PrestashopExceptionCore Extends Exception
{
}
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5.0
*/
class PrestashopModuleExceptionCore extends PrestashopException
{
}
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5.0
*/
class PrestashopPaymentExceptionCore extends PrestashopException
{
}
+36
View File
@@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;
@@ -0,0 +1,7 @@
<?php
class PrestashopDatabaseException extends PrestashopDatabaseExceptionCore
{
}
@@ -0,0 +1,7 @@
<?php
class PrestashopException extends PrestashopExceptionCore
{
}
@@ -0,0 +1,7 @@
<?php
class PrestashopModuleException extends PrestashopModuleExceptionCore
{
}
@@ -0,0 +1,7 @@
<?php
class PrestashopPaymentException extends PrestashopPaymentExceptionCore
{
}
+36
View File
@@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;
+36
View File
@@ -0,0 +1,36 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;