@@ -66,11 +66,11 @@ protected function service_construct($array) {
66
66
* @param string $key
67
67
* @return mixed
68
68
*/
69
- public function where ($ value , $ key ='username ' ) {
69
+ public function & where ($ value , $ key ='username ' ) {
70
70
foreach ($ this ->streams as &$ arr ) {
71
71
if ($ arr ->$ key == $ value ) {
72
- $ item =& $ arr ;
73
- return $ item ;
72
+ // $item =& $arr;
73
+ return $ arr ;
74
74
}
75
75
}
76
76
}
@@ -149,36 +149,22 @@ public function sort($sort=NULL, $byKey="viewers", $direction="desc") {
149
149
});
150
150
}
151
151
152
+ private function mergeService (Service $ merge ) {
153
+ $ this ->streams = array_merge ($ this ->streams , $ merge ->get ());
154
+ $ this ->removeDuplicates ();
155
+ return $ this ;
156
+ }
157
+
152
158
/**
153
159
* @param Service $merge
160
+ * @return $this
154
161
*/
155
- public function merge (Service $ merge ) {
156
- $ new_array = [];
157
- $ stream = $ merge ->get ();
158
- /** @var Stream $merge_stream */
159
- foreach ($ stream as $ merge_stream ) {
160
- $ found = FALSE ;
161
- /** @var Stream $stream */
162
- foreach ($ this ->streams as $ key => $ stream ) {
163
- if ($ stream ->username === $ merge_stream ->username && $ stream ->service === $ merge_stream ->service ) {
164
- if ($ merge_stream ->hasCustomKeys ()) {
165
- $ this ->streams [$ key ] = $ merge_stream ;
166
- }
167
- $ found = TRUE ;
168
- }
169
- }
170
- if (!$ found ) {
171
- array_push ($ this ->streams , $ merge_stream );
172
- }
173
- }
174
- }
175
-
176
- public function m (Service $ merge ) {
177
- $ merge_streams = $ merge ->get ();
178
- /** @var Stream $merge_stream */
179
- foreach ($ merge_streams as $ merge_stream ) {
180
-
162
+ public function merge () {
163
+ $ args = is_array (func_get_args ()[0 ]) ? func_get_args ()[0 ] : func_get_args ();
164
+ foreach ($ args as $ arg ) {
165
+ $ this ->mergeService ($ arg );
181
166
}
167
+ return $ this ;
182
168
}
183
169
184
170
/**
@@ -263,4 +249,4 @@ public function attach(Service $service) {
263
249
$ this ->streams = array_push ($ this ->streams , $ service ->get ());
264
250
}
265
251
266
- }
252
+ }
0 commit comments