birdsystem/common

Common bundle for Birdsystem

Installs: 27

Dependents: 0

Suggesters: 0

Security: 0

Type:symfony-bundle

0.2 2020-12-02 13:56 UTC

This package is auto-updated.

Last update: 2020-12-04 16:19:56 UTC


README

Purpose

This component contains some common libraries/services used by all micro-services in BirdSystem

Installation

In your composer.json file, add the following code:

  "extra": {
    "symfony": {
      "endpoint": "https://flex-server.birdsystem.com"
    }
  }

To do so is to use our own flex-server, so we can use our own private Flex Recipes.

Then require this lib from packagies:

composer require -W birdsystem/common:dev-master

The -W option is to update all dependencies required by this lib.

Verify Installation

You should be able to see more environment variables being added to your .env file. (This is achived by flex recipes)

In your own micro-service, run

bin/console debug:container birdsystem

If you see some services listed, then it means the installation has been successful.

Usage

To follow the best practice of Symfony Service Container, normally we should mark all our own services as private.

With private services you cannot use $container->get('service_name').

Instead, use the service by type-hinting (the following example is to use the Company micro-service, which is just a Scoped HttpClient with predefined base_uri):

<?php
namespace App;

use Birdsystem\CommonBundle\MicroServiceClient\Company;

class Test{
    public function test(Company $company){
        $company->request('GET','/company');
    }  
}

The above code should send a GET request to http://company/api/company, because in your .env file there should be a defination of

SERVICE_URL_COMPANY=http://company/api/

Update the recipe

In case we later on added more configurations into the system, and we have updated the recipe, you will need to update it

bin/console recipes:install birdsystem/common --force