File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,22 @@ public function unwrapProxyCollection(?ImageSourceProxyCollection $proxyCollecti
3636 return $ this ->imageSourceFactory ->createFromProxyCollection ($ proxyCollection );
3737 }
3838
39+ public function combineCollection (ImageSourceProxyCollection |ImageSourceProxy |null ...$ items ): ImageSourceProxyCollection
40+ {
41+ /**
42+ * @var ImageSourceProxy[] $proxies
43+ */
44+ $ proxies = [];
45+ foreach ($ items as $ item ) {
46+ if ($ item instanceof ImageSourceProxy) {
47+ $ proxies [] = $ item ;
48+ } elseif ($ item instanceof ImageSourceProxyCollection) {
49+ $ proxies = array_merge ($ proxies , $ item ->items );
50+ }
51+ }
52+ return new ImageSourceProxyCollection (...$ proxies );
53+ }
54+
3955 public function allowsCallOfMethod ($ methodName )
4056 {
4157 return true ;
Original file line number Diff line number Diff line change @@ -25,6 +25,45 @@ public function __construct(
2525 $ this ->items = $ items ;
2626 }
2727
28+ public function isEmpty (): bool
29+ {
30+ return empty ($ this ->items );
31+ }
32+
33+ public function getFirst (): ?ImageSourceProxy
34+ {
35+ if (count ($ this ->items ) > 0 ) {
36+ return $ this ->items [array_key_first ($ this ->items )];
37+ }
38+ return null ;
39+ }
40+
41+ public function getRandom (): ?ImageSourceProxy
42+ {
43+ if (count ($ this ->items ) > 0 ) {
44+ $ randomKey = array_rand ($ this ->items );
45+ return $ this ->items [$ randomKey ];
46+ }
47+ return null ;
48+ }
49+
50+ public function withRandomOrder (): self
51+ {
52+ $ items = $ this ->items ;
53+ shuffle ($ items );
54+ return new self (...$ items );
55+ }
56+
57+ public function widthAppendedCollection (ImageSourceProxyCollection $ collection ): self
58+ {
59+ return new self (...$ this ->items , ...$ collection ->items );
60+ }
61+
62+ public function widthAppendedItem (ImageSourceProxy $ item ): self
63+ {
64+ return new self (...$ this ->items , ...[$ item ]);
65+ }
66+
2867 /**
2968 * @return \Traversable<ImageSourceProxy>
3069 */
You can’t perform that action at this time.
0 commit comments