Skip to content

Commit

Permalink
replaced deprecated create_function
Browse files Browse the repository at this point in the history
  • Loading branch information
nutama committed Sep 7, 2021
1 parent daf2a61 commit 20b53d9
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 35 deletions.
8 changes: 6 additions & 2 deletions lib/cache/sfMemcacheCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ public function removePattern($pattern)
*/
public function getMany($keys)
{
$values = array();
foreach ($this->memcache->get(array_map(create_function('$k', 'return "'.$this->getOption('prefix').'".$k;'), $keys)) as $key => $value)
$values = array();
$prefixed_keys = array_map(function ($key) {
return $this->getOption('prefix') . $key;
}, $keys);

foreach ($this->memcache->get($prefixed_keys) as $key => $value)
{
$values[str_replace($this->getOption('prefix'), '', $key)] = $value;
}
Expand Down
7 changes: 6 additions & 1 deletion lib/command/sfCommandApplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,12 @@ protected function fixCgi()
}

// close the streams on script termination
register_shutdown_function(create_function('', 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;'));
register_shutdown_function(function () {
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
return true;
});
}

/**
Expand Down
13 changes: 9 additions & 4 deletions lib/helper/ObjectAdminHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function object_admin_double_list($object, $method, $options = array(), $callbac
$label_assoc = __(isset($options['associated_label']) ? $options['associated_label'] : 'Associated');

// get the lists of objects
list($all_objects, $objects_associated, $associated_ids) = _get_object_list($object, $method, $options, $callback);
[$all_objects, $objects_associated, $associated_ids] = _get_object_list($object, $method, $options, $callback);

$objects_unassociated = array();
foreach ($all_objects as $object)
Expand Down Expand Up @@ -126,7 +126,7 @@ function object_admin_select_list($object, $method, $options = array(), $callbac
}

// get the lists of objects
list($objects, $objects_associated, $ids) = _get_object_list($object, $method, $options, $callback);
[$objects, $objects_associated, $ids] = _get_object_list($object, $method, $options, $callback);
// remove non html option
unset($options['through_class']);
// override field name
Expand All @@ -141,7 +141,7 @@ function object_admin_check_list($object, $method, $options = array(), $callback
$options = _parse_attributes($options);

// get the lists of objects
list($objects, $objects_associated, $assoc_ids) = _get_object_list($object, $method, $options, $callback);
[$objects, $objects_associated, $assoc_ids] = _get_object_list($object, $method, $options, $callback);

// override field name
unset($options['control_name']);
Expand Down Expand Up @@ -191,7 +191,12 @@ function _get_propel_object_list($object, $method, $options)

$objects = sfPropelManyToMany::getAllObjects($object, $through_class);
$objects_associated = sfPropelManyToMany::getRelatedObjects($object, $through_class);
$ids = array_map(create_function('$o', 'return $o->getPrimaryKey();'), $objects_associated);
$ids = array_map(
function($o) {
return $o->getPrimaryKey();
},
$objects_associated
);

return array($objects, $objects_associated, $ids);
}
Expand Down
33 changes: 15 additions & 18 deletions lib/helper/TextHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,35 +236,32 @@ function _auto_link_urls($text, $href_options = array(), $truncate = false, $tru
{
$href_options = _tag_options($href_options);

$callback_function = '
$callback_function = function ($matches) use ($truncate, $truncate_len, $href_options, $pad) {
if (preg_match("/<a\s/i", $matches[1]))
{
return $matches[0];
}
';

if ($truncate)
{
$callback_function .= '
else if (strlen($matches[2].$matches[3]) > '.$truncate_len.')
{
return $matches[1].\'<a href="\'.($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3].\'"'.$href_options.'>\'.substr($matches[2].$matches[3], 0, '.$truncate_len.').\''.$pad.'</a>\'.$matches[4];
}
';
}

$callback_function .= '
else if ($truncate && strlen($matches[2].$matches[3]) > $truncate_len)
{
return $matches[1].'<a href="' .($matches[2] === 'www.'
? 'http://www.'
: $matches[2]
).$matches[3].'"'.$href_options.'>'.substr($matches[2].$matches[3], 0, $truncate_len).$pad.'</a>'.$matches[4];
}
else
{
return $matches[1].\'<a href="\'.($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3].\'"'.$href_options.'>\'.$matches[2].$matches[3].\'</a>\'.$matches[4];
return $matches[1].'<a href="'.($matches[2] === 'www.'
? 'http://www.'
: $matches[2]
).$matches[3].'"'.$href_options.'>'.$matches[2].$matches[3].'</a>'.$matches[4];
}
';
};

return preg_replace_callback(
SF_AUTO_LINK_RE,
create_function('$matches', $callback_function),
$callback_function,
$text
);
);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions lib/routing/sfPatternRouting.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public function generate($name, $params = array(), $querydiv = '/', $divider = '
$tparams = $this->mergeArrays($defaults, $params);

// all params must be given
if ($diff = array_diff_key($variables, array_filter($tparams, create_function('$v', 'return !is_null($v);'))))
if ($diff = array_diff_key($variables, array_filter($tparams, function($v) { return !is_null($v); })))
{
throw new InvalidArgumentException(sprintf('The "%s" route has some missing mandatory parameters (%s).', $name, implode(', ', $diff)));
}
Expand Down Expand Up @@ -567,7 +567,12 @@ public function generate($name, $params = array(), $querydiv = '/', $divider = '
$realUrl = $url;

$tmp = $variables;
uasort($tmp, create_function('$a, $b', 'return strlen($a) < strlen($b);'));
uasort(
$tmp,
function($a, $b) {
return strlen($a) < strlen($b);
}
);
foreach ($tmp as $variable => $value)
{
$realUrl = str_replace($value, urlencode($tparams[$variable]), $realUrl);
Expand Down
9 changes: 7 additions & 2 deletions lib/util/sfBrowser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function call($uri, $method = 'get', $parameters = array(), $changeStack
$this->stackPosition = count($this->stack) - 1;
}

list($path, $query_string) = false !== ($pos = strpos($uri, '?')) ? array(substr($uri, 0, $pos), substr($uri, $pos + 1)) : array($uri, '');
[$path, $query_string] = false !== ($pos = strpos($uri, '?')) ? array(substr($uri, 0, $pos), substr($uri, $pos + 1)) : array($uri, '');
$query_string = html_entity_decode($query_string);

// remove anchor
Expand Down Expand Up @@ -686,7 +686,12 @@ protected function parseArgumentAsArray($name, $value, &$vars)
if (false !== $pos = strpos($name, '['))
{
$var = &$vars;
$tmps = array_filter(preg_split('/(\[ | \[\] | \])/x', $name), create_function('$s', 'return $s !== "";'));
$tmps = array_filter(
preg_split('/(\[ | \[\] | \])/x', $name),
function($s) {
return $s !== "";
}
);
foreach ($tmps as $tmp)
{
$var = &$var[$tmp];
Expand Down
20 changes: 16 additions & 4 deletions lib/validator/sfValidatorErrorSchema.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,16 @@ public function offsetUnset($offset)
protected function updateCode()
{
$this->code = implode(' ', array_merge(
array_map(create_function('$e', 'return $e->getCode();'), $this->globalErrors),
array_map(create_function('$n,$e', 'return $n.\' [\'.$e->getCode().\']\';'), array_keys($this->namedErrors), array_values($this->namedErrors))
array_map(
function ($e) {
return $e->getCode();
}, $this->globalErrors
),
array_map(
function ($n, $e) {
return $n.' ['.$e->getCode().']';
}, array_keys($this->namedErrors), array_values($this->namedErrors)
)
));
}

Expand All @@ -304,8 +312,12 @@ protected function updateCode()
protected function updateMessage()
{
$this->message = implode(' ', array_merge(
array_map(create_function('$e', 'return $e->getMessage();'), $this->globalErrors),
array_map(create_function('$n,$e', 'return $n.\' [\'.$e->getMessage().\']\';'), array_keys($this->namedErrors), array_values($this->namedErrors))
array_map(function ($e) {
return $e->getMessage();
}, $this->globalErrors),
array_map(function ($n, $e) {
return $n.' ['.$e->getMessage().']';
}, array_keys($this->namedErrors), array_values($this->namedErrors))
));
}

Expand Down
8 changes: 6 additions & 2 deletions lib/validator/sfValidatorFromDescription.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ public function __construct($class, $arguments = array())

public function asPhp()
{
return sprintf('new %s(%s)', $this->class, implode(', ', array_map(create_function('$a', 'return var_export($a, true);'), $this->arguments)));
return sprintf('new %s(%s)', $this->class, implode(', ', array_map(function ($a) {
return var_export($a, true);
}, $this->arguments)));
}

public function getValidator()
Expand Down Expand Up @@ -353,7 +355,9 @@ public function asPhp($tokenLeft, $tokenRight)
$this->class,
in_array(get_class($tokenLeft), array('sfValidatorFDToken', 'sfValidatorFDTokenFilter')) ? $tokenLeft->asPhp() : $tokenLeft,
in_array(get_class($tokenRight), array('sfValidatorFDToken', 'sfValidatorFDTokenFilter')) ? $tokenRight->asPhp() : $tokenRight,
implode(', ', array_map(create_function('$a', 'return var_export($a, true);'), $this->arguments))
implode(', ', array_map(function ($a) {
return var_export($a, true);
}, $this->arguments))
);
}

Expand Down

0 comments on commit 20b53d9

Please sign in to comment.