amoeba/common

amoeba codeigniter 4 common library

1.1.0 2022-03-10 13:00 UTC

This package is not auto-updated.

Last update: 2022-09-23 02:27:19 UTC


README

common library collections


ServiceClient

<?php

    use Amoeba\Common\ServiceClient\ServiceClient;
    
    $this->someService = new ServiceClient('https://api.runselltype.co');
    
    $response = $this->someService->req->get('v1/font');
    
    print_r($response->getBody());
    print_r($response->getHeaders());
    print_r($response->getStatusCode());


AMQP

  • Publish
<?php

    use Amoeba\Common\AMQP;
    
    $connection = AMQP::connection('localhost:4000', 'user', 'password', 'default');
    
    $result = AMQP::publishJSON($connection, "SOME.EXCHANGE", '{"title":"snowpiercer"}');
    
    print_r($result);
  • Subscribe
<?php
    use Amoeba\Common\AMQP;
    
    $connection = AMQP::connection('localhost:4000', 'user', 'password', 'default');
    $cnl =  $connection->channel();
    
    $handler = function ($msg) {
        print_r($msg->body);
    };
    
    $cnl->basic_consume('THREAD.SERVICE', '', false, true, false, false, $handler);
    while ($cnl->is_open()) {
        $cnl->wait();
    }
    $cnl->close();
    $connection->close();


ObjStorage

  • Upload file

    <?php
      use Amoeba\Common\ObjStorage\ObjStorage;
      use CodeIgniter\HTTP\Files\UploadedFile;
        
      $client = ObjStorage::client('locahost:4000', 'key', 'secret');
      $result = ObjStorage::upload($client, new UploadedFile('composer.json', 'composer.json'), 'config_file');
        
      print_r($result);
    


Cache

  • cache with duration

    <?php
    
      use Amoeba\Common\Cache\RedisCache;
        
      $cache = RedisCache::client('http://localhost', 'password');
        
      $result = RedisCache::set($cache, 'ity', 'Bandung', 500);
        
      print_r($result);
    


Logging