• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Exceptions\InvalidArgumentException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Functional\Exceptions\InvalidArgumentException的典型用法代码示例。如果您正苦于以下问题:PHP InvalidArgumentException类的具体用法?PHP InvalidArgumentException怎么用?PHP InvalidArgumentException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了InvalidArgumentException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: sequence_exponential

/**
 * Returns an infinite, traversable sequence that exponentially grows by given percentage
 *
 * @param integer $start
 * @param integer $percentage Integer between 1 and 100
 * @return ExponentialSequence
 * @throws InvalidArgumentException
 */
function sequence_exponential($start, $percentage)
{
    InvalidArgumentException::assertIntegerGreaterThanOrEqual($start, 1, __METHOD__, 1);
    InvalidArgumentException::assertIntegerGreaterThanOrEqual($percentage, 1, __METHOD__, 2);
    InvalidArgumentException::assertIntegerLessThanOrEqual($percentage, 100, __METHOD__, 2);
    return new ExponentialSequence($start, $percentage);
}
开发者ID:lstrojny,项目名称:functional-php,代码行数:15,代码来源:SequenceExponential.php


示例2: retry

/**
 * Retry a callback until the number of retries are reached or the callback does no longer throw an exception
 *
 * @param callable $callback
 * @param integer $retries
 * @param Traversable|null $delaySequence Default: no delay between calls
 * @throws Exception Any exception thrown by the callback
 * @throws InvalidArgumentException
 * @return mixed Return value of the function
 */
function retry(callable $callback, $retries, Traversable $delaySequence = null)
{
    InvalidArgumentException::assertIntegerGreaterThanOrEqual($retries, 1, __FUNCTION__, 2);
    if ($delaySequence) {
        $delays = new AppendIterator();
        $delays->append(new InfiniteIterator($delaySequence));
        $delays->append(new InfiniteIterator(new ArrayIterator([0])));
        $delays = new LimitIterator($delays, $retries);
    } else {
        $delays = array_fill_keys(range(0, $retries), 0);
    }
    $retry = 0;
    foreach ($delays as $delay) {
        try {
            return $callback($retry, $delay);
        } catch (Exception $e) {
            if ($retry === $retries - 1) {
                throw $e;
            }
        }
        if ($delay > 0) {
            usleep($delay);
        }
        ++$retry;
    }
}
开发者ID:tdomarkas,项目名称:functional-php,代码行数:36,代码来源:Retry.php


示例3: zip

/**
 * Recombines arrays by index and applies a callback optionally
 *
 * @param $args array|Traversable $collection One or more callbacks
 * @return array
 */
function zip($arg)
{
    $args = func_get_args();
    $callback = null;
    if (is_callable(end($args))) {
        $callback = array_pop($args);
    }
    foreach ($args as $position => $arg) {
        InvalidArgumentException::assertCollection($arg, __FUNCTION__, $position + 1);
    }
    $result = [];
    foreach ((array) reset($args) as $index => $value) {
        $zipped = [];
        foreach ($args as $arg) {
            $zipped[] = isset($arg[$index]) ? $arg[$index] : null;
        }
        if ($callback !== null) {
            /** @var callable $callback */
            //            $zipped = $callback(...$zipped);
            $zipped = call_user_func_array($callback, $zipped);
        }
        $result[] = $zipped;
    }
    return $result;
}
开发者ID:yarec,项目名称:functional-php,代码行数:31,代码来源:Zip.php


示例4: __construct

 public function __construct($start, $amount)
 {
     InvalidArgumentException::assertIntegerGreaterThanOrEqual($start, 0, __METHOD__, 1);
     InvalidArgumentException::assertInteger($amount, __METHOD__, 2);
     $this->start = $start;
     $this->amount = $amount;
 }
开发者ID:lstrojny,项目名称:functional-php,代码行数:7,代码来源:LinearSequence.php


示例5: 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);
    };
}
开发者ID:lstrojny,项目名称:functional-php,代码行数:14,代码来源:Invoker.php


示例6: zip_all

/**
 * Recombines arrays by index (column) and applies a callback optionally
 *
 * When the input collections are different lengths the resulting collections
 * will all have the length which is required to fit all the keys
 *
 * @param $args array|Traversable $collection One or more callbacks
 * @return array
 */
function zip_all(...$args)
{
    /** @var callable|null $callback */
    $callback = null;
    if (is_callable(end($args))) {
        $callback = array_pop($args);
    }
    foreach ($args as $position => $arg) {
        InvalidArgumentException::assertCollection($arg, __FUNCTION__, $position + 1);
    }
    $resultKeys = [];
    foreach ($args as $arg) {
        foreach ($arg as $index => $value) {
            $resultKeys[] = $index;
        }
    }
    $resultKeys = array_unique($resultKeys);
    $result = [];
    foreach ($resultKeys as $key) {
        $zipped = [];
        foreach ($args as $arg) {
            $zipped[] = isset($arg[$key]) ? $arg[$key] : null;
        }
        $result[$key] = $zipped;
    }
    if ($callback !== null) {
        foreach ($result as $key => $column) {
            $result[$key] = $callback(...$column);
        }
    }
    return $result;
}
开发者ID:lstrojny,项目名称:functional-php,代码行数:41,代码来源:ZipAll.php


示例7: each

/**
 * Iterates over a collection of elements, yielding each in turn to a callback function. Each invocation of $callback
 * is called with three arguments: (element, index, collection)
 *
 * @param Traversable|array $collection
 * @param callable $callback
 * @return null
 */
function each($collection, callable $callback)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    foreach ($collection as $index => $element) {
        $callback($element, $index, $collection);
    }
}
开发者ID:tdomarkas,项目名称:functional-php,代码行数:15,代码来源:Each.php


示例8: memoize

/**
 * Memoizes callbacks and returns their value instead of calling them
 *
 * @param callable $callback Callable closure or function
 * @param array $arguments Arguments
 * @param array|string $key Optional memoize key to override the auto calculated hash
 * @return mixed
 */
function memoize($callback, array $arguments = array(), $key = null)
{
    static $storage = array();
    if ($callback === null) {
        $storage = array();
        return null;
    }
    InvalidArgumentException::assertCallback($callback, __FUNCTION__, 1);
    static $keyGenerator = null;
    if (!$keyGenerator) {
        $keyGenerator = function ($value) use(&$keyGenerator) {
            $type = gettype($value);
            if ($type === 'array') {
                $key = join(':', map($value, $keyGenerator));
            } elseif ($type === 'object') {
                $key = get_class($value) . ':' . spl_object_hash($value);
            } else {
                $key = (string) $value;
            }
            return $key;
        };
    }
    if ($key === null) {
        $key = $keyGenerator(array_merge(array($callback), $arguments));
    } else {
        $key = $keyGenerator($key);
    }
    if (!isset($storage[$key]) && !array_key_exists($key, $storage)) {
        $storage[$key] = call_user_func_array($callback, $arguments);
    }
    return $storage[$key];
}
开发者ID:RightThisMinute,项目名称:responsive-images-php,代码行数:40,代码来源:Memoize.php


示例9: each

/**
 * Iterates over a collection of elements, yielding each in turn to a callback function. Each invocation of $callback
 * is called with three arguments: (element, index, collection)
 *
 * @param Traversable|array $collection
 * @param callable $callback
 * @return null
 */
function each($collection, $callback)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    InvalidArgumentException::assertCallback($callback, __FUNCTION__, 2);
    foreach ($collection as $index => $element) {
        call_user_func($callback, $element, $index, $collection);
    }
}
开发者ID:RightThisMinute,项目名称:responsive-images-php,代码行数:16,代码来源:Each.php


示例10: testHashIterator

 public function testHashIterator()
 {
     $flat = flat_map(new ArrayIterator(['ka' => 'a', 'kb' => ['b'], 'kc' => ['C' => 'c'], 'kd' => [['d']], 'ke' => null, null]), function ($v, $k, $collection) {
         InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3);
         return $v;
     });
     $this->assertSame(['a', 'b', 'c', ['d']], $flat);
 }
开发者ID:tdomarkas,项目名称:functional-php,代码行数:8,代码来源:FlatMapTest.php


示例11: head

/**
 * Alias for Functional\first
 *
 * @param Traversable|array $collection
 * @param callable $callback
 * @return mixed
 */
function head($collection, $callback = null)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    if ($callback !== null) {
        InvalidArgumentException::assertCallback($callback, __FUNCTION__, 2);
    }
    return first($collection, $callback);
}
开发者ID:RightThisMinute,项目名称:responsive-images-php,代码行数:15,代码来源:Head.php


示例12: reduce_left

/**
 * @param Traversable|array $collection
 * @param callable $callback
 * @param mixed $initial
 * @return array
 */
function reduce_left($collection, callable $callback, $initial = null)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    foreach ($collection as $index => $value) {
        $initial = $callback($value, $index, $collection, $initial);
    }
    return $initial;
}
开发者ID:tdomarkas,项目名称:functional-php,代码行数:14,代码来源:ReduceLeft.php


示例13: __construct

 public function __construct($start, $percentage)
 {
     InvalidArgumentException::assertIntegerGreaterThanOrEqual($start, 1, __METHOD__, 1);
     InvalidArgumentException::assertIntegerGreaterThanOrEqual($percentage, 1, __METHOD__, 2);
     InvalidArgumentException::assertIntegerLessThanOrEqual($percentage, 100, __METHOD__, 2);
     $this->start = $start;
     $this->percentage = $percentage;
 }
开发者ID:lstrojny,项目名称:functional-php,代码行数:8,代码来源:ExponentialSequence.php


示例14: testDuplicateKeys

 public function testDuplicateKeys()
 {
     $fn = function ($v, $k, $collection) {
         InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3);
         return $k[0];
     };
     $this->assertSame(['k' => 'val2'], reindex($this->hash, $fn));
 }
开发者ID:lstrojny,项目名称:functional-php,代码行数:8,代码来源:ReindexTest.php


示例15: map

/**
 * Produces a new array of elements by mapping each element in collection through a transformation function (callback).
 * Callback arguments will be element, index, collection
 *
 * @param Traversable|array $collection
 * @param callable $callback
 * @return array
 */
function map($collection, callable $callback)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    $aggregation = [];
    foreach ($collection as $index => $element) {
        $aggregation[$index] = $callback($element, $index, $collection);
    }
    return $aggregation;
}
开发者ID:lstrojny,项目名称:functional-php,代码行数:17,代码来源:Map.php


示例16: none

/**
 * Returns true if all of the elements in the collection pass the callback falsy test. Opposite of Functional\all().
 * Callback arguments will be element, index, collection.
 *
 * @param Traversable|array $collection
 * @param callable $callback
 * @return bool
 */
function none($collection, callable $callback)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    foreach ($collection as $index => $element) {
        if ($callback($element, $index, $collection)) {
            return false;
        }
    }
    return true;
}
开发者ID:lstrojny,项目名称:functional-php,代码行数:18,代码来源:None.php


示例17: 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);
    };
}
开发者ID:tdomarkas,项目名称:functional-php,代码行数:18,代码来源:PartialMethod.php


示例18: flatten

/**
 * Takes a nested combination of collections and returns their contents as a single, flat array.
 * Does not preserve indexs.
 *
 * @param Traversable|array $collection
 * @return array
 */
function flatten($collection)
{
    Exceptions\InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($collection));
    $result = array();
    foreach ($it as $val) {
        $result[] = $val;
    }
    return $result;
}
开发者ID:reeze,项目名称:functional-php,代码行数:17,代码来源:Flatten.php


示例19: partition

/**
 * Partitions a collection by callback result. The truthy partition is the first one
 * (array index "0"), the falsy the second one (array index "1")
 *
 * @param Traversable|array $collection
 * @param callable $callback
 * @return array
 */
function partition($collection, callable $callback)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    $partitions = [0 => [], 1 => []];
    foreach ($collection as $index => $element) {
        $partitionKey = $callback($element, $index, $collection) ? 0 : 1;
        $partitions[$partitionKey][$index] = $element;
    }
    return $partitions;
}
开发者ID:tdomarkas,项目名称:functional-php,代码行数:18,代码来源:Partition.php


示例20: map

/**
 * Produces a new array of elements by mapping each element in collection through a transformation function (callback).
 * Callback arguments will be element, index, collection
 *
 * @param Traversable|array $collection
 * @param callable $callback
 * @return array
 */
function map($collection, $callback)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    InvalidArgumentException::assertCallback($callback, __FUNCTION__, 2);
    $aggregation = array();
    foreach ($collection as $index => $element) {
        $aggregation[$index] = call_user_func($callback, $element, $index, $collection);
    }
    return $aggregation;
}
开发者ID:RightThisMinute,项目名称:responsive-images-php,代码行数:18,代码来源:Map.php



注:本文中的Functional\Exceptions\InvalidArgumentException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Filesystem\Folder类代码示例发布时间:2022-05-23
下一篇:
PHP models\User类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap