本文整理汇总了PHP中JError::setErrorHandling方法的典型用法代码示例。如果您正苦于以下问题:PHP JError::setErrorHandling方法的具体用法?PHP JError::setErrorHandling怎么用?PHP JError::setErrorHandling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JError
的用法示例。
在下文中一共展示了JError::setErrorHandling方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_
/**
* @todo Implement test_().
*/
public function test_()
{
// first we test to ensure that if a handler is properly registered, it gets called
$registered = $this->getMock('MyHtmlClass', array('mockFunction'));
// test that we can register the method
JHtml::register('file.testfunction', array($registered, 'mockFunction'));
// test that calling _ actually calls the function
$registered->expects($this->once())->method('mockFunction')->with('Test Return Value')->will($this->returnValue('My Expected Return Value'));
$this->assertThat(JHtml::_('file.testfunction', 'Test Return Value'), $this->equalTo('My Expected Return Value'));
// we unregister the method to return to our original state
JHtml::unregister('prefix.file.testfunction');
// now we test with a class that will be found in the expected file
JHtml::addIncludePath(array(JPATH_BASE . '/tests/unit/suite/libraries/joomla/html/htmltests'));
$this->assertThat(JHtml::_('mocktest.method1', 'argument1', 'argument2'), $this->equalTo('JHtml Mock Called'));
$this->assertThat(JHtmlMockTest::$arguments[0], $this->equalTo(array('argument1', 'argument2')));
JHtmlMockTest::$arguments = array();
$this->saveErrorHandlers();
$mock1 = $this->getMock('errorCallback', array('error1', 'error2', 'error3'));
JError::setErrorHandling(E_ERROR, 'callback', array($mock1, 'error1'));
$mock1->expects($this->once())->method('error1');
// we ensure that we get an error if we can find the file but the file does not contain the class
$this->assertThat(JHtml::_('mocktest2.function1'), $this->isFalse());
JError::setErrorHandling(E_ERROR, 'callback', array($mock1, 'error2'));
$mock1->expects($this->once())->method('error2');
// we ensure that we get an error if we can't find the file
$this->assertThat(JHtml::_('mocktestnotthere.function1'), $this->isFalse());
JError::setErrorHandling(E_ERROR, 'callback', array($mock1, 'error3'));
$mock1->expects($this->once())->method('error3');
// we ensure that we get an error if we have the class but not the method
$this->assertThat(JHtml::_('mocktest.nomethod'), $this->isFalse());
// restore our error handlers
$this->setErrorHandlers($this->savedErrorState);
}
示例2: __construct
/**
* Constructor.
*
* @param object &$subject The object to observe
* @param array $config An optional associative array of configuration settings.
*
* @since 1.6
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
// Set the error handler for E_ERROR to be the class handleError method.
JError::setErrorHandling(E_ERROR, 'callback', array('PlgSystemRedirect', 'handleError'));
set_exception_handler(array('PlgSystemRedirect', 'handleError'));
}
示例3: __construct
/**
* Object Constructor.
*
* @access public
* @param object The object to observe -- event dispatcher.
* @param object The configuration object for the plugin.
* @return void
* @since 1.0
*/
function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
// Set the error handler for E_ERROR to be the class handleError method.
JError::setErrorHandling(E_ERROR, 'callback', array('plgSystemError404', 'handleError'));
//$redirect=$this->params->get('redirection');
}
示例4: test_
/**
* Test the _ method.
*
* @return void
*
* @since 11.1
*/
public function test_()
{
// Add the include path to html test files.
JHtml::addIncludePath(array(__DIR__ . '/html/testfiles'));
// Test the class method was called and the arguments passed correctly.
$this->assertThat(JHtml::_('inspector.method1', 'argument1', 'argument2'), $this->equalTo('JHtmlInspector::method1'), 'JHtmlInspector::method1 could not be called.');
$this->assertThat(JHtmlInspector::$arguments[0], $this->equalTo(array('argument1', 'argument2')), 'The arguments where not correctly passed to JHtmlInspector::method1.');
// Test error cases.
// Prepare the error handlers.
$this->saveErrorHandlers();
$errorCallback = $this->getMock('errorCallback', array('error1', 'error2', 'error3'));
$errorCallback->expects($this->once())->method('error1');
$errorCallback->expects($this->once())->method('error2');
$errorCallback->expects($this->once())->method('error3');
// Ensure that we get an error if we can find the file but the file does not contain the class.
JError::setErrorHandling(E_ERROR, 'callback', array($errorCallback, 'error1'));
$this->assertThat(JHtml::_('empty.anything'), $this->isFalse());
// Ensure that we get an error if we can't find the file.
JError::setErrorHandling(E_ERROR, 'callback', array($errorCallback, 'error2'));
$this->assertThat(JHtml::_('nofile.anything'), $this->isFalse());
// Ensure that we get an error if we have the class but not the method.
JError::setErrorHandling(E_ERROR, 'callback', array($errorCallback, 'error3'));
$this->assertThat(JHtml::_('inspector.nomethod'), $this->isFalse());
// Restore the error handlers.
$this->setErrorHandlers($this->savedErrorState);
}
示例5: startJoomlaDbErrorLogger
/**
* Set db logger. Since all JErrors E_ERROR will be added to log.
* Usefull if you render something J! native.
* Covers all E_ERROR generated by
* JError::raiseError, JError::raise, JError::throwError.
*
* All execs of JLog::add(...) with
* JLog::EMERGENCY | JLog::ALERT | JLog::CRITICAL | JLog::ERROR
* will be added to LOGS table.
*/
public static function startJoomlaDbErrorLogger()
{
// Add handler to JError for E_ERROR
JError::setErrorHandling(E_ERROR, 'callback', array('LogHelper', 'addJError'));
// Now we log all the troubles into our LOGS table.
JLog::addLogger(array('logger' => 'database', 'db_table' => '#__newsletter_logs'), JLog::EMERGENCY | JLog::ALERT | JLog::CRITICAL | JLog::ERROR);
}
示例6: onAfterInitialise
/**
* Method to register custom library.
*
* @return void
*/
public function onAfterInitialise()
{
if (defined('REDCORE_LIBRARY_LOADED')) {
$apiName = JFactory::getApplication()->input->getString('api');
if ($this->isApiEnabled($apiName)) {
$input = JFactory::getApplication()->input;
if (!empty($apiName)) {
try {
// We will disable all error messaging from PHP from the output
error_reporting(0);
ini_set('display_errors', 0);
JError::setErrorHandling(E_ERROR, 'message');
JFactory::getApplication()->clearHeaders();
$webserviceClient = $input->get->getString('webserviceClient', '');
$optionName = $input->get->getString('option', '');
$optionName = strpos($optionName, 'com_') === 0 ? substr($optionName, 4) : $optionName;
$viewName = $input->getString('view', '');
$version = $input->getString('webserviceVersion', '');
$token = $input->getString(RBootstrap::getConfig('oauth2_token_param_name', 'access_token'), '');
$apiName = ucfirst($apiName);
$method = strtoupper($input->getMethod());
$task = RApiHalHelper::getTask();
$data = RApi::getPostedData();
$dataGet = $input->get->getArray();
if (empty($webserviceClient)) {
$webserviceClient = JFactory::getApplication()->isAdmin() ? 'administrator' : 'site';
}
$options = array('api' => $apiName, 'optionName' => $optionName, 'viewName' => $viewName, 'webserviceVersion' => $version, 'webserviceClient' => $webserviceClient, 'method' => $method, 'task' => $task, 'data' => $data, 'dataGet' => $dataGet, 'accessToken' => $token, 'format' => $input->getString('format', $this->params->get('webservices_default_format', 'json')), 'id' => $input->getString('id', ''), 'absoluteHrefs' => $input->get->getBool('absoluteHrefs', true));
// Create instance of Api and fill all required options
$api = RApi::getInstance($options);
// Run the api task
$api->execute();
// Display output
$api->render();
} catch (Exception $e) {
$code = $e->getCode() > 0 ? $e->getCode() : 500;
if (strtolower($apiName) == 'soap') {
// We must have status of 200 for SOAP communication even if it is fault
$message = RApiSoapHelper::createSoapFaultResponse($e->getMessage());
header("Content-Type: soap+xml");
header("Content-length: " . strlen($message));
header("Status: 200");
echo $message;
} else {
// Set the server response code.
header('Status: ' . $code, true, $code);
// Check for defined constants
if (!defined('JSON_UNESCAPED_SLASHES')) {
define('JSON_UNESCAPED_SLASHES', 64);
}
// An exception has been caught, echo the message and exit.
echo json_encode(array('message' => $e->getMessage(), 'code' => $e->getCode(), 'type' => get_class($e)), JSON_UNESCAPED_SLASHES);
}
}
JFactory::getApplication()->close();
}
}
}
}
示例7: __construct
/**
* Constructor.
*
* @param object &$subject The object to observe
* @param array $config An optional associative array of configuration settings.
*
* @since 1.6
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
// Set the JError handler for E_ERROR to be the class' handleError method.
JError::setErrorHandling(E_ERROR, 'callback', array('PlgSystemRedirect', 'handleError'));
// Register the previously defined exception handler so we can forward errors to it
self::$previousExceptionHandler = set_exception_handler(array('PlgSystemRedirect', 'handleException'));
}
示例8: __construct
/**
* Class constructor
*
* @access protected
* @param array An optional associative array of configuration settings.
* Recognized key values include 'clientId' (this list is not meant to be comprehensive).
*/
public function __construct(array $config = array())
{
$config['clientId'] = 2;
parent::__construct($config);
JError::setErrorHandling(E_ALL, 'Ignore');
$this->_createConfiguration();
// Set the root in the URI based on the application name.
JURI::root(null, str_replace('/' . $this->getName(), '', JURI::base(true)));
}
示例9: __construct
function __construct()
{
// Set timelimit to 0
set_time_limit(0);
// Base includes
require_once JPATH_LIBRARIES . '/joomla/import.php';
require_once JPATH_LIBRARIES . '/joomla/methods.php';
require_once JPATH_LIBRARIES . '/joomla/factory.php';
require_once JPATH_LIBRARIES . '/joomla/import.php';
require_once JPATH_LIBRARIES . '/joomla/config.php';
require_once JPATH_SITE . '/configuration.php';
// Base includes
jimport('joomla.base.object');
jimport('joomla.base.adapter');
// Application includes
jimport('joomla.application.helper');
jimport('joomla.application.application');
jimport('joomla.application.component.modellist');
// Error includes
jimport('joomla.error.error');
jimport('joomla.error.exception');
// Database includes
jimport('joomla.database.database');
jimport('joomla.database.table');
jimport('joomla.database.tablenested');
jimport('joomla.database.table.asset');
jimport('joomla.database.table.category');
// Update and installer includes for 3rd party extensions
jimport('joomla.installer.installer');
jimport('joomla.updater.updater');
jimport('joomla.updater.update');
// Other stuff
jimport('joomla.filesystem.folder');
jimport('joomla.utilities.string');
jimport('joomla.filter.filteroutput');
jimport('joomla.html.parameter');
// Echo all errors, otherwise things go really bad.
JError::setErrorHandling(E_ALL, 'echo');
// Manually
//JTable::addIncludePath(JPATH_LIBRARIES.'/joomla/database/table');
$jconfig = new JConfig();
$this->config['driver'] = 'mysql';
$this->config['host'] = $jconfig->host;
$this->config['user'] = $jconfig->user;
$this->config['password'] = $jconfig->password;
$this->config['database'] = $jconfig->db;
$this->config['prefix'] = $jconfig->dbprefix;
//print_r($config);
$this->config_old = $this->config;
$this->config_old['prefix'] = $this->getPrefix();
$this->db_new = JDatabase::getInstance($this->config);
$this->db_old = JDatabase::getInstance($this->config_old);
}
示例10: testSetErrorHandling
/**
* Test JError::setErrorHandling
*
* @return void
*/
public function testSetErrorHandling()
{
JErrorInspector::manipulateLevels(array(E_NOTICE => 'Notice', E_WARNING => 'Warning', E_ERROR => 'Error'));
$errorHandling = JErrorInspector::inspectHandlers();
$this->assertThat(JError::setErrorHandling(E_NOTICE, 'message'), $this->isTrue(), 'Setting a message error handler failed');
$handlers = JErrorInspector::inspectHandlers();
$this->assertThat($handlers[E_NOTICE], $this->equalTo(array('mode' => 'message')), 'The error handler did not get set to message');
$this->assertThat(JError::setErrorHandling(E_NOTICE, 'callback', array($this, 'callbackHandler')), $this->isTrue(), 'Setting a message error handler failed');
$handlers = JErrorInspector::inspectHandlers();
$this->assertThat($handlers[E_NOTICE], $this->equalTo(array('mode' => 'callback', 'options' => array($this, 'callbackHandler'))), 'The error handler did not get set to callback');
JErrorInspector::manipulateHandlers($errorHandling);
}
示例11: setlanguage
/**
* Method to set the setup language for the application.
*
* @return void
* @since 1.6
*/
public function setlanguage()
{
// Get the application object.
$app = JFactory::getApplication();
// Check for potentially unwritable session
$session = JFactory::getSession();
if ($session->isNew()) {
JError::setErrorHandling(E_ERROR, 'message');
JError::raise(E_ERROR, 500, JText::_('INSTL_COOKIES_NOT_ENABLED'));
return false;
}
// Check for request forgeries.
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Get the setup model.
$model = $this->getModel('Setup', 'JInstallationModel', array('dbo' => null));
// Get the posted values from the request and validate them.
$data = JRequest::getVar('jform', array(), 'post', 'array');
$return = $model->validate($data, 'language');
// Check for validation errors.
if ($return === false) {
// Get the validation messages.
$errors = $model->getErrors();
// Push up to three validation messages out to the user.
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
{
if (JError::isError($errors[$i])) {
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
} else {
$app->enqueueMessage($errors[$i], 'warning');
}
}
// Redirect back to the language selection screen.
$this->setRedirect('index.php?view=language');
return false;
}
// Store the options in the session.
$vars = $model->storeOptions($return);
// Redirect to the next page.
$this->setRedirect('index.php?view=preinstall');
}
示例12: setErrorHandlers
/**
* Sets the JError error handlers.
*
* @param array araay of values and options to set the handlers
*
* @return void
*/
protected function setErrorHandlers($errorHandlers)
{
$mode = null;
$options = null;
foreach ($errorHandlers as $type => $params) {
$mode = $params['mode'];
if (isset($params['options'])) {
JError::setErrorHandling($type, $mode, $params['options']);
} else {
JError::setErrorHandling($type, $mode);
}
}
}
示例13: __construct
/**
* Object Constructor.
*
* @access public
* @param object The object to observe -- event dispatcher.
* @param object The configuration object for the plugin.
* @return void
* @since 1.5
*/
function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
$hash = JUtility::getHash('plgSystemLogout');
if (JFactory::getApplication()->isSite() and JRequest::getString($hash, null, 'cookie')) {
// Destroy the cookie
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('config.cookie_domain', '');
$cookie_path = $conf->get('config.cookie_path', '/');
setcookie($hash, false, time() - 86400, $cookie_path, $cookie_domain);
// Set the error handler for E_ALL to be the class handleError method.
JError::setErrorHandling(E_ALL, 'callback', array('plgSystemLogout', 'handleError'));
}
}
示例14: __construct
/**
* Constructor.
*
* @param object &$subject The object to observe -- event dispatcher.
* @param object $config An optional associative array of configuration settings.
*
* @since 1.6
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
$app = JFactory::getApplication();
$input = $app->input;
$hash = JApplicationHelper::getHash('PlgSystemLogout');
if ($app->isSite() && $input->cookie->getString($hash)) {
// Destroy the cookie.
$cookie_domain = $app->get('cookie_domain', '');
$cookie_path = $app->get('cookie_path', '/');
setcookie($hash, false, time() - 86400, $cookie_path, $cookie_domain);
// Set the error handler for E_ALL to be the class handleError method.
JError::setErrorHandling(E_ALL, 'callback', array('PlgSystemLogout', 'handleError'));
}
}
示例15: display
/**
* Displays a layout file
*
* @param unknown_type $tpl
* @return unknown_type
*/
public function display($tpl = null)
{
// Load the model
$model = $this->getModel();
$items = $model->getList();
$this->assignRef('items', $items);
$document = JFactory::getDocument();
$document->setMimeEncoding('text/csv');
JResponse::setHeader('Pragma', 'public');
JResponse::setHeader('Expires', '0');
JResponse::setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
JResponse::setHeader('Cache-Control', 'public', false);
JResponse::setHeader('Content-Description', 'File Transfer');
JResponse::setHeader('Content-Disposition', 'attachment; filename=' . $this->csvFilename);
JError::setErrorHandling(E_ALL, 'ignore');
if (is_null($tpl)) {
$tpl = 'csv';
}
$result = $this->loadTemplate($tpl);
JError::setErrorHandling(E_WARNING, 'callback');
if ($result instanceof JException) {
// Default CSV behaviour in case the template isn't there!
if (empty($items)) {
return;
}
if ($this->csvHeader) {
$item = array_pop($items);
$keys = get_object_vars($item);
$items[] = $item;
reset($items);
$csv = array();
foreach ($keys as $k => $v) {
$csv[] = '"' . str_replace('"', '""', $k) . '"';
}
echo implode(",", $csv) . "\r\n";
}
foreach ($items as $item) {
$csv = array();
$keys = get_object_vars($item);
foreach ($item as $k => $v) {
$csv[] = '"' . str_replace('"', '""', $v) . '"';
}
echo implode(",", $csv) . "\r\n";
}
return;
}
}