@@ -66,11 +66,11 @@ protected function service_construct($array) {
6666 * @param string $key
6767 * @return mixed
6868 */
69- public function where ($ value , $ key ='username ' ) {
69+ public function & where ($ value , $ key ='username ' ) {
7070 foreach ($ this ->streams as &$ arr ) {
7171 if ($ arr ->$ key == $ value ) {
72- $ item =& $ arr ;
73- return $ item ;
72+ // $item =& $arr;
73+ return $ arr ;
7474 }
7575 }
7676 }
@@ -149,36 +149,22 @@ public function sort($sort=NULL, $byKey="viewers", $direction="desc") {
149149 });
150150 }
151151
152+ private function mergeService (Service $ merge ) {
153+ $ this ->streams = array_merge ($ this ->streams , $ merge ->get ());
154+ $ this ->removeDuplicates ();
155+ return $ this ;
156+ }
157+
152158 /**
153159 * @param Service $merge
160+ * @return $this
154161 */
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 );
181166 }
167+ return $ this ;
182168 }
183169
184170 /**
@@ -263,4 +249,4 @@ public function attach(Service $service) {
263249 $ this ->streams = array_push ($ this ->streams , $ service ->get ());
264250 }
265251
266- }
252+ }
0 commit comments