aminyazdanpanah /
PHP-FFmpeg-video-streaming
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This file is part of the PHP-FFmpeg-video-streaming package. |
||
| 5 | * |
||
| 6 | * (c) Amin Yazdanpanah <[email protected]> |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | */ |
||
| 11 | |||
| 12 | |||
| 13 | namespace Streaming; |
||
| 14 | |||
| 15 | |||
| 16 | class RepsCollection implements \Countable, \IteratorAggregate |
||
| 17 | { |
||
| 18 | /** @return array */ |
||
| 19 | private $representations = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * RepsCollection constructor. |
||
| 23 | * @param array $representations |
||
| 24 | */ |
||
| 25 | public function __construct(array $representations = []) |
||
| 26 | { |
||
| 27 | array_walk($representations, [$this, 'add']); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @return null|Representation |
||
| 32 | */ |
||
| 33 | public function first() |
||
| 34 | { |
||
| 35 | return reset($this->representations) ?: null; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @return null|Representation |
||
| 40 | */ |
||
| 41 | public function end() |
||
| 42 | { |
||
| 43 | return end($this->representations) ?: null; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param RepresentationInterface $representation |
||
| 48 | * @return RepsCollection |
||
| 49 | */ |
||
| 50 | public function add(RepresentationInterface $representation) |
||
| 51 | { |
||
| 52 | array_push($this->representations, $representation); |
||
| 53 | return $this; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | public function all(): array |
||
| 60 | { |
||
| 61 | return $this->representations; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | public function keys(): array |
||
| 68 | { |
||
| 69 | return array_keys($this->representations); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param $key |
||
| 74 | * @param null $default |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 75 | * @return Representation | mixed |
||
| 76 | */ |
||
| 77 | public function get($key, $default = null) |
||
| 78 | { |
||
| 79 | return $this->representations[$key] ?? $default; |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param callable $func |
||
| 84 | */ |
||
| 85 | public function map(callable $func) |
||
| 86 | { |
||
| 87 | $this->representations = array_map($func, $this->representations); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * count of representations |
||
| 92 | */ |
||
| 93 | public function count(): int |
||
| 94 | { |
||
| 95 | return count($this->representations); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * {@inheritdoc} |
||
| 100 | */ |
||
| 101 | public function getIterator() |
||
| 102 | { |
||
| 103 | return new \ArrayIterator($this->representations); |
||
| 104 | } |
||
| 105 | } |