Skip to content

Commit

Permalink
Fixed the create_function deprecation. (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickprent authored and nicoschoenmaker committed Apr 10, 2018
1 parent 05e3f8e commit 6596bc8
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 56 deletions.
10 changes: 7 additions & 3 deletions lib/cache/sfMemcacheCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <[email protected]>
*
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down Expand Up @@ -203,8 +203,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
10 changes: 8 additions & 2 deletions lib/command/sfCommandApplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <[email protected]>
*
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down Expand Up @@ -564,7 +564,13 @@ 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
8 changes: 6 additions & 2 deletions lib/config/sfConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ static public function replaceConstants($value)
{
if (is_array($value))
{
array_walk_recursive($value, create_function('&$value', '$value = sfToolkit::replaceConstants($value);'));
array_walk_recursive($value, function (&$value) {
$value = sfToolkit::replaceConstants($value);
});
}
else
{
Expand All @@ -96,7 +98,9 @@ static public function replacePath($path)
{
if (is_array($path))
{
array_walk_recursive($path, create_function('&$path', '$path = sfConfigHandler::replacePath($path);'));
array_walk_recursive($path, function (&$path) {
$path = sfConfigHandler::replacePath($path);
});
}
else
{
Expand Down
49 changes: 23 additions & 26 deletions lib/helper/TextHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,34 +247,31 @@ function _auto_link_urls($text, $href_options = array(), $truncate = false, $tru
{
$href_options = _tag_options($href_options);

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

if ($truncate)
{
$callback_function .= '
else if (strlen($matches[2].$matches[3]) > '.$truncate_len.')
$callback_function = function ($matches) use ($truncate, $truncate_len, $href_options, $pad) {
if (preg_match("/<a\s/i", $matches[1]))
{
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];
return $matches[0];
}
';
}

$callback_function .= '
else
{
return $matches[1].\'<a href="\'.($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3].\'"'.$href_options.'>\'.$matches[2].$matches[3].\'</a>\'.$matches[4];
}
';
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 preg_replace_callback(
SF_AUTO_LINK_RE,
create_function('$matches', $callback_function),
$text
return preg_replace_callback(
SF_AUTO_LINK_RE,
$callback_function,
$text
);
}

Expand All @@ -286,7 +283,7 @@ function _auto_link_email_addresses($text)
// Taken from http://snippets.dzone.com/posts/show/6156
return preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $text);

// Removed since it destroys already linked emails
// Removed since it destroys already linked emails
// Example: <a href="mailto:[email protected]">bar</a> gets <a href="mailto:[email protected]">bar</a> gets <a href="mailto:<a href="mailto:[email protected]">bar</a>
//return preg_replace('/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/', '<a href="mailto:\\1">\\1</a>', $text);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ protected function execute($arguments = array(), $options = array())
{
if (!$options['no-confirmation'] && !$this->askConfirmation(array_merge(
array('The following '.$modelName.' files will be deleted:', ''),
array_map(create_function('$v', 'return \' - \'.sfDebug::shortenFilePath($v);'), $files),
array_map(function ($v) {
return ' - '.sfDebug::shortenFilePath($v);
}, $files),
array('', 'Continue? (y/N)')
), 'QUESTION_LARGE', false))
{
Expand All @@ -100,10 +102,10 @@ protected function execute($arguments = array(), $options = array())

/**
* Converts an array of values to a regular expression pattern fragment.
*
*
* @param array $values An array of values for the pattern
* @param string $delimiter The regular expression delimiter
*
*
* @return string A regular expression fragment
*/
protected function valuesToRegex($values, $delimiter = '/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ protected function execute($arguments = array(), $options = array())
&&
!$this->askConfirmation(array_merge(
array(sprintf('This command will remove all data in the following "%s" connection(s):', $environment), ''),
array_map(create_function('$v', 'return \' - \'.$v;'), array_keys($databases)),
array_map(function ($v) {
return ' - '.$v;
}, array_keys($databases)),
array('', 'Are you sure you want to proceed? (y/N)')
), 'QUESTION_LARGE', false)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ protected function execute($arguments = array(), $options = array())
{
$this->logBlock(array_merge(
array('The following errors occurred:', ''),
array_map(create_function('$e', 'return \' - \'.$e->getMessage();'), $migration->getErrors())
array_map(function ($e) {
return ' - '.$e->getMessage();
}, $migration->getErrors())
), 'ERROR_LARGE');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ static protected function dumpArray($value)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,9 @@ public function getLimitSubquery()
foreach ($e as $f) {
if ($f == 0 || $f % 2 == 0) {
$partOriginal = str_replace(',', '', trim($f));
$callback = create_function('$e', 'return trim($e, \'[]`"\');');
$callback = function ($e) {
return trim($e, '[]`"');
};
$part = trim(implode('.', array_map($callback, explode('.', $partOriginal))));

if (strpos($part, '.') === false) {
Expand Down
10 changes: 7 additions & 3 deletions lib/routing/sfRoute.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ protected function tokenize()
throw new InvalidArgumentException(sprintf('Unable to parse "%s" route near "%s".', $this->pattern, $buffer));
}
}

// check for suffix
if ($this->suffix)
{
Expand Down Expand Up @@ -691,7 +691,9 @@ protected function initializeOptions()
'extra_parameters_as_query_string' => true,
), $this->getDefaultOptions(), $this->options);

$preg_quote_hash = create_function('$a', 'return preg_quote($a, \'#\');');
$preg_quote_hash = function ($a) {
return preg_quote($a, '#');
};

// compute some regexes
$this->options['variable_prefix_regex'] = '(?:'.implode('|', array_map($preg_quote_hash, $this->options['variable_prefixes'])).')';
Expand All @@ -701,7 +703,9 @@ protected function initializeOptions()
$this->options['segment_separators_regex'] = '(?:'.implode('|', array_map($preg_quote_hash, $this->options['segment_separators'])).')';

// as of PHP 5.3.0, preg_quote automatically quotes dashes "-" (see http://bugs.php.net/bug.php?id=47229)
$preg_quote_hash_53 = create_function('$a', 'return str_replace(\'-\', \'\-\', preg_quote($a, \'#\'));');
$preg_quote_hash_53 = function ($a) {
return str_replace('-', '\-', preg_quote($a, '#'));
};
$this->options['variable_content_regex'] = '[^'.implode('',
array_map(version_compare(PHP_VERSION, '5.3.0RC4', '>=') ? $preg_quote_hash : $preg_quote_hash_53, $this->options['segment_separators'])
).']+';
Expand Down
12 changes: 7 additions & 5 deletions lib/task/project/sfProjectPermissionsTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
*
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down Expand Up @@ -72,18 +72,20 @@ protected function execute($arguments = array(), $options = array())
{
$this->logBlock(array_merge(
array('Permissions on the following file(s) could not be fixed:', ''),
array_map(create_function('$f', 'return \' - \'.sfDebug::shortenFilePath($f);'), $this->failed)
array_map(function ($f) {
return ' - '.sfDebug::shortenFilePath($f);
}, $this->failed)
), 'ERROR_LARGE');
}
}

/**
* Chmod and capture any failures.
*
*
* @param string $file
* @param integer $mode
* @param integer $umask
*
*
* @see sfFilesystem
*/
protected function chmod($file, $mode, $umask = 0000)
Expand All @@ -109,7 +111,7 @@ protected function chmod($file, $mode, $umask = 0000)

/**
* Captures those chmod commands that fail.
*
*
* @see http://www.php.net/set_error_handler
*/
public function handleError($no, $string, $file, $line, $context)
Expand Down
4 changes: 3 additions & 1 deletion lib/util/sfBrowserBase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,9 @@ 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
16 changes: 12 additions & 4 deletions lib/validator/sfValidatorErrorSchema.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,12 @@ 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 @@ -312,8 +316,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,
is_object($tokenLeft) && in_array(get_class($tokenLeft), array('sfValidatorFDToken', 'sfValidatorFDTokenFilter')) ? $tokenLeft->asPhp() : $tokenLeft,
is_object($tokenRight) && 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
4 changes: 3 additions & 1 deletion lib/yaml/sfYamlInline.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ static protected function dumpArray($value)
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)
Expand Down

0 comments on commit 6596bc8

Please sign in to comment.