本文整理汇总了PHP中Functional\Exceptions\InvalidArgumentException::assertMethodName方法的典型用法代码示例。如果您正苦于以下问题:PHP InvalidArgumentException::assertMethodName方法的具体用法?PHP InvalidArgumentException::assertMethodName怎么用?PHP InvalidArgumentException::assertMethodName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Functional\Exceptions\InvalidArgumentException
的用法示例。
在下文中一共展示了InvalidArgumentException::assertMethodName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: invoker
/**
* Returns a function that invokes method `$method` with arguments `$methodArguments` on the object
*
* @param string $methodName
* @param array $arguments
* @return callable
*/
function invoker($methodName, array $arguments = [])
{
InvalidArgumentException::assertMethodName($methodName, __FUNCTION__, 1);
return static function ($object) use($methodName, $arguments) {
return $object->{$methodName}(...$arguments);
};
}
示例2: partial_method
/**
* Returns a function that expects an object as the first param and tries to invoke the given method on it
*
* @param string $methodName
* @param array $arguments
* @param mixed $defaultValue
* @return callable
*/
function partial_method($methodName, array $arguments = [], $defaultValue = null)
{
InvalidArgumentException::assertMethodName($methodName, __FUNCTION__, 1);
return function ($object) use($methodName, $arguments, $defaultValue) {
if (!is_callable([$object, $methodName])) {
return $defaultValue;
}
return $object->{$methodName}(...$arguments);
};
}
示例3: invoke_first
/**
* Calls the method named by $methodName on first value in the collection. Any extra arguments passed to invoke will be
* forwarded on to the method invocation.
*
* @param Traversable|array $collection
* @param string $methodName
* @param array $arguments
* @return array
*/
function invoke_first($collection, $methodName, array $arguments = [])
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
InvalidArgumentException::assertMethodName($methodName, __FUNCTION__, 2);
foreach ($collection as $element) {
$callback = [$element, $methodName];
if (is_callable($callback)) {
return $callback(...$arguments);
}
}
return null;
}
示例4: invoke
/**
* Calls the method named by $methodName on each value in the collection. Any extra arguments passed to invoke will be
* forwarded on to the method invocation.
*
* @param Traversable|array $collection
* @param string $methodName
* @param array $arguments
* @return array
*/
function invoke($collection, $methodName, array $arguments = [])
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
InvalidArgumentException::assertMethodName($methodName, __FUNCTION__, 2);
$aggregation = [];
foreach ($collection as $index => $element) {
$value = null;
$callback = [$element, $methodName];
if (is_callable($callback)) {
$value = $callback(...$arguments);
}
$aggregation[$index] = $value;
}
return $aggregation;
}
示例5: invoke_last
/**
* Calls the method named by $methodName on last value in the collection. Any extra arguments passed to invoke will be
* forwarded on to the method invocation.
*
* @param Traversable|array $collection
* @param string $methodName
* @param array $arguments
* @return array
*/
function invoke_last($collection, $methodName, array $arguments = array())
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
InvalidArgumentException::assertMethodName($methodName, __FUNCTION__, 2);
$lastCallback = null;
foreach ($collection as $element) {
$callback = array($element, $methodName);
if (is_callable($callback)) {
$lastCallback = $callback;
}
}
if (!$lastCallback) {
return null;
}
return call_user_func_array($lastCallback, $arguments);
}