PHP Classes

File: src/MultiRepositoryClient.php

Recommend this page to a friend!
  Classes of Till Wehowski   Package Fetcher   src/MultiRepositoryClient.php   Download  
File: src/MultiRepositoryClient.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Package Fetcher
Fetch packages from several Composer repositories
Author: By
Last change:
Date: 3 years ago
Size: 853 bytes
 

Contents

Class file image Download
<?php
namespace frdl\PackageFetcher;

use
frdl\PackageFetcher\RepositoryClientInterface;
 
class
MultiRepositoryClient
{
    protected
$clients = [];
    public function
__construct(array $clients = null){
      if(
is_array($clients)){
        foreach(
$clients as $client){
          
$this->addClient($client);
        }
      }
    }
   
    public function
addClient(RepositoryClientInterface $client){
      
$this->clients[] = $client;
       return
$this;
    }
    public function
_call($name, $params){
     
$result = [];
       foreach(
$this->clients as $client){
             if(
in_array($name,$client->supports()){
               
$r = call_user_func_array($client->service($name), $params);
               
$r = (array)$r;
               
$result = array_merge($result, $r);
             }
       }
      
       return
$result;
    }
}