HHVM does not support variadic arguments with type hints. This is mostly not a big problem, because we can just drop the type hint, but for some reason PHPUnit adds a type hint of "array" when it creates mocks, so a class with a variadic method can't be mocked (at least in some cases). As such, I left alone all the classes that seem like someone might like to mock them, like Title and User. If anyone wants to mock them in the future, they'll have to switch back to func_get_args(). Some of the changes are definitely safe, like functions and test classes. In most cases, func_get_args() (and/or func_get_arg(), func_num_args() ) were only present because the code was written before we required PHP 5.6, and writing them as variadic functions is strictly superior. In some cases I left them alone, aside from HHVM compatibility: * Forwarding all arguments to another function. It's useful to keep func_get_args() here where we want to keep the list of expected arguments and their meanings in the function signature line for documentation purposes, but don't want to copy-paste a long line of argument names. * Handling deprecated calling conventions. * One or two miscellaneous cases where we're basically using the arguments individually but want to use them as an array as well for some reason. Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* Class that defers a slow string generation until the string is actually needed.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
*/
|
|
|
|
/**
|
|
* @since 1.25
|
|
* @deprecated since 1.31, use Message::listParam() instead
|
|
*/
|
|
class DeferredStringifier {
|
|
/** @var callable Callback used for result string generation */
|
|
private $callback;
|
|
|
|
/** @var array */
|
|
private $params;
|
|
|
|
/** @var string */
|
|
private $result;
|
|
|
|
/**
|
|
* @param callable $callback Callback that gets called by __toString
|
|
* @param mixed ...$params Parameters to the callback
|
|
*/
|
|
public function __construct( $callback, ...$params ) {
|
|
$this->callback = $callback;
|
|
$this->params = $params;
|
|
}
|
|
|
|
/**
|
|
* Get the string generated from the callback
|
|
*
|
|
* @return string
|
|
*/
|
|
public function __toString() {
|
|
if ( $this->result === null ) {
|
|
$this->result = call_user_func_array( $this->callback, $this->params );
|
|
}
|
|
return $this->result;
|
|
}
|
|
}
|