当前位置: 首页>>代码示例>>PHP>>正文


PHP Exceptions\InvalidArgumentException类代码示例

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


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


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