An open API service indexing awesome lists of open source software.

https://github.com/spotlibs/php-lib

Standardized reuseable pkg for PHP
https://github.com/spotlibs/php-lib

Last synced: 5 months ago
JSON representation

Standardized reuseable pkg for PHP

Awesome Lists containing this project

README

          

# spotlibs-php-lib

[![Build Status](https://github.com/spotlibs/php-lib/actions/workflows/php.yml/badge.svg)](https://github.com/spotlibs/php-lib/actions)
[![Total Downloads](https://img.shields.io/packagist/dt/spotlibs/php-lib)](https://packagist.org/packages/spotlibs/php-lib)
[![Latest Stable Version](https://img.shields.io/packagist/v/spotlibs/php-lib)](https://packagist.org/packages/spotlibs/php-lib)
[![License](https://img.shields.io/packagist/l/spotlibs/php-lib)](https://packagist.org/packages/spotlibs/php-lib)

## Description
This library is used to support easier development of Spotlibs Microservice Project.

This library provides rest client for communication between microservice.
This library provides kafka client both producer and consumer with support avro serde.

## Install

composer require spotlibs/php-lib

## Usage
- Exception
```php
'Top 10 Countries with Best Cyber Security, Finland Ranked First',
'content' => 'Here are the top 10 countries with the best cyber securities based on the data published by Mix Mode and 2024 Global Security Index:'
]);
return StdResponse::success('Daily news posted.');
}
}
```
- DTO
```php
person = new Person([
'name' => 'John',
'age' => 30,
'hobbies' => ['fishing', 'sleeping', 'coding']
]);
}

public function index(): void
{
echo "Hi, my name is " . $this->person->name . ". I am " . $this->person->age . " year(s) old" . PHP_EOL;
}
}
```
- Context

Implement a context as an object containing several key:value from the begining to the end of request lifecycle. To use context, add this service provider to your bootstrap/app.php for Lumen or config/app.php for Laravel
```php
$app->register(\Spotlibs\PhpLib\Providers\ContextServiceProvider::class);
```
- Activity Middleware

Request and response middleware to initiate context and writing activity log. To use this middleware, add this line to your app middleware setting
```php
$app->middleware([
//...
\Spotlibs\PhpLib\Middlewares\ActivityMonitor::class,
//...
]);
```
- Logger
```php
info(['timestamp' => '2006-01-02 15:04:05', 'status' => 'accomplished']);
Log::worker()->info(['timestamp' => '2006-01-02 15:04:05', 'job' => 'holding bro\'s beer']);
Log::runtime()->info(['timestamp' => '2006-01-02 15:04:05', 'error' => 'the beer likely to spilled']);
Log::runtime()->warning(['timestamp' => '2006-01-02 15:04:05', 'error' => 'the beer gonna be spilled']);
Log::runtime()->error(['timestamp' => '2006-01-02 15:04:05', 'error' => 'the beer got spilled']);
}
}
```
- Queue

add this service provider to your bootstrap/app.php for Lumen or config/app.php for Laravel
```php
$app->register(\Spotlibs\PhpLib\Providers\QueueEventServiceProvider::class);
```

and here is how to use Queue
```php