當前位置: 首頁>>代碼示例>>PHP>>正文


PHP InvalidArgumentException::assertCollection方法代碼示例

本文整理匯總了PHP中Functional\Exceptions\InvalidArgumentException::assertCollection方法的典型用法代碼示例。如果您正苦於以下問題:PHP InvalidArgumentException::assertCollection方法的具體用法?PHP InvalidArgumentException::assertCollection怎麽用?PHP InvalidArgumentException::assertCollection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Functional\Exceptions\InvalidArgumentException的用法示例。


在下文中一共展示了InvalidArgumentException::assertCollection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: 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

示例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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: contains

/**
 * Returns true if the collection contains the given value. If the third parameter is
 * true values will be compared in strict mode
 *
 * @param Traversable|array $collection
 * @param mixed $value
 * @param bool $strict
 * @return bool
 */
function contains($collection, $value, $strict = true)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    foreach ($collection as $element) {
        if ($value === $element || !$strict && $value == $element) {
            return true;
        }
    }
    return false;
}
開發者ID:lstrojny,項目名稱:functional-php,代碼行數:19,代碼來源:Contains.php

示例13: 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

示例14: 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

示例15: true

/**
 * Returns true if all elements of the collection are strictly true
 *
 * @param Traversable|array $collection
 * @return bool
 */
function true($collection)
{
    InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
    foreach ($collection as $value) {
        if ($value !== true) {
            return false;
        }
    }
    return true;
}
開發者ID:tdomarkas,項目名稱:functional-php,代碼行數:16,代碼來源:True.php


注:本文中的Functional\Exceptions\InvalidArgumentException::assertCollection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。