scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 /*
4 * This file is part of PHP-FFmpeg.
5 *
6 * (c) Alchemy <info@alchemy.fr>
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 namespace FFMpeg\FFProbe\DataMapping;
13  
14 class StreamCollection implements \Countable, \IteratorAggregate
15 {
16 private $streams;
17  
18 public function __construct(array $streams = array())
19 {
20 $this->streams = array_values($streams);
21 }
22  
23 /**
24 * Returns the first stream of the collection, null if the collection is
25 * empty.
26 *
27 * @return null|Stream
28 */
29 public function first()
30 {
31 $stream = reset($this->streams);
32  
33 return $stream ?: null;
34 }
35  
36 /**
37 * Adds a stream to the collection.
38 *
39 * @param Stream $stream
40 *
41 * @return StreamCollection
42 */
43 public function add(Stream $stream)
44 {
45 $this->streams[] = $stream;
46  
47 return $this;
48 }
49  
50 /**
51 * Returns a new StreamCollection with only video streams.
52 *
53 * @return StreamCollection
54 */
55 public function videos()
56 {
57 return new static(array_filter($this->streams, function (Stream $stream) {
58 return $stream->isVideo();
59 }));
60 }
61  
62 /**
63 * Returns a new StreamCollection with only audio streams.
64 *
65 * @return StreamCollection
66 */
67 public function audios()
68 {
69 return new static(array_filter($this->streams, function (Stream $stream) {
70 return $stream->isAudio();
71 }));
72 }
73  
74 /**
75 * {@inheritdoc}
76 */
77 public function count()
78 {
79 return count($this->streams);
80 }
81  
82 /**
83 * Returns the array of contained streams.
84 *
85 * @return array
86 */
87 public function all()
88 {
89 return $this->streams;
90 }
91  
92 /**
93 * {@inheritdoc}
94 */
95 public function getIterator()
96 {
97 return new \ArrayIterator($this->streams);
98 }
99 }