Skip to content
Snippets Groups Projects
Commit 9f092434 authored by colemanw's avatar colemanw
Browse files

Merge pull request #933 from dlobo/CRM-12743

CRM-12743 - goodbye eval
parents ff4f7744 0e6e8724
No related branches found
No related tags found
No related merge requests found
Showing
with 109 additions and 112 deletions
......@@ -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 );
}
}
}
......
......@@ -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;
......
......@@ -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'];
......
......@@ -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
......
......@@ -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;
}
}
......@@ -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";
}
......
......@@ -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];
......
......@@ -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;
}
}
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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();
}
}
/**
......
......@@ -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;
......
......@@ -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();
}
......
......@@ -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);
}
}
}
......
......@@ -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;
}
}
......@@ -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 &&
......
......@@ -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) ||
......
......@@ -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.
*
......
......@@ -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');
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment