From 4d5c2eb510a6be0017085d1f8dae09495e28e74b Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 9 May 2013 11:52:40 +1200 Subject: [PATCH] Remove all eval instances where eval is being used to instantiate a new object using a variable as the name --- CRM/Contact/BAO/SearchCustom.php | 2 +- CRM/Contact/Form/Search/Custom.php | 2 +- CRM/Contact/Form/Task.php | 5 ++--- CRM/Contact/Form/Task/Print.php | 8 +++----- CRM/Contact/Selector/Custom.php | 5 ++--- CRM/Core/BAO/Location.php | 8 ++++---- CRM/Core/BAO/LocationType.php | 4 ++-- CRM/Core/OptionValue.php | 3 +-- CRM/Core/Page/Basic.php | 4 ++-- CRM/Event/Form/Task/Badge.php | 4 +--- CRM/Event/Page/ParticipantListing.php | 2 +- CRM/Financial/BAO/FinancialTypeAccount.php | 3 ++- CRM/Logging/Differ.php | 3 +-- CRM/Logging/Reverter.php | 3 +-- CRM/Member/BAO/MembershipStatus.php | 4 ++-- CRM/Member/BAO/MembershipType.php | 4 ++-- CRM/Upgrade/Incremental/Legacy.php | 4 ++-- CRM/Upgrade/TwoOne/Page/Upgrade.php | 4 ++-- CRM/Utils/Migrate/Export.php | 4 +--- CRM/Utils/Migrate/ImportJSON.php | 5 ++--- CRM/Utils/Weight.php | 7 ++----- tests/phpunit/CiviTest/CiviDBAssert.php | 3 +-- tests/phpunit/CiviTest/CiviUnitTestCase.php | 3 +-- 23 files changed, 39 insertions(+), 55 deletions(-) diff --git a/CRM/Contact/BAO/SearchCustom.php b/CRM/Contact/BAO/SearchCustom.php index aa341e12a9..76ed287cbf 100644 --- a/CRM/Contact/BAO/SearchCustom.php +++ b/CRM/Contact/BAO/SearchCustom.php @@ -99,7 +99,7 @@ class CRM_Contact_BAO_SearchCustom { } // instantiate the new class - eval('$customClass = new ' . $customSearchClass . '( $formValues );'); + $customClass = new $customSearchClass( $formValues ); return $customClass; } diff --git a/CRM/Contact/Form/Search/Custom.php b/CRM/Contact/Form/Search/Custom.php index b1edfc16ff..8a77cf44b6 100644 --- a/CRM/Contact/Form/Search/Custom.php +++ b/CRM/Contact/Form/Search/Custom.php @@ -75,7 +75,7 @@ class CRM_Contact_Form_Search_Custom extends CRM_Contact_Form_Search { parent::preProcess(); // instantiate the new class - eval('$this->_customClass = new ' . $this->_customSearchClass . '( $this->_formValues );'); + $this->_customClass = new $this->_customSearchClass( $this->_formValues ); } function setDefaultValues() { diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php index ce74d5d2c1..eb96060ceb 100644 --- a/CRM/Contact/Form/Task.php +++ b/CRM/Contact/Form/Task.php @@ -292,9 +292,8 @@ class CRM_Contact_Form_Task extends CRM_Core_Form { require_once 'CRM/Core/BAO/Mapping.php'; $returnProperties = CRM_Core_BAO_Mapping::returnProperties(self::$_searchFormValues); - eval('$selector = new ' . - $selectorName . - '( $customClass, $fv, null, $returnProperties ); ' + $selector = new $selectorName( + $customClass, $fv, null, $returnProperties ); $params = $this->get('queryParams'); diff --git a/CRM/Contact/Form/Task/Print.php b/CRM/Contact/Form/Task/Print.php index cb3b7c89c8..0d96564728 100644 --- a/CRM/Contact/Form/Task/Print.php +++ b/CRM/Contact/Form/Task/Print.php @@ -86,15 +86,13 @@ class CRM_Contact_Form_Task_Print extends CRM_Contact_Form_Task { $returnP = isset($returnPropeties) ? $returnPropeties : ""; $customSearchClass = $this->get('customSearchClass'); - eval('$selector = new ' . - $selectorName . - '( $customSearchClass, + $selector = new $selectorName( $customSearchClass, $fv, $params, $returnP, $this->_action, - $includeContactIds );' - ); + $includeContactIds + ); $controller = new CRM_Core_Selector_Controller($selector, NULL, $sortID, diff --git a/CRM/Contact/Selector/Custom.php b/CRM/Contact/Selector/Custom.php index eb63dfb030..fd10d7f42a 100644 --- a/CRM/Contact/Selector/Custom.php +++ b/CRM/Contact/Selector/Custom.php @@ -141,12 +141,11 @@ class CRM_Contact_Selector_Custom extends CRM_Contact_Selector { else { require_once (str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php'); } - eval('$this->_search = new ' . $customSearchClass . '( $formValues );'); + $this->_search = new $customSearchClass( $formValues ); } else { $customSearchFile = $ext->keyToPath($customSearchClass, 'search'); - require_once ($customSearchFile); - eval('$this->_search = new ' . $ext->keyToClass($customSearchClass, 'search') . '( $formValues );'); + $this->_search = new $ext->keyToClass($customSearchClass, 'search')( $formValues ); } } //end of constructor diff --git a/CRM/Core/BAO/Location.php b/CRM/Core/BAO/Location.php index 396857b8cd..1be4763fbf 100644 --- a/CRM/Core/BAO/Location.php +++ b/CRM/Core/BAO/Location.php @@ -198,8 +198,8 @@ WHERE e.id = %1"; $locBlock->delete(); foreach ($store as $daoName => $id) { if ($id) { - $daoName = substr($daoName, 0, -2); - eval('$dao = new CRM_Core_DAO_' . $daoName . '( );'); + $daoName = 'CRM_Core_DAO_' . substr($daoName, 0, -2); + $dao = new $daoName(); $dao->id = $id; $dao->find(TRUE); $dao->delete(); @@ -245,7 +245,7 @@ WHERE e.id = %1"; if (empty($entityBlock)) { return NULL; } - + $blocks = array(); $name_map = array( 'im' => 'IM', 'openid' => 'OpenID', @@ -259,7 +259,7 @@ WHERE e.id = %1"; else { $name = ucfirst($block); } - $baoString = 'CRM_Core_BAO_' . $name ; + $baoString = 'CRM_Core_BAO_' . $name; $blocks[$block] = $baoString::getValues( $entityBlock, $microformat ); } return $blocks; diff --git a/CRM/Core/BAO/LocationType.php b/CRM/Core/BAO/LocationType.php index 390acc3459..36818e16b4 100644 --- a/CRM/Core/BAO/LocationType.php +++ b/CRM/Core/BAO/LocationType.php @@ -164,8 +164,8 @@ class CRM_Core_BAO_LocationType extends CRM_Core_DAO_LocationType { else { $name = ucfirst($key); } - require_once (str_replace('_', DIRECTORY_SEPARATOR, 'CRM_Core_DAO_' . $name) . ".php"); - eval('$object = new CRM_Core_DAO_' . $name . '( );'); + $baoString = 'CRM_Core_BAO_' . $name; + $object = new $baoString(); $object->location_type_id = $locationTypeId; $object->delete(); } diff --git a/CRM/Core/OptionValue.php b/CRM/Core/OptionValue.php index ebb2480676..89f1a72494 100644 --- a/CRM/Core/OptionValue.php +++ b/CRM/Core/OptionValue.php @@ -245,8 +245,7 @@ class CRM_Core_OptionValue { * @static */ static function optionExists($value, $daoName, $daoID, $optionGroupID, $fieldName = 'name') { - require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php"); - eval('$object = new ' . $daoName . '( );'); + $object = new $daoName(); $object->$fieldName = $value; $object->option_group_id = $optionGroupID; diff --git a/CRM/Core/Page/Basic.php b/CRM/Core/Page/Basic.php index bdb5b8d498..3c7a441f8c 100644 --- a/CRM/Core/Page/Basic.php +++ b/CRM/Core/Page/Basic.php @@ -213,8 +213,8 @@ abstract class CRM_Core_Page_Basic extends CRM_Core_Page { if ($action & CRM_Core_Action::ENABLE) { $action -= CRM_Core_Action::ENABLE; } - - eval('$object = new ' . $this->getBAOName() . '( );'); + $baoString = $this->getBAOName(); + $object = new $baoString(); $values = array(); diff --git a/CRM/Event/Form/Task/Badge.php b/CRM/Event/Form/Task/Badge.php index ba30dbb5cb..3c691cc94a 100644 --- a/CRM/Event/Form/Task/Badge.php +++ b/CRM/Event/Form/Task/Badge.php @@ -173,9 +173,7 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task { CRM_Core_Error::fatal('Event Badge code file: ' . $classFile . ' does not exist. Please verify your custom event badge settings in CiviCRM administrative panel.'); } - eval("\$eventBadgeClass = new $className( );"); - - + $eventBadgeClass = new $className(); $eventBadgeClass->run($rows); } } diff --git a/CRM/Event/Page/ParticipantListing.php b/CRM/Event/Page/ParticipantListing.php index d700054051..a72bcaa84b 100644 --- a/CRM/Event/Page/ParticipantListing.php +++ b/CRM/Event/Page/ParticipantListing.php @@ -90,7 +90,7 @@ class CRM_Event_Page_ParticipantListing extends CRM_Core_Page { CRM_Core_Error::fatal('Participant listing code file: ' . $classFile . ' does not exist. Please verify your custom particpant listing settings in CiviCRM administrative panel.'); } - eval("\$participantListingClass = new $className( );"); + $participantListingClass = new $className(); $participantListingClass->preProcess(); $participantListingClass->run(); diff --git a/CRM/Financial/BAO/FinancialTypeAccount.php b/CRM/Financial/BAO/FinancialTypeAccount.php index 8668084a1d..bc6b03f349 100644 --- a/CRM/Financial/BAO/FinancialTypeAccount.php +++ b/CRM/Financial/BAO/FinancialTypeAccount.php @@ -130,7 +130,8 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin ); foreach ($dependancy as $name) { - eval('$dao = new CRM_' . $name[0] . '_DAO_' . $name[1] . '();'); + $daoString = 'CRM_' . $name[0] . '_DAO_' . $name[1]; + $dao = new $daoString(); $dao->financial_type_id = $financialTypeId; if ($dao->find(true)) { $check = true; diff --git a/CRM/Logging/Differ.php b/CRM/Logging/Differ.php index 49a5452f3d..fe22bc9552 100644 --- a/CRM/Logging/Differ.php +++ b/CRM/Logging/Differ.php @@ -260,8 +260,7 @@ WHERE log_conn_id = %1 AND break; } - require_once str_replace('_', DIRECTORY_SEPARATOR, $daos[$table]) . '.php'; - eval("\$dao = new $daos[$table];"); + $dao = new $daos[$table]; foreach ($dao->fields() as $field) { $titles[$table][$field['name']] = CRM_Utils_Array::value('title', $field); diff --git a/CRM/Logging/Reverter.php b/CRM/Logging/Reverter.php index fb8d07c76a..708fbf9095 100644 --- a/CRM/Logging/Reverter.php +++ b/CRM/Logging/Reverter.php @@ -107,8 +107,7 @@ class CRM_Logging_Reverter { // DAO-based tables case in_array($table, array_keys($daos)): - require_once str_replace('_', DIRECTORY_SEPARATOR, $daos[$table]) . '.php'; - eval("\$dao = new {$daos[$table]};"); + $dao = new {$daos[$table]}; foreach ($row as $id => $changes) { $dao->id = $id; foreach ($changes as $field => $value) { diff --git a/CRM/Member/BAO/MembershipStatus.php b/CRM/Member/BAO/MembershipStatus.php index 7de3cf575a..a5d84b6f09 100644 --- a/CRM/Member/BAO/MembershipStatus.php +++ b/CRM/Member/BAO/MembershipStatus.php @@ -189,8 +189,8 @@ class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus { $dependancy = array('Membership', 'MembershipLog'); foreach ($dependancy as $name) { - require_once (str_replace('_', DIRECTORY_SEPARATOR, "CRM_Member_BAO_" . $name) . ".php"); - eval('$dao = new CRM_Member_BAO_' . $name . '();'); + $baoString = 'CRM_Member_BAO_' . $name; + $dao = new $baoString(); $dao->status_id = $membershipStatusId; if ($dao->find(TRUE)) { $check = TRUE; diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index c8218459d1..bb988ccbeb 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -141,8 +141,8 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { ); foreach ($dependancy as $name => $field) { - require_once (str_replace('_', DIRECTORY_SEPARATOR, "CRM_Member_DAO_" . $name) . ".php"); - eval('$dao = new CRM_Member_DAO_' . $name . '();'); + $baoString = 'CRM_Member_BAO_' . $name; + $dao = new $baoString(); $dao->$field = $membershipTypeId; if ($dao->find(TRUE)) { $check = TRUE; diff --git a/CRM/Upgrade/Incremental/Legacy.php b/CRM/Upgrade/Incremental/Legacy.php index e8e4cee8c4..944655034d 100644 --- a/CRM/Upgrade/Incremental/Legacy.php +++ b/CRM/Upgrade/Incremental/Legacy.php @@ -234,7 +234,7 @@ SELECT count( id ) as statusCount static function upgrade_2_2_alpha1($rev) { for ($stepID = 1; $stepID <= 4; $stepID++) { $formName = "CRM_Upgrade_TwoTwo_Form_Step{$stepID}"; - eval("\$form = new $formName( );"); + $form = new $formName(); $error = NULL; if (!$form->verifyPreDBState($error)) { @@ -277,7 +277,7 @@ SELECT count( id ) as statusCount */ static function upgrade_2_1_2($rev) { $formName = "CRM_Upgrade_TwoOne_Form_TwoOneTwo"; - eval("\$form = new $formName( '$rev' );"); + $form = new $formName($rev); $error = NULL; if (!$form->verifyPreDBState($error)) { diff --git a/CRM/Upgrade/TwoOne/Page/Upgrade.php b/CRM/Upgrade/TwoOne/Page/Upgrade.php index f0bdc5d67d..1a82fd8383 100644 --- a/CRM/Upgrade/TwoOne/Page/Upgrade.php +++ b/CRM/Upgrade/TwoOne/Page/Upgrade.php @@ -89,7 +89,7 @@ class CRM_Upgrade_TwoOne_Page_Upgrade extends CRM_Core_Page { function runForm($stepID) { $formName = "CRM_Upgrade_TwoOne_Form_Step{$stepID}"; - eval("\$form = new $formName( );"); + $form = new $formName(); $error = NULL; if (!$form->verifyPreDBState($error)) { @@ -115,7 +115,7 @@ class CRM_Upgrade_TwoOne_Page_Upgrade extends CRM_Core_Page { function runTwoOneTwo() { $formName = "CRM_Upgrade_TwoOne_Form_TwoOneTwo"; - eval("\$form = new $formName( '2.1.4' );"); + $form = new $formName( '2.1.4' ); $error = NULL; if (!$form->verifyPreDBState($error)) { diff --git a/CRM/Utils/Migrate/Export.php b/CRM/Utils/Migrate/Export.php index 1e13ba6fd6..804567b985 100644 --- a/CRM/Utils/Migrate/Export.php +++ b/CRM/Utils/Migrate/Export.php @@ -292,9 +292,7 @@ AND entity_id IS NULL } function fetch($groupName, $daoName, $sql = NULL, $map = NULL, $add = NULL) { - require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . '.php'); - - eval("\$dao = new $daoName( );"); + $dao = new $daoName(); if ($sql) { $dao->query($sql); } diff --git a/CRM/Utils/Migrate/ImportJSON.php b/CRM/Utils/Migrate/ImportJSON.php index ca2d528d54..650def7bb7 100644 --- a/CRM/Utils/Migrate/ImportJSON.php +++ b/CRM/Utils/Migrate/ImportJSON.php @@ -170,8 +170,7 @@ class CRM_Utils_Migrate_ImportJSON { } function restore(&$chunk, $daoName, $lookUpMapping = NULL) { - require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php"); - eval('$object = new ' . $daoName . '( );'); + $object = new $daoName(); $tableName = $object->__table; if (is_array($lookUpMapping)) { @@ -189,7 +188,7 @@ class CRM_Utils_Migrate_ImportJSON { $columns = $chunk[0]; foreach ($chunk as $key => $value) { if ($key) { - eval('$object = new ' . $daoName . '( );'); + $object = new $daoName(); foreach ($columns as $k => $column) { if ($column == 'id') { $childID = $value[$k]; diff --git a/CRM/Utils/Weight.php b/CRM/Utils/Weight.php index af35c1f909..525f791a62 100644 --- a/CRM/Utils/Weight.php +++ b/CRM/Utils/Weight.php @@ -88,8 +88,7 @@ class CRM_Utils_Weight { * @return bool */ static function delWeight($daoName, $fieldID, $fieldValues = NULL, $weightField = 'weight') { - require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php"); - eval('$object = new ' . $daoName . '( );'); + $object = new . $daoName(); $object->id = $fieldID; if (!$object->find(TRUE)) { return FALSE; @@ -412,9 +411,7 @@ class CRM_Utils_Weight { $src = CRM_Utils_Request::retrieve('src', 'Integer', CRM_Core_DAO::$_nullObject); $dst = CRM_Utils_Request::retrieve('dst', 'Integer', CRM_Core_DAO::$_nullObject); $dir = CRM_Utils_Request::retrieve('dir', 'String', CRM_Core_DAO::$_nullObject); - - require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php"); - eval('$object = new ' . $daoName . '( );'); + $object = new $daoName(); $srcWeight = CRM_Core_DAO::getFieldValue($daoName, $src, 'weight', $idName); $dstWeight = CRM_Core_DAO::getFieldValue($daoName, $dst, 'weight', $idName); if ($srcWeight == $dstWeight) { diff --git a/tests/phpunit/CiviTest/CiviDBAssert.php b/tests/phpunit/CiviTest/CiviDBAssert.php index d464dafb2b..261f3a9053 100644 --- a/tests/phpunit/CiviTest/CiviDBAssert.php +++ b/tests/phpunit/CiviTest/CiviDBAssert.php @@ -51,8 +51,7 @@ class CiviDBAssert { $testCase->fail('ID not populated. Please fix your assertDBState usage!!!'); } - require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php"); - eval('$object = new ' . $daoName . '( );'); + $object = new $daoName(); $object->id = $id; $verifiedCount = 0; diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 1b8304330c..d15dd43720 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -429,8 +429,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $this->fail('ID not populated. Please fix your assertDBState usage!!!'); } - require_once (str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php"); - eval('$object = new ' . $daoName . '( );'); + $object = new $daoName(); $object->id = $id; $verifiedCount = 0; -- 2.25.1