Replace PEAR::raiseError with new Exception

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent d4072515c9
commit f3093f40eb
  1. 112
      main/inc/lib/pear/HTML/QuickForm.php
  2. 10
      main/inc/lib/pear/HTML/QuickForm/Controller.php
  3. 4
      main/inc/lib/pear/HTML/QuickForm/Renderer/QuickHtml.php
  4. 2
      main/inc/lib/pear/HTML/QuickForm/file.php
  5. 3
      main/inc/lib/pear/HTML/Table.php
  6. 13
      main/inc/lib/pear/HTML/Table/Storage.php
  7. 4
      main/inc/lib/pear/Pager/Common.php

@ -365,35 +365,6 @@ class HTML_QuickForm extends HTML_Common
return isset($this->_elementIndex[$element]);
}
/**
* Sets a datasource object for this form object
*
* Datasource default and constant values will feed the QuickForm object if
* the datasource implements defaultValues() and constantValues() methods.
*
* @param object $datasource datasource object implementing the informal datasource protocol
* @param mixed $defaultsFilter string or array of filter(s) to apply to default values
* @param mixed $constantsFilter string or array of filter(s) to apply to constants values
* @since 3.3
* @access public
* @return void
* @throws HTML_QuickForm_Error
* @deprecated
*/
function setDatasource(&$datasource, $defaultsFilter = null, $constantsFilter = null)
{
if (is_object($datasource)) {
$this->_datasource =& $datasource;
if (is_callable(array($datasource, 'defaultValues'))) {
$this->setDefaults($datasource->defaultValues($this), $defaultsFilter);
}
if (is_callable(array($datasource, 'constantValues'))) {
$this->setConstants($datasource->constantValues($this), $constantsFilter);
}
} else {
return PEAR::raiseError(null, QUICKFORM_INVALID_DATASOURCE, null, E_USER_WARNING, "Datasource is not an object in QuickForm::setDatasource()", 'HTML_QuickForm_Error', true);
}
}
// }}}
// {{{ setDefaults()
@ -415,13 +386,13 @@ class HTML_QuickForm extends HTML_Common
if (is_array($filter) && (2 != count($filter) || !is_callable($filter))) {
foreach ($filter as $val) {
if (!is_callable($val)) {
return PEAR::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setDefaults()", 'HTML_QuickForm_Error', true);
throw new \Exception("Callback function does not exist in QuickForm::setDefaults()");
} else {
$defaultValues = $this->_recursiveFilter($val, $defaultValues);
}
}
} elseif (!is_callable($filter)) {
return PEAR::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setDefaults()", 'HTML_QuickForm_Error', true);
throw new \Exception("Callback function does not exist in QuickForm::setDefaults()");
} else {
$defaultValues = $this->_recursiveFilter($filter, $defaultValues);
}
@ -450,20 +421,20 @@ class HTML_QuickForm extends HTML_Common
* @return void
* @throws HTML_QuickForm_Error
*/
function setConstants($constantValues = null, $filter = null)
public function setConstants($constantValues = null, $filter = null)
{
if (is_array($constantValues)) {
if (isset($filter)) {
if (is_array($filter) && (2 != count($filter) || !is_callable($filter))) {
foreach ($filter as $val) {
if (!is_callable($val)) {
return PEAR::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setConstants()", 'HTML_QuickForm_Error', true);
throw new \Exception("Callback function does not exist in QuickForm::setConstants()");
} else {
$constantValues = $this->_recursiveFilter($val, $constantValues);
}
}
} elseif (!is_callable($filter)) {
return PEAR::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setConstants()", 'HTML_QuickForm_Error', true);
throw new \Exception("Callback function does not exist in QuickForm::setConstants()");
} else {
$constantValues = $this->_recursiveFilter($filter, $constantValues);
}
@ -648,15 +619,7 @@ class HTML_QuickForm extends HTML_Common
$elKeys = array_keys($this->_elements);
$this->_duplicateIndex[$elementName][] = end($elKeys);
} else {
$error = PEAR::raiseError(
null,
QUICKFORM_INVALID_ELEMENT_NAME,
null,
E_USER_WARNING,
"Element '$elementName' already exists in HTML_QuickForm::addElement()", 'HTML_QuickForm_Error',
true
);
return $error;
throw new \Exception("Element '$elementName' already exists in HTML_QuickForm::addElement()");
}
} else {
$this->_elements[] =& $elementObject;
@ -697,14 +660,13 @@ class HTML_QuickForm extends HTML_Common
* @return HTML_QuickForm_element reference to inserted element
* @throws HTML_QuickForm_Error
*/
function &insertElementBefore(&$element, $nameAfter)
public function &insertElementBefore(&$element, $nameAfter)
{
if (!empty($this->_duplicateIndex[$nameAfter])) {
$error = PEAR::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, 'Several elements named "' . $nameAfter . '" exist in HTML_QuickForm::insertElementBefore().', 'HTML_QuickForm_Error', true);
return $error;
throw new \Exception('Several elements named "' . $nameAfter . '" exist in HTML_QuickForm::insertElementBefore().');
} elseif (!$this->elementExists($nameAfter)) {
$error = PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$nameAfter' does not exist in HTML_QuickForm::insertElementBefore()", 'HTML_QuickForm_Error', true);
return $error;
throw new \Exception("Element '$nameAfter' does not exist in HTML_QuickForm::insertElementBefore()");
}
$elementName = $element->getName();
$targetIdx = $this->_elementIndex[$nameAfter];
@ -712,8 +674,7 @@ class HTML_QuickForm extends HTML_Common
// Like in addElement(), check that it's not an incompatible duplicate
if (!empty($elementName) && isset($this->_elementIndex[$elementName])) {
if ($this->_elements[$this->_elementIndex[$elementName]]->getType() != $element->getType()) {
$error = PEAR::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, "Element '$elementName' already exists in HTML_QuickForm::insertElementBefore()", 'HTML_QuickForm_Error', true);
return $error;
throw new \Exception("Element '$elementName' already exists in HTML_QuickForm::insertElementBefore()");
}
$duplicate = true;
}
@ -791,15 +752,12 @@ class HTML_QuickForm extends HTML_Common
public function &getElement($element)
{
if (isset($this->_elementIndex[$element])) {
return $this->_elements[$this->_elementIndex[$element]];
} else {
$error = PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$element' does not exist in HTML_QuickForm::getElement()", 'HTML_QuickForm_Error', true);
return $error;
throw new \Exception("Element '$element' does not exist in HTML_QuickForm::getElement()");
}
} // end func getElement
// }}}
// {{{ &getElementValue()
}
/**
* Returns the element's raw value
@ -816,16 +774,7 @@ class HTML_QuickForm extends HTML_Common
function &getElementValue($element)
{
if (!isset($this->_elementIndex[$element])) {
$error = PEAR::raiseError(
null,
QUICKFORM_NONEXIST_ELEMENT,
null,
E_USER_WARNING,
"Element '$element' does not exist in HTML_QuickForm::getElementValue()",
'HTML_QuickForm_Error',
true
);
return $error;
throw new \Exception("Element '$element' does not exist in HTML_QuickForm::getElementValue()");
}
$value = $this->_elements[$this->_elementIndex[$element]]->getValue();
if (isset($this->_duplicateIndex[$element])) {
@ -840,10 +789,7 @@ class HTML_QuickForm extends HTML_Common
}
}
return $value;
} // end func getElementValue
// }}}
// {{{ getSubmitValue()
}
/**
* Returns the elements value after submit and filter
@ -860,7 +806,10 @@ class HTML_QuickForm extends HTML_Common
$value = isset($this->_submitValues[$elementName])? $this->_submitValues[$elementName]: array();
if (is_array($value) && isset($this->_submitFiles[$elementName])) {
foreach ($this->_submitFiles[$elementName] as $k => $v) {
$value = HTML_QuickForm::arrayMerge($value, $this->_reindexFiles($this->_submitFiles[$elementName][$k], $k));
$value = HTML_QuickForm::arrayMerge(
$value,
$this->_reindexFiles($this->_submitFiles[$elementName][$k], $k)
);
}
}
@ -1059,8 +1008,7 @@ class HTML_QuickForm extends HTML_Common
function &removeElement($elementName, $removeRules = true)
{
if (!isset($this->_elementIndex[$elementName])) {
$error = PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$elementName' does not exist in HTML_QuickForm::removeElement()", 'HTML_QuickForm_Error', true);
return $error;
throw new \Exception("Element '$elementName' does not exist in HTML_QuickForm::removeElement()");
}
$el =& $this->_elements[$this->_elementIndex[$elementName]];
unset($this->_elements[$this->_elementIndex[$elementName]]);
@ -1190,7 +1138,7 @@ class HTML_QuickForm extends HTML_Common
$reset = isset($rule[4]) && $rule[4];
$type = $rule[1];
if (false === ($newName = $this->isRuleRegistered($type, true))) {
return PEAR::raiseError(null, QUICKFORM_INVALID_RULE, null, E_USER_WARNING, "Rule '$type' is not registered in HTML_QuickForm::addGroupRule()", 'HTML_QuickForm_Error', true);
throw new \Exception("Rule '$type' is not registered in HTML_QuickForm::addGroupRule()");
} elseif (is_string($newName)) {
$type = $newName;
}
@ -1220,7 +1168,7 @@ class HTML_QuickForm extends HTML_Common
}
} elseif (is_string($arg1)) {
if (false === ($newName = $this->isRuleRegistered($type, true))) {
return PEAR::raiseError(null, QUICKFORM_INVALID_RULE, null, E_USER_WARNING, "Rule '$type' is not registered in HTML_QuickForm::addGroupRule()", 'HTML_QuickForm_Error', true);
throw new \Exception("Rule '$type' is not registered in HTML_QuickForm::addGroupRule()");
} elseif (is_string($newName)) {
$type = $newName;
}
@ -1270,7 +1218,7 @@ class HTML_QuickForm extends HTML_Common
public function addFormRule($rule)
{
if (!is_callable($rule)) {
return PEAR::raiseError(null, QUICKFORM_INVALID_RULE, null, E_USER_WARNING, 'Callback function does not exist in HTML_QuickForm::addFormRule()', 'HTML_QuickForm_Error', true);
throw new \Exception('Callback function does not exist in HTML_QuickForm::addFormRule()');
}
$this->_formRules[] = $rule;
}
@ -1290,7 +1238,7 @@ class HTML_QuickForm extends HTML_Common
function applyFilter($element, $filter)
{
if (!is_callable($filter)) {
return PEAR::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::applyFilter()", 'HTML_QuickForm_Error', true);
throw new \Exception("Callback function does not exist in QuickForm::applyFilter()");
}
if ($element == '__ALL__') {
$this->_submitValues = $this->_recursiveFilter($filter, $this->_submitValues);
@ -1627,7 +1575,7 @@ class HTML_QuickForm extends HTML_Common
if (is_array($res)) {
$this->_errors += $res;
} else {
return PEAR::raiseError(null, QUICKFORM_ERROR, null, E_USER_WARNING, 'Form rule callback returned invalid value in HTML_QuickForm::validate()', 'HTML_QuickForm_Error', true);
throw new \Exception('Form rule callback returned invalid value in HTML_QuickForm::validate()');
}
}
}
@ -1664,8 +1612,9 @@ class HTML_QuickForm extends HTML_Common
}
if (!empty($elementList)) {
return PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Nonexistant element(s): '" . implode("', '", array_keys($elementList)) . "' in HTML_QuickForm::freeze()", 'HTML_QuickForm_Error', true);
throw new \Exception("Nonexistant element(s): '" . implode("', '", array_keys($elementList)) . "' in HTML_QuickForm::freeze()");
}
return true;
}
@ -1694,9 +1643,10 @@ class HTML_QuickForm extends HTML_Common
public function process($callback, $mergeFiles = true)
{
if (!is_callable($callback)) {
return PEAR::raiseError(null, QUICKFORM_INVALID_PROCESS, null, E_USER_WARNING, "Callback function does not exist in QuickForm::process()", 'HTML_QuickForm_Error', true);
throw new \Exception("Callback function does not exist in QuickForm::process()");
}
$values = ($mergeFiles === true) ? HTML_QuickForm::arrayMerge($this->_submitValues, $this->_submitFiles) : $this->_submitValues;
return call_user_func($callback, $values);
}
@ -1901,7 +1851,7 @@ class HTML_QuickForm extends HTML_Common
function exportValue($element)
{
if (!isset($this->_elementIndex[$element])) {
return PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$element' does not exist in HTML_QuickForm::getElementValue()", 'HTML_QuickForm_Error', true);
throw new \Exception("Element '$element' does not exist in HTML_QuickForm::getElementValue()");
}
$value = $this->_elements[$this->_elementIndex[$element]]->exportValue($this->_submitValues, false);
if (isset($this->_duplicateIndex[$element])) {

@ -175,8 +175,9 @@ class HTML_QuickForm_Controller
function &getPage($pageName)
{
if (!isset($this->_pages[$pageName])) {
return PEAR::raiseError('HTML_QuickForm_Controller: Unknown page "' . $pageName . '"');
throw new \Exception('HTML_QuickForm_Controller: Unknown page "' . $pageName . '"');
}
return $this->_pages[$pageName];
}
@ -210,7 +211,8 @@ class HTML_QuickForm_Controller
return $this->_actions[$actionName]->perform($page, $actionName);
break;
default:
return PEAR::raiseError('HTML_QuickForm_Controller: Unhandled action "' . $actionName . '" in page "' . $page->getAttribute('id') . '"');
throw new \Exception('HTML_QuickForm_Controller: Unhandled action "' . $actionName . '" in page "' . $page->getAttribute('id') . '"');
} // switch
}
@ -410,13 +412,13 @@ class HTML_QuickForm_Controller
if (is_array($filter) && (2 != count($filter) || !is_callable($filter))) {
foreach ($filter as $val) {
if (!is_callable($val)) {
return PEAR::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm_Controller::_setDefaultsOrConstants()", 'HTML_QuickForm_Error', true);
throw new \Exception("Callback function does not exist in QuickForm_Controller::_setDefaultsOrConstants()");
} else {
$newValues = $this->_arrayMapRecursive($val, $newValues);
}
}
} elseif (!is_callable($filter)) {
return PEAR::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm_Controller::_setDefaultsOrConstants()", 'HTML_QuickForm_Error', true);
throw new \Exception("Callback function does not exist in QuickForm_Controller::_setDefaultsOrConstants()");
} else {
$newValues = $this->_arrayMapRecursive($val, $newValues);
}

@ -119,12 +119,12 @@ class HTML_QuickForm_Renderer_QuickHtml extends HTML_QuickForm_Renderer_Default
if (is_null($elementKey)) {
$msg = is_null($elementValue) ? "Element $elementName does not exist." :
"Element $elementName with value of $elementValue does not exist.";
return PEAR::raiseError(null, QUICKFORM_UNREGISTERED_ELEMENT, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
throw new \Exception($msg);
} else {
if ($this->renderedElements[$elementKey]['rendered']) {
$msg = is_null($elementValue) ? "Element $elementName has already been rendered." :
"Element $elementName with value of $elementValue has already been rendered.";
return PEAR::raiseError(null, QUICKFORM_ERROR, null, E_USER_WARNING, $msg, 'HTML_QuickForm_Error', true);
throw new \Exception($msg);
} else {
$this->renderedElements[$elementKey]['rendered'] = true;
return $this->renderedElements[$elementKey]['html'];

@ -163,7 +163,7 @@ class HTML_QuickForm_file extends HTML_QuickForm_input
switch ($event) {
case 'updateValue':
if ($caller->getAttribute('method') == 'get') {
return PEAR::raiseError('Cannot add a file upload field to a GET method form');
throw new \Exception('Cannot add a file upload field to a GET method form');
}
$this->_value = $this->_findValue();
$caller->updateAttributes(array('enctype' => 'multipart/form-data'));

@ -276,8 +276,7 @@ class HTML_Table extends HTML_Common
$this->addBody();
}
} else {
return PEAR::raiseError('Invalid body reference[' .
$body . '] in HTML_Table::' . $method);
throw new \Exception('Invalid body reference[' .$body . '] in HTML_Table::' . $method);
}
}

@ -342,10 +342,8 @@ class HTML_Table_Storage extends HTML_Common
) {
return $this->_structure[$row][$col]['attr'];
} elseif (!isset($this->_structure[$row][$col])) {
return PEAR::raiseError('Invalid table cell reference[' .
$row . '][' . $col . '] in HTML_Table::getCellAttributes');
throw new \Exception('Invalid table cell reference[' .$row . '][' . $col . '] in HTML_Table::getCellAttributes');
}
return;
}
/**
@ -433,8 +431,7 @@ class HTML_Table_Storage extends HTML_Common
return;
}
if (!isset($this->_structure[$row][$col])) {
return PEAR::raiseError('Invalid table cell reference[' .
$row . '][' . $col . '] in HTML_Table::getCellContents');
throw new \Exception('Invalid table cell reference[' .$row . '][' . $col . '] in HTML_Table::getCellContents');
}
return $this->_structure[$row][$col]['contents'];
}
@ -477,8 +474,7 @@ class HTML_Table_Storage extends HTML_Common
$inTR = false)
{
if (isset($contents) && !is_array($contents)) {
return PEAR::raiseError('First parameter to HTML_Table::addRow ' .
'must be an array');
throw new \Exception('First parameter to HTML_Table::addRow must be an array');
}
if (is_null($contents)) {
$contents = array();
@ -620,8 +616,7 @@ class HTML_Table_Storage extends HTML_Common
function addCol($contents = null, $attributes = null, $type = 'td')
{
if (isset($contents) && !is_array($contents)) {
return PEAR::raiseError('First parameter to HTML_Table::addCol ' .
'must be an array');
throw new \Exception('First parameter to HTML_Table::addCol must be an array');
}
if (is_null($contents)) {
$contents = array();

@ -1547,11 +1547,13 @@ class Pager_Common
*/
function raiseError($msg, $code)
{
throw new Exception($msg);
/*
include_once 'PEAR.php';
if (empty($this->_pearErrorMode)) {
$this->_pearErrorMode = PEAR_ERROR_RETURN;
}
return PEAR::raiseError($msg, $code, $this->_pearErrorMode);
return PEAR::raiseError($msg, $code, $this->_pearErrorMode);*/
}
// }}}

Loading…
Cancel
Save