remove create_function usage

This commit is contained in:
Daniel Hensby 2017-11-30 18:08:48 +00:00
parent 2538f59ab7
commit 2aa1d8f2c4
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
9 changed files with 28 additions and 10 deletions

View File

@ -173,7 +173,9 @@ class LeftAndMainTest extends FunctionalTest {
$adminuser = $this->objFromFixture('Member', 'admin');
$securityonlyuser = $this->objFromFixture('Member', 'securityonlyuser');
$allcmssectionsuser = $this->objFromFixture('Member', 'allcmssectionsuser');
$allValsFn = create_function('$obj', 'return $obj->getValue();');
$allValsFn = function($obj) {
return $obj->getValue();
};
// anonymous user
$this->session()->inst_set('loggedInAs', null);

View File

@ -373,7 +373,9 @@ class RestfulService extends ViewableData implements Flushable {
if( preg_match('/([^:]+): (.+)/m', $field, $match) ) {
$match[1] = preg_replace_callback(
'/(?<=^|[\x09\x20\x2D])./',
create_function('$matches', 'return strtoupper($matches[0]);'),
function($matches) {
return strtoupper($matches[0]);
},
trim($match[1])
);
if( isset($headers[$match[1]]) ) {

View File

@ -948,7 +948,9 @@ abstract class Object {
*/
protected function createMethod($method, $code) {
self::$extra_methods[get_class($this)][strtolower($method)] = array (
'function' => create_function('$obj, $args', $code)
'function' => function($obj, $args) use ($code) {
eval($code);
}
);
}

View File

@ -1307,7 +1307,9 @@ class Installer extends InstallRequirements {
$locale = isset($_POST['locale']) ? addcslashes($_POST['locale'], "\'") : 'en_US';
$type = addcslashes($config['db']['type'], "\'");
$dbConfig = $config['db'][$type];
$dbConfig = array_map(create_function('$v', 'return addcslashes($v, "\\\'");'), $dbConfig);
$dbConfig = array_map(function($v) {
return addcslashes($v, "\\'");
}, $dbConfig);
if(!isset($dbConfig['path'])) $dbConfig['path'] = '';
if(!$dbConfig) {
echo "<p style=\"color: red\">Bad config submitted</p><pre>";

View File

@ -859,7 +859,9 @@ class Form extends RequestHandler {
$attrs = $this->getAttributes();
// Remove empty
$attrs = array_filter((array)$attrs, create_function('$v', 'return ($v || $v === 0);'));
$attrs = array_filter((array)$attrs, function($v) {
return ($v || $v === 0);
});
// Remove excluded
if($exclude) $attrs = array_diff_key($attrs, array_flip($exclude));

View File

@ -136,7 +136,9 @@ class ListboxField extends DropdownField {
public function setSource($source) {
if($source) {
$hasCommas = array_filter(array_keys($source),
create_function('$key', 'return strpos($key, ",") !== FALSE;'));
function($key) {
return strpos($key, ",") !== FALSE;
});
if($hasCommas) {
throw new InvalidArgumentException('No commas allowed in $source keys');
}

View File

@ -118,7 +118,9 @@ class HTMLText extends Text {
$doc = new DOMDocument();
// Catch warnings thrown by loadHTML and turn them into a failure boolean rather than a SilverStripe error
set_error_handler(create_function('$no, $str', 'throw new Exception("HTML Parse Error: ".$str);'), E_ALL);
set_error_handler(function($no, $str) {
throw new Exception("HTML Parse Error: " . $str);
}, E_ALL);
// Nonbreaking spaces get converted into weird characters, so strip them
$value = str_replace('&nbsp;', ' ', $this->RAW());
try {

View File

@ -728,7 +728,9 @@ class UploadFieldTest extends FunctionalTest {
// A bit too much coupling with GridField, but a full template overload would make things too complex
$parser = new CSSContentParser($response->getBody());
$items = $parser->getBySelector('.ss-gridfield-item');
$itemIDs = array_map(create_function('$el', 'return (int)$el["data-id"];'), $items);
$itemIDs = array_map(function($el) {
return (int)$el["data-id"];
}, $items);
$this->assertContains($file4->ID, $itemIDs, 'Contains file in assigned folder');
$this->assertContains($fileSubfolder->ID, $itemIDs, 'Contains file in subfolder');
}
@ -746,7 +748,9 @@ class UploadFieldTest extends FunctionalTest {
// A bit too much coupling with GridField, but a full template overload would make things too complex
$parser = new CSSContentParser($response->getBody());
$items = $parser->getBySelector('.ss-gridfield-item');
$itemIDs = array_map(create_function('$el', 'return (int)$el["data-id"];'), $items);
$itemIDs = array_map(function($el) {
return (int)$el["data-id"];
}, $items);
$this->assertContains($file4->ID, $itemIDs, 'Contains file in assigned folder');
$this->assertNotContains($fileSubfolder->ID, $itemIDs, 'Does not contain file in subfolder');
}

View File

@ -135,7 +135,7 @@ class sfYamlInline
if (
(1 == count($keys) && '0' == $keys[0])
||
(count($keys) > 1 && array_reduce($keys, create_function('$v,$w', 'return (integer) $v + $w;'), 0) == count($keys) * (count($keys) - 1) / 2))
(count($keys) > 1 && array_reduce($keys, function($v,$w) { return (integer) $v + $w;}, 0) == count($keys) * (count($keys) - 1) / 2))
{
$output = array();
foreach ($value as $val)