PHP Classes

File: src/PackagistClient.php

Recommend this page to a friend!
  Classes of Till Wehowski   Package Fetcher   src/PackagistClient.php   Download  
File: src/PackagistClient.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: 1,166 bytes
 

Contents

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

use
Packagist\Api\Client as PClient;
use
frdl\PackageFetcher\AbstractComposerRepositoryClient as RepositoryClient;

class
PackagistClient extends RepositoryClient
{
     protected
$Client;
     protected
$services;
     public function
__construct($packagistUrl = "https://packagist.org"){
       
$this->Client = new PClient(null, null, $packagistUrl);
       
$this->services = [
         
RepositoryClient::SERVICE_PACKAGE => [$this,'get'],
         
RepositoryClient::SERVICE_ALL => [$this,'all'],
         
RepositoryClient::SERVICE_SEARCH => [$this,'search'],
         
RepositoryClient::SERVICE_POPULAR => [$this,'popular'],
      ];
     }
    
     public function
__call($name, $params){
       return
call_user_func_array([$this->Client, $name], $params);
     }
    
    public function
service(string $service) :?\callable
    {
        if(isset(
$this->services[$service]) && is_callable($this->services[$service])){
          return
$this->services[$service];
        }
       
        return
null;
    }
   
    public function
supports() : array
    {
      return
array_keys($this->services);
    }
}