@@ 19-36 (lines=18) @@ | ||
16 | * @param iterable $iterable |
|
17 | * @return static |
|
18 | */ |
|
19 | public static function from($iterable) |
|
20 | { |
|
21 | if ($iterable instanceof \Iterator) { |
|
22 | return new static(iterator_to_array($iterable)); |
|
23 | } |
|
24 | if (is_array($iterable) |
|
25 | || $iterable instanceof \IteratorAggregate |
|
26 | ) { |
|
27 | return new static($iterable); |
|
28 | } |
|
29 | ||
30 | throw new \InvalidArgumentException( |
|
31 | sprintf( |
|
32 | 'Argument 1 must be an instance of Traversable or an array, %s given', |
|
33 | is_object($iterable) ? get_class($iterable) : gettype($iterable) |
|
34 | ) |
|
35 | ); |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * Alias for getArrayCopy() |
@@ 24-41 (lines=18) @@ | ||
21 | * |
|
22 | * @return self |
|
23 | */ |
|
24 | public static function from($iterable) |
|
25 | { |
|
26 | if (is_array($iterable) |
|
27 | || $iterable instanceof \IteratorAggregate |
|
28 | ) { |
|
29 | return new static(new \ArrayIterator($iterable)); |
|
30 | } |
|
31 | if ($iterable instanceof \Iterator) { |
|
32 | return new static($iterable); |
|
33 | } |
|
34 | ||
35 | throw new \InvalidArgumentException( |
|
36 | sprintf( |
|
37 | 'Argument 1 must be an instance of Traversable or an array, %s given', |
|
38 | is_object($iterable) ? get_class($iterable) : gettype($iterable) |
|
39 | ) |
|
40 | ); |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * @inheritDoc |