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
- Host: GitHub
- URL: https://github.com/spotlibs/php-lib
- Owner: spotlibs
- Created: 2024-07-22T11:10:21.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2026-02-26T03:06:30.000Z (5 months ago)
- Last Synced: 2026-02-26T07:56:55.719Z (5 months ago)
- Language: PHP
- Homepage:
- Size: 883 KB
- Stars: 0
- Watchers: 0
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spotlibs-php-lib
[](https://github.com/spotlibs/php-lib/actions)
[](https://packagist.org/packages/spotlibs/php-lib)
[](https://packagist.org/packages/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