From: Donald A. Lobo Date: Fri, 31 May 2013 20:16:05 +0000 (-0700) Subject: CRM-12743 - goodbye eval X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0e6e872410535da3f9d4675e1005c27a06fac5ba;p=civicrm-core.git CRM-12743 - goodbye eval ---------------------------------------- * CRM-12743: Eliminate use of eval in core code http://issues.civicrm.org/jira/browse/CRM-12743 --- diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index b665527031..0c41a3affa 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -461,7 +461,8 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $this->setFields(); if ($this->_activityTypeFile) { - eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}::preProcess( \$this );"); + $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; + $className::preProcess($this); } $this->_values = $this->get('values'); @@ -592,9 +593,8 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } if ($this->_activityTypeFile) { - eval('$defaults += CRM_' . $this->_crmDir . '_Form_Activity_' . - $this->_activityTypeFile . '::setDefaultValues($this);' - ); + $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; + $defaults += $className::setDefaultValues($this); } if (!CRM_Utils_Array::value('priority_id', $defaults)) { $priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'); @@ -874,14 +874,10 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } if ($this->_activityTypeFile) { - eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}::buildQuickForm( \$this );"); - } + $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; - if ($this->_activityTypeFile) { - eval('$this->addFormRule' . - "(array( - 'CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}', 'formrule'), \$this);" - ); + $className::buildQuickForm($this); + $this->addFormRule(array($className, 'formRule'), $this); } $this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this); @@ -1217,9 +1213,8 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { */ function beginPostProcess(&$params) { if ($this->_activityTypeFile) { - eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}" . - "::beginPostProcess( \$this, \$params );" - ); + $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; + $className::beginPostProcess($this, $params); } } @@ -1230,9 +1225,8 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { */ function endPostProcess(&$params, &$activity) { if ($this->_activityTypeFile) { - eval("CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}" . - "::endPostProcess( \$this, \$params, \$activity );" - ); + $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; + $className::endPostProcess($this, $params, $activity ); } } } diff --git a/CRM/Admin/Form.php b/CRM/Admin/Form.php index 8e89aad39c..6267c9f329 100644 --- a/CRM/Admin/Form.php +++ b/CRM/Admin/Form.php @@ -67,8 +67,8 @@ class CRM_Admin_Form extends CRM_Core_Form { if (isset($this->_id)) { $params = array('id' => $this->_id); // this is needed if the form is outside the CRM name space - require_once (str_replace('_', DIRECTORY_SEPARATOR, $this->_BAOName) . ".php"); - eval($this->_BAOName . '::retrieve( $params, $this->_values );'); + $baoName = $this->_BAOName; + $baoName::retrieve($params, $this->_values ); } } @@ -84,8 +84,8 @@ class CRM_Admin_Form extends CRM_Core_Form { if (isset($this->_id) && empty($this->_values)) { $this->_values = array(); $params = array('id' => $this->_id); - require_once (str_replace('_', DIRECTORY_SEPARATOR, $this->_BAOName) . ".php"); - eval($this->_BAOName . '::retrieve( $params, $this->_values );'); + $baoName = $this->_BAOName; + $baoName::retrieve($params, $this->_values ); } $defaults = $this->_values; diff --git a/CRM/Admin/Form/RelationshipType.php b/CRM/Admin/Form/RelationshipType.php index 55422790ab..aa8892405e 100644 --- a/CRM/Admin/Form/RelationshipType.php +++ b/CRM/Admin/Form/RelationshipType.php @@ -111,7 +111,8 @@ class CRM_Admin_Form_RelationshipType extends CRM_Admin_Form { ) { $defaults = $params = array(); $params = array('id' => $this->_id); - eval($this->_BAOName . '::retrieve( $params, $defaults );'); + $baoName = $this->_BAOName; + $baoName::retrieve($params, $defaults); $defaults['contact_types_a'] = CRM_Utils_Array::value('contact_type_a', $defaults); if (CRM_Utils_Array::value('contact_sub_type_a', $defaults)) { $defaults['contact_types_a'] .= CRM_Core_DAO::VALUE_SEPARATOR . $defaults['contact_sub_type_a']; diff --git a/CRM/Case/Form/Case.php b/CRM/Case/Form/Case.php index f69a3241d7..08e7c01d7f 100644 --- a/CRM/Case/Form/Case.php +++ b/CRM/Case/Form/Case.php @@ -183,7 +183,8 @@ class CRM_Case_Form_Case extends CRM_Core_Form { //when custom data is included in this page CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity'); - eval("CRM_Case_Form_Activity_{$this->_activityTypeFile}::preProcess( \$this );"); + $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}"; + $className::preProcess($this); $activityGroupTree = $this->_groupTree; // for case custom fields to populate with defaults @@ -209,7 +210,8 @@ class CRM_Case_Form_Case extends CRM_Core_Form { if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW || $this->_cdType) { return TRUE; } - eval('$defaults = CRM_Case_Form_Activity_' . $this->_activityTypeFile . '::setDefaultValues($this);'); + $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}"; + $defaults = $className::setDefaultValues($this); $defaults = array_merge($defaults, CRM_Custom_Form_CustomData::setDefaultValues($this)); return $defaults; } @@ -284,7 +286,8 @@ class CRM_Case_Form_Case extends CRM_Core_Form { ) ); - eval("CRM_Case_Form_Activity_{$this->_activityTypeFile}::buildQuickForm( \$this );"); + $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}"; + $className::buildQuickForm($this); } /** @@ -298,7 +301,8 @@ class CRM_Case_Form_Case extends CRM_Core_Form { if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW || $this->_cdType) { return TRUE; } - eval('$this->addFormRule' . "(array('CRM_Case_Form_Activity_{$this->_activityTypeFile}', 'formrule'), \$this);"); + $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}"; + $this->addFormRule(array($className, 'formRule'), $this); $this->addFormRule(array('CRM_Case_Form_Case', 'formRule'), $this); } @@ -357,14 +361,17 @@ class CRM_Case_Form_Case extends CRM_Core_Form { // 1. call begin post process if ($this->_activityTypeFile) { - eval("CRM_Case_Form_Activity_{$this->_activityTypeFile}" . "::beginPostProcess( \$this, \$params );"); + $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}"; + $className::beginPostProcess($this, $params ); } - if (CRM_Utils_Array::value('hidden_custom', $params) && + if ( + CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom']) ) { $customFields = array(); - $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, + $params['custom'] = CRM_Core_BAO_CustomField::postProcess( + $params, $customFields, NULL, 'Case' @@ -422,7 +429,7 @@ class CRM_Case_Form_Case extends CRM_Core_Form { // 4. call end post process if ($this->_activityTypeFile) { - eval("CRM_Case_Form_Activity_{$this->_activityTypeFile}" . "::endPostProcess( \$this, \$params );"); + $className::endPostProcess($this, $params ); } // 5. auto populate activites diff --git a/CRM/Contact/DAO/Factory.php b/CRM/Contact/DAO/Factory.php index d4b89050ef..419885a19d 100644 --- a/CRM/Contact/DAO/Factory.php +++ b/CRM/Contact/DAO/Factory.php @@ -23,21 +23,7 @@ class CRM_Contact_DAO_Factory { static $_suffix = '.php'; - static $_preCall = array( - 'singleton' => '', - 'business' => 'new', - 'data' => 'new', - ); - - static $_extCall = array( - 'singleton' => '::singleton', - 'business' => '', - 'data' => '', - ); - - - static - function &create($className) { + static function &create($className) { $type = CRM_Utils_Array::value($className, self::$_classes); if (!$type) { return CRM_Core_DAO_Factory::create($className); @@ -48,13 +34,14 @@ class CRM_Contact_DAO_Factory { require_once ($file . self::$_suffix); - $newObj = eval(sprintf("return %s %s%s();", - self::$_preCall[$type], - $class, - self::$_extCall[$type] - )); + if ($type == 'singleton') { + $newObj = $class::singleton(); + } + else { + // this is either 'business' or 'data' + $newObj = new $class; + } return $newObj; } } - diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index e6fcc3f775..ed1193f143 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -156,7 +156,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { $this->_paneTemplatePath[$type] = $c->getAdvancedSearchPaneTemplatePath(); } else { - eval('CRM_Contact_Form_Search_Criteria::' . $type . '( $this );'); + CRM_Contact_Form_Search_Criteria::$type($this); $template = ucfirst($type); $this->_paneTemplatePath[$type] = "CRM/Contact/Form/Search/Criteria/{$template}.tpl"; } diff --git a/CRM/Contact/Import/Form/Preview.php b/CRM/Contact/Import/Form/Preview.php index f84341e2ba..ad446974f8 100644 --- a/CRM/Contact/Import/Form/Preview.php +++ b/CRM/Contact/Import/Form/Preview.php @@ -215,9 +215,13 @@ class CRM_Contact_Import_Form_Preview extends CRM_Core_Form { $title = trim($fields['newGroupName']); $name = CRM_Utils_String::titleToVar($title); $query = 'select count(*) from civicrm_group where name like %1 OR title like %2'; - $grpCnt = CRM_Core_DAO::singleValueQuery($query, array(1 => array($name, 'String'), + $grpCnt = CRM_Core_DAO::singleValueQuery( + $query, + array( + 1 => array($name, 'String'), 2 => array($title, 'String'), - )); + ) + ); if ($grpCnt) { $invalidGroupName = TRUE; $errors['newGroupName'] = ts('Group \'%1\' already exists.', array(1 => $fields['newGroupName'])); @@ -388,7 +392,8 @@ class CRM_Contact_Import_Form_Preview extends CRM_Core_Form { $relationType = new CRM_Contact_DAO_RelationshipType(); $relationType->id = $id; $relationType->find(TRUE); - eval('$mapperRelatedContactType[$key] = $relationType->contact_type_' . $second . ';'); + $fieldName = "contact_type_$second"; + $mapperRelatedContactType[$key] = $relationType->$fieldName; $mapperRelated[$key] = $mapper[$key][0]; $mapperRelatedContactDetails[$key] = $mapper[$key][1]; $mapperRelatedContactLocType[$key] = $mapper[$key][2]; diff --git a/CRM/Contact/Import/ImportJob.php b/CRM/Contact/Import/ImportJob.php index ddfcbdd352..220c0eb3c9 100644 --- a/CRM/Contact/Import/ImportJob.php +++ b/CRM/Contact/Import/ImportJob.php @@ -137,7 +137,8 @@ class CRM_Contact_Import_ImportJob { public function setJobParams(&$params) { foreach ($params as $param => $value) { - eval("\$this->_$param = \$value;"); + $fldName = "_$param"; + $this->$fldName = $value; } } diff --git a/CRM/Contact/StateMachine/Search.php b/CRM/Contact/StateMachine/Search.php index f04eed1ac7..4f4188ba3b 100644 --- a/CRM/Contact/StateMachine/Search.php +++ b/CRM/Contact/StateMachine/Search.php @@ -108,8 +108,8 @@ class CRM_Contact_StateMachine_Search extends CRM_Core_StateMachine { if ($value) { $componentMode = $this->_controller->get('component_mode'); $modeValue = CRM_Contact_Form_Search::getModeValue($componentMode); - require_once (str_replace('_', DIRECTORY_SEPARATOR, $modeValue['taskClassName']) . '.php'); - return eval("return {$modeValue['taskClassName']}::getTask( $value );"); + $taskClassName = $modeValue['taskClassName']; + return $taskClassName::getTask($value); } else { return CRM_Contact_Task::getTask($value); diff --git a/CRM/Contribute/Form.php b/CRM/Contribute/Form.php index 3e359c836d..c9bc305cee 100644 --- a/CRM/Contribute/Form.php +++ b/CRM/Contribute/Form.php @@ -71,8 +71,8 @@ class CRM_Contribute_Form extends CRM_Core_Form { if (isset($this->_id)) { $params = array('id' => $this->_id); if (!empty( $this->_BAOName)) { - require_once (str_replace('_', DIRECTORY_SEPARATOR, $this->_BAOName) . ".php"); - eval($this->_BAOName . '::retrieve( $params, $defaults );'); + $baoName = $this->_BAOName; + $baoName::retrieve($params, $defaults); } } if ($this->_action == CRM_Core_Action::DELETE && CRM_Utils_Array::value('name', $defaults)) { @@ -95,7 +95,7 @@ class CRM_Contribute_Form extends CRM_Core_Form { if ($parentId = CRM_Utils_Array::value('parent_id', $defaults)) { $this->assign('parentId', $parentId); } - } + } return $defaults; } diff --git a/CRM/Contribute/Form/AdditionalInfo.php b/CRM/Contribute/Form/AdditionalInfo.php index b01b243286..c62558613e 100644 --- a/CRM/Contribute/Form/AdditionalInfo.php +++ b/CRM/Contribute/Form/AdditionalInfo.php @@ -114,7 +114,7 @@ class CRM_Contribute_Form_AdditionalInfo { if ($form->_online) { $feeAmount->freeze(); } - + $netAmount = & $form->add('text', 'net_amount', ts('Net Amount'), $attributes['net_amount'] ); @@ -145,13 +145,13 @@ class CRM_Contribute_Form_AdditionalInfo { ); $form->add('textarea', 'note', ts('Notes'), array("rows" => 4, "cols" => 60)); - + $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); if ($form->_id && $form->_values['contribution_status_id'] == array_search('Cancelled', $statusName)) { $netAmount->freeze(); $feeAmount->freeze(); } - + } /** diff --git a/CRM/Contribute/Form/ContributionCharts.php b/CRM/Contribute/Form/ContributionCharts.php index ce2fdc288a..f562e8f66f 100644 --- a/CRM/Contribute/Form/ContributionCharts.php +++ b/CRM/Contribute/Form/ContributionCharts.php @@ -187,7 +187,7 @@ class CRM_Contribute_Form_ContributionCharts extends CRM_Core_Form { $funName = ($chartType == 'bvg') ? 'barChart' : 'pieChart'; // build the chart objects. - eval("\$values['object'] = CRM_Utils_OpenFlashChart::" . $funName . '( $values );'); + $values['object'] = CRM_Utils_OpenFlashChart::$funName($values); //build the urls. $urlCnt = 0; diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index d322c79d15..5d4de53dbe 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -304,7 +304,8 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup { * @static * */ - public static function &getTree($entityType, + public static function &getTree( + $entityType, &$form, $entityID = NULL, $groupID = NULL, @@ -2047,10 +2048,7 @@ SELECT civicrm_custom_group.id as groupID, civicrm_custom_group.title as groupT // description is expected to be a callback func to subtypes list($callback, $args) = explode(';', trim($ovValues['description'])); - if (!empty($args)) { - eval('$args = ' . $args . ';'); - } - else { + if (empty($args)) { $args = array(); } diff --git a/CRM/Core/Block.php b/CRM/Core/Block.php index f7312269ac..b4292788b6 100644 --- a/CRM/Core/Block.php +++ b/CRM/Core/Block.php @@ -364,7 +364,7 @@ class CRM_Core_Block { foreach ($components as $componentName => $obj) { if (in_array($componentName, $config->enableComponents)) { - eval('$obj->creatNewShortcut( $shortCuts, $newCredit );'); + $obj->creatNewShortcut($shortCuts, $newCredit); } } } diff --git a/CRM/Core/DAO/Factory.php b/CRM/Core/DAO/Factory.php index b94894fb90..d2db1b9474 100644 --- a/CRM/Core/DAO/Factory.php +++ b/CRM/Core/DAO/Factory.php @@ -18,21 +18,7 @@ class CRM_Core_DAO_Factory { static $_suffix = '.php'; - static $_preCall = array( - 'singleton' => '', - 'business' => 'new', - 'data' => 'new', - ); - - static $_extCall = array( - 'singleton' => '::singleton', - 'business' => '', - 'data' => '', - ); - - - static - function &create($className) { + static function &create($className) { $type = CRM_Utils_Array::value($className, self::$_classes); if (!$type) { CRM_Core_Error::fatal("class $className not found"); @@ -43,13 +29,14 @@ class CRM_Core_DAO_Factory { require_once ($file . self::$_suffix); - $newObj = eval(sprintf("return %s %s%s();", - self::$_preCall[$type], - $class, - self::$_extCall[$type] - )); + if ($type == 'singleton') { + $newObj = $class::singleton(); + } + else { + // this is either 'business' or 'data' + $newObj = new $class; + } return $newObj; } } - diff --git a/CRM/Core/I18n/Schema.php b/CRM/Core/I18n/Schema.php index f6b463c456..e2adc51d4c 100644 --- a/CRM/Core/I18n/Schema.php +++ b/CRM/Core/I18n/Schema.php @@ -174,8 +174,8 @@ class CRM_Core_I18n_Schema { return; } - eval("\$columns =& $class::columns();"); - eval("\$indices =& $class::indices();"); + $columns =& $class::columns(); + $indices =& $class::indices(); $queries = array(); $dropQueries = array(); // drop indices @@ -304,8 +304,8 @@ class CRM_Core_I18n_Schema { else { $class = 'CRM_Core_I18n_SchemaStructure'; } - eval("\$indices =& $class::indices();"); - eval("\$tables =& $class::tables();"); + $indices =& $class::indices(); + $tables =& $class::tables(); $queries = array(); $dao = new CRM_Core_DAO; @@ -378,7 +378,7 @@ class CRM_Core_I18n_Schema { // class loader look for file like - CRM/Core/I18n/SchemaStructure/4/1/0.php which is not what we want to be loaded require_once "CRM/Core/I18n/SchemaStructure_{$latest}.php"; $class = "CRM_Core_I18n_SchemaStructure_{$latest}"; - eval("\$tables =& $class::tables();"); + $tables =& $class::tables(); } else { $tables = CRM_Core_I18n_SchemaStructure::tables(); @@ -420,8 +420,8 @@ class CRM_Core_I18n_Schema { * @return array array of CREATE INDEX queries */ private static function createIndexQueries($locale, $table, $class = 'CRM_Core_I18n_SchemaStructure') { - eval("\$indices =& $class::indices();"); - eval("\$columns =& $class::columns();"); + $indices =& $class::indices(); + $columns =& $class::columns(); if (!isset($indices[$table])) { return array(); } @@ -460,7 +460,7 @@ class CRM_Core_I18n_Schema { * @return array array of CREATE INDEX queries */ private static function createViewQuery($locale, $table, &$dao, $class = 'CRM_Core_I18n_SchemaStructure') { - eval("\$columns =& $class::columns();"); + $columns =& $class::columns(); $cols = array(); $dao->query("DESCRIBE {$table}", FALSE); while ($dao->fetch()) { @@ -506,7 +506,7 @@ class CRM_Core_I18n_Schema { $class = 'CRM_Core_I18n_SchemaStructure'; } - eval("\$columns =& $class::columns();"); + $columns =& $class::columns(); foreach ($columns as $table => $hash) { if ($tableName && diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 80a7702f51..968cffefca 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -113,7 +113,7 @@ abstract class CRM_Core_Payment { } //load the object. - self::$_singleton[$cacheKey] = eval('return ' . $paymentClass . '::singleton( $mode, $paymentProcessor );'); + self::$_singleton[$cacheKey] = $paymentClass::singleton($mode, $paymentProcessor); } //load the payment form for required processor. @@ -266,7 +266,7 @@ abstract class CRM_Core_Payment { } // Instantiate PP - eval('$processorInstance = ' . $paymentClass . '::singleton( $mode, $paymentProcessor );'); + $processorInstance = $paymentClass::singleton($mode, $paymentProcessor); // Does PP implement this method, and can we call it? if (!method_exists($processorInstance, $method) || diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 3607893c02..7271efd1b9 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -389,7 +389,7 @@ class CRM_Core_PseudoConstant { * * @return string */ - function getValue($daoName, $fieldName, $key, $params = array()) { + static function getValue($daoName, $fieldName, $key, $params = array()) { $values = self::get($daoName, $fieldName, $params); return CRM_Utils_Array::value($key, $values); } @@ -404,7 +404,7 @@ class CRM_Core_PseudoConstant { * * @return string */ - function getKey($daoName, $fieldName, $value, $params = array()) { + static function getKey($daoName, $fieldName, $value, $params = array()) { $values = self::get($daoName, $fieldName, $params); return CRM_Utils_Array::key($value, $values); } @@ -565,7 +565,7 @@ class CRM_Core_PseudoConstant { } return self::$activityType[$index]; } - + /** * Get all the State/Province from database. * diff --git a/CRM/Event/Form/ManageEvent/Location.php b/CRM/Event/Form/ManageEvent/Location.php index 071da30d24..ed4ac253cd 100644 --- a/CRM/Event/Form/ManageEvent/Location.php +++ b/CRM/Event/Form/ManageEvent/Location.php @@ -179,7 +179,8 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent { public function buildQuickForm() { //load form for child blocks if ($this->_addBlockName) { - return eval('CRM_Contact_Form_Edit_' . $this->_addBlockName . '::buildQuickForm( $this );'); + $className = "CRM_Contact_Form_Edit_{$this->_addBlockName}"; + return $className::buildQuickForm($this); } $this->applyFilter('__ALL__', 'trim'); diff --git a/CRM/Export/Form/Select.php b/CRM/Export/Form/Select.php index 28e9bb502e..5f259688ec 100644 --- a/CRM/Export/Form/Select.php +++ b/CRM/Export/Form/Select.php @@ -41,12 +41,25 @@ class CRM_Export_Form_Select extends CRM_Core_Form { /** * various Contact types */ - CONST EXPORT_ALL = 1, EXPORT_SELECTED = 2, EXPORT_MERGE_DO_NOT_MERGE = 0, EXPORT_MERGE_SAME_ADDRESS = 1, EXPORT_MERGE_HOUSEHOLD = 2; + CONST + EXPORT_ALL = 1, + EXPORT_SELECTED = 2, + EXPORT_MERGE_DO_NOT_MERGE = 0, + EXPORT_MERGE_SAME_ADDRESS = 1, + EXPORT_MERGE_HOUSEHOLD = 2; /** * export modes */ - CONST CONTACT_EXPORT = 1, CONTRIBUTE_EXPORT = 2, MEMBER_EXPORT = 3, EVENT_EXPORT = 4, PLEDGE_EXPORT = 5, CASE_EXPORT = 6, GRANT_EXPORT = 7, ACTIVITY_EXPORT = 8; + CONST + CONTACT_EXPORT = 1, + CONTRIBUTE_EXPORT = 2, + MEMBER_EXPORT = 3, + EVENT_EXPORT = 4, + PLEDGE_EXPORT = 5, + CASE_EXPORT = 6, + GRANT_EXPORT = 7, + ACTIVITY_EXPORT = 8; /** * current export mode @@ -98,8 +111,10 @@ class CRM_Export_Form_Select extends CRM_Core_Form { $components = array('Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity'); if (in_array($componentName[1], $components)) { - eval('$this->_exportMode = self::' . strtoupper($componentName[1]) . '_EXPORT;'); - eval('CRM_' . $componentName[1] . '_Form_Task::preProcessCommon( $this, true );'); + $fieldName = strtoupper($componentName[1]) . '_EXPORT'; + $this->_exportMode = self::$fieldName; + $className = "CRM_{$componentName[1]}_Form_Task"; + $className::preProcessCommon( $this, true ); $values = $this->controller->exportValues('Search'); } else { @@ -161,7 +176,8 @@ class CRM_Export_Form_Select extends CRM_Core_Form { } else { $this->assign('taskName', "Export $componentName[1]"); - eval('$componentTasks = CRM_' . $componentName[1] . '_Task::tasks();'); + $className = "CRM_{$componentName[1]}_Task"; + $componentTasks = $className::tasks(); $taskName = $componentTasks[$this->_task]; $component = TRUE; } diff --git a/CRM/Extension/Manager/Payment.php b/CRM/Extension/Manager/Payment.php index 9a79f4991c..b5ba73b243 100644 --- a/CRM/Extension/Manager/Payment.php +++ b/CRM/Extension/Manager/Payment.php @@ -263,7 +263,7 @@ class CRM_Extension_Manager_Payment extends CRM_Extension_Manager_Base { case 'disable': // Instantiate PP - eval('$processorInstance = ' . $paymentClass . '::singleton( null, $paymentProcessor );'); + $processorInstance = $paymentClass::singleton(NULL, $paymentProcessor); // Does PP implement this method, and can we call it? if (method_exists($processorInstance, $method) && is_callable(array( diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index 9c53bf618e..e4ddefcc5b 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -47,7 +47,7 @@ class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAcco function __construct() { parent::__construct(); } - + /** * Takes a bunch of params that are needed to match certain criteria and * retrieves the relevant objects. Typically the valid params are only @@ -90,9 +90,9 @@ class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAcco * * @param array $params reference array contains the values submitted by the form * @param array $ids reference array contains the id - * + * * @access public - * @static + * @static * @return object */ static function add(&$params, &$ids) { @@ -105,8 +105,8 @@ class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAcco $query = 'UPDATE civicrm_financial_account SET is_default = 0 WHERE financial_account_type_id = %1'; $queryParams = array(1 => array($params['financial_account_type_id'], 'Integer')); CRM_Core_DAO::executeQuery($query, $queryParams); - } - + } + // action is taken depending upon the mode $financialAccount = new CRM_Financial_DAO_FinancialAccount(); $financialAccount->copyValues($params); @@ -114,42 +114,43 @@ class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAcco $financialAccount->save(); return $financialAccount; } - + /** - * Function to delete financial Types - * + * Function to delete financial Types + * * @param int $financialAccountId * @static */ static function del($financialAccountId) { - //checking if financial type is present + //checking if financial type is present $check = FALSE; - + //check dependencies - $dependancy = array( - array('Core', 'FinancialTrxn', 'to_financial_account_id'), - array('Financial', 'FinancialTypeAccount', 'financial_account_id'), + $dependancy = array( + array('Core', 'FinancialTrxn', 'to_financial_account_id'), + array('Financial', 'FinancialTypeAccount', 'financial_account_id'), ); foreach ($dependancy as $name) { require_once (str_replace('_', DIRECTORY_SEPARATOR, "CRM_" . $name[0] . "_BAO_" . $name[1]) . ".php"); - eval('$bao = new CRM_' . $name[0] . '_BAO_' . $name[1] . '();'); + $className = "CRM_{$name[0]}_BAO_{$name[1]}"; + $bao = new $className(); $bao->$name[2] = $financialAccountId; if ($bao->find(TRUE)) { $check = TRUE; } } - + if ($check) { CRM_Core_Session::setStatus(ts('This financial account cannot be deleted since it is being used as a header account. Please remove it from being a header account before trying to delete it again.')); return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialAccount', "reset=1&action=browse")); } - + //delete from financial Type table $financialAccount = new CRM_Financial_DAO_FinancialAccount(); $financialAccount->id = $financialAccountId; $financialAccount->delete(); } - + /** * get accounting code for a financial type with account relation Income Account is * @@ -172,7 +173,7 @@ WHERE cft.id = %1 ); return CRM_Core_DAO::singleValueQuery($query, $params); } - + /** * get AR account * diff --git a/CRM/Mailing/Form/Component.php b/CRM/Mailing/Form/Component.php index 272a44d0b1..eb07a8a7cc 100644 --- a/CRM/Mailing/Form/Component.php +++ b/CRM/Mailing/Form/Component.php @@ -118,8 +118,8 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form { if (isset($this->_id)) { $params = array('id' => $this->_id); - require_once (str_replace('_', DIRECTORY_SEPARATOR, $this->_BAOName) . ".php"); - eval($this->_BAOName . '::retrieve( $params, $defaults );'); + $baoName = $this->_BAOName; + $baoName::retrieve($params, $defaults); } $defaults['is_active'] = 1; diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 5c99e44771..84cb93d63b 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -71,8 +71,8 @@ class CRM_Member_Form extends CRM_Core_Form { if (isset($this->_id)) { $params = array('id' => $this->_id); - require_once (str_replace('_', DIRECTORY_SEPARATOR, $this->_BAOName) . ".php"); - eval($this->_BAOName . '::retrieve( $params, $defaults );'); + $baoName = $this->_BAOName; + $baoName::retrieve($params, $defaults); } if (isset($defaults['minimum_fee'])) { diff --git a/CRM/Pledge/Form/Pledge.php b/CRM/Pledge/Form/Pledge.php index 6cb55a661e..d1ecbb5c86 100644 --- a/CRM/Pledge/Form/Pledge.php +++ b/CRM/Pledge/Form/Pledge.php @@ -330,7 +330,8 @@ class CRM_Pledge_Form_Pledge extends CRM_Core_Form { $showAdditionalInfo = TRUE; $allPanes[$name]['open'] = 'true'; } - eval('CRM_Contribute_Form_AdditionalInfo::build' . $type . '( $this );'); + $fnName = "build{$type}"; + CRM_Contribute_Form_AdditionalInfo::$fnName($this); } $this->assign('allPanes', $allPanes); diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 07ae9fca8e..4088c94243 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -437,12 +437,12 @@ class CRM_Report_Form extends CRM_Core_Form { // higher preference to bao object if (array_key_exists('bao', $table)) { - require_once str_replace('_', DIRECTORY_SEPARATOR, $table['bao'] . '.php'); - eval("\$expFields = {$table['bao']}::exportableFields( );"); + $baoName = $table['bao']; + $expFields = $baoName::exportableFields( ); } elseif (array_key_exists('dao', $table)){ - require_once str_replace('_', DIRECTORY_SEPARATOR, $table['dao'] . '.php'); - eval("\$expFields = {$table['dao']}::export( );"); + $daoName = $table['dao']; + $expFields = $daoName::export( ); } else{ $expFields = array(); @@ -1284,7 +1284,7 @@ class CRM_Report_Form extends CRM_Core_Form { if (isset($field['clause'])) { // FIXME: we not doing escape here. Better solution is to use two // different types - data-type and filter-type - eval("\$clause = \"{$field['clause']}\";"); + $clause = $field['clause']; } else { $value = CRM_Utils_Type::escape($value, $type); diff --git a/CRM/SMS/Provider.php b/CRM/SMS/Provider.php index 72c6e1251f..31422f381d 100644 --- a/CRM/SMS/Provider.php +++ b/CRM/SMS/Provider.php @@ -82,7 +82,7 @@ abstract class CRM_SMS_Provider { CRM_Core_Error::fatal("Could not locate extension for {$providerName}."); } - self::$_singleton[$cacheKey] = eval('return ' . $paymentClass . '::singleton( $providerParams, $force );'); + self::$_singleton[$cacheKey] = $paymentClass::singleton($providerParams, $force); } return self::$_singleton[$cacheKey]; } diff --git a/CRM/UF/Form/Group.php b/CRM/UF/Form/Group.php index d24caa9a03..1a564e2d42 100644 --- a/CRM/UF/Form/Group.php +++ b/CRM/UF/Form/Group.php @@ -180,7 +180,7 @@ class CRM_UF_Form_Group extends CRM_Core_Form { 'id' => $type, ); - eval('CRM_UF_Form_AdvanceSetting::' . $type . '( $this );'); + CRM_UF_Form_AdvanceSetting::$type($this); } $this->addButtons(array( diff --git a/CRM/Upgrade/Form.php b/CRM/Upgrade/Form.php index 7ec91adfbe..229f0d0eec 100644 --- a/CRM/Upgrade/Form.php +++ b/CRM/Upgrade/Form.php @@ -121,7 +121,8 @@ class CRM_Upgrade_Form extends CRM_Core_Form { $versionName = self::$_numberMap[$versionParts[0]] . self::$_numberMap[$versionParts[1]]; if (!array_key_exists($versionName, $incrementalPhpObject)) { - eval("\$incrementalPhpObject['$versionName'] = new CRM_Upgrade_Incremental_php_{$versionName};"); + $className = "CRM_Upgrade_Incremental_php_{$versionName}"; + $incrementalPhpObject['$versionName'] = new $className(); } return $incrementalPhpObject[$versionName]; } diff --git a/CRM/Utils/Address/BatchUpdate.php b/CRM/Utils/Address/BatchUpdate.php index 537b290c8c..b9e7f5d09a 100644 --- a/CRM/Utils/Address/BatchUpdate.php +++ b/CRM/Utils/Address/BatchUpdate.php @@ -177,7 +177,8 @@ class CRM_Utils_Address_BatchUpdate { usleep(5000000); } - eval($config->geocodeMethod . '::format( $params, true );'); + $className = $config->geocodeMethod; + $className::format( $params, true ); array_shift($params); $maxTries--; } while ((!isset($params['geo_code_1'])) && diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index e5184e27ec..2111970642 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -1572,7 +1572,7 @@ class CRM_Utils_Date { } // validate date. - eval('$valid = CRM_Utils_Rule::' . $ruleName . '( $dateVal );'); + $valid = CRM_Utils_Rule::$ruleName($dateVal); if ($valid) { //format date and time to default. diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index acb7e03a2a..293d3d08a6 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -1004,8 +1004,8 @@ function _civicrm_api3_deprecated_add_formatted_location_blocks(&$values, &$para } if (!array_key_exists($block, $fields)) { - require_once (str_replace('_', DIRECTORY_SEPARATOR, "CRM_Core_DAO_" . $block) . ".php"); - eval('$fields[$block] =& CRM_Core_DAO_' . $block . '::fields( );'); + $className = "CRM_Core_DAO_$block"; + $fields[$block] =& $className::fields( ); } $blockCnt = count($params[$name]); diff --git a/CRM/Utils/OpenFlashChart.php b/CRM/Utils/OpenFlashChart.php index 344d613997..efbc0f642c 100644 --- a/CRM/Utils/OpenFlashChart.php +++ b/CRM/Utils/OpenFlashChart.php @@ -477,7 +477,7 @@ class CRM_Utils_OpenFlashChart { $openFlashChart = array(); if ($chart && is_array($params) && !empty($params)) { // build the chart objects. - eval("\$chartObj = CRM_Utils_OpenFlashChart::" . $chart . '( $params );'); + $chartObj = CRM_Utils_OpenFlashChart::$chart($params); $openFlashChart = array(); if ($chartObj) { diff --git a/CRM/Utils/SoapServer.php b/CRM/Utils/SoapServer.php index cd9f2a5eae..348c1e0f06 100644 --- a/CRM/Utils/SoapServer.php +++ b/CRM/Utils/SoapServer.php @@ -129,7 +129,8 @@ class CRM_Utils_SoapServer { $loadCMSBootstrap = true; } - eval('$result =& ' . $this->ufClass . '::authenticate($name, $pass, $loadCMSBootstrap );'); + $className = $this->ufClass; + $result =& $className::authenticate($name, $pass, $loadCMSBootstrap ); if (empty($result)) { throw new SoapFault('Client', 'Invalid login'); diff --git a/CRM/Utils/System/Soap.php b/CRM/Utils/System/Soap.php index 10d6e1384e..c8d2c24704 100644 --- a/CRM/Utils/System/Soap.php +++ b/CRM/Utils/System/Soap.php @@ -111,7 +111,8 @@ class CRM_Utils_System_Soap extends CRM_Utils_System_Base { */ function url($path = NULL, $query = NULL, $absolute = TRUE, $fragment = NULL) { if (isset(self::$ufClass)) { - eval('$url = ' . self::$ufClass . '::url($path, $query, $absolute, $fragment);'); + $className = self::$ufClass; + $url = $className::url($path, $query, $absolute, $fragment); return $url; } else { @@ -152,7 +153,8 @@ class CRM_Utils_System_Soap extends CRM_Utils_System_Base { */ function &authenticate($name, $pass) { if (isset(self::$ufClass)) { - eval('$result =& ' . self::$ufClass . '::authenticate($name, $pass);'); + $className = self::$ufClass; + $result =& $className::authenticate($name, $pass); return $result; } else {