Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saidqb/core-php
core php
https://github.com/saidqb/core-php
Last synced: about 1 month ago
JSON representation
core php
- Host: GitHub
- URL: https://github.com/saidqb/core-php
- Owner: saidqb
- License: mit
- Created: 2024-07-15T04:44:31.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-10-14T07:43:17.000Z (4 months ago)
- Last Synced: 2024-12-13T09:06:20.017Z (about 2 months ago)
- Language: PHP
- Size: 80.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# core-php
A dependency for php project
## Description
progress build...
## Requirments
PHP >= 8.1
## Installation
```
composer require saidqb/core-php
```## Package include
- **Array Collection** [doctrine/collection](https://www.doctrine-project.org/projects/collections.html)
- **String Manipulation** [str/str](https://github.com/fe3dback/str?tab=readme-ov-file#functions-index)
- **Generator String** [phlak/strgen](https://github.com/PHLAK/StrGen)### Arr
```php
use Saidqb\CorePhp\Lib\Arr;$arr = [1, 2, 3];
Arr::collection($arr)->filter(function($element) {
return $element > 1;
}); // [2, 3]Arr::collection($arr)->contains(1); // true
Arr::collection($arr)->filter(function($element) {
return $element > 1;
}); // [2, 3]
```Detail [Documentation](https://www.doctrine-project.org/projects/doctrine-collections/en/stable/index.html#collection-methods)
### Str
```php
use Saidqb\CorePhp\Lib\Str;$str = 'string';
Str::make($str)->startsWith($substring);
Str::make($str)->endsWith($substring);
```
Detail [Documentation](https://github.com/fe3dback/str?tab=readme-ov-file#functions-index)### Generate
```php
use Saidqb\CorePhp\Lib\Generate;Generate::str()->lowerAlpha($length);
Generate::str()->upperAlpha($length);
Generate::str()->mixedAlpha($length);
Generate::str()->numeric($length);
Generate::str()->alphaNumeric($length);
Generate::str()->special($length);
Generate::str()->all($length);
Generate::str()->custom($length, $charset);
```
Detail [Documentation](https://github.com/PHLAK/StrGen)### Pagination
```php
use Saidqb\CorePhp\Pagination;$pagination = Pagination::make()->totalItems(100)->itemPerPage(10)->currentPage(1)->get();
```
### Response
```php
use Saidqb\CorePhp\Response;Response::make()->response([], ResponseCode::HTTP_OK, ResponseCode::HTTP_OK_MESSAGE, 0)->send();
// list item
Response::make()->response(['items' => $items, 'pagination' => $pagination])->send();// single item
Response::make()->response(['item' => $item])->send();
```**used in controller**
BaseController
```php
use Saidqb\CorePhp\Response;
use Saidqb\CorePhp\ResponseCode;public $res;
public function __construct()
{
$this->initResponse();
}public function initResponse()
{
$this->res = new Response();
return $this->res;
}public function response($data, $code = ResponseCode::HTTP_OK, $message = ResponseCode::HTTP_OK_MESSAGE, $errorCode = 0)
{
$this->res->response($data, $code, $message, $errorCode)->send();
}
```Extends to BaseController
```php
use Saidqb\CorePhp\ResponseCode;public function __construct()
{
parent::__construct();$this->initResponse()->hide(['password']);
}
public function index()
{
$this->response($data, ResponseCode::HTTP_OK);
}
```Avilable Manipulate data:
```php
->hide(['password'])
->decode(['extra'])
->decodeChild(['extra.user'])
->decodeArray(['extra_list'])
->addFields(['field1' => '1', 'field2' => '2'])
->addField('field1', '1')
->hook('item', function($data){ return $data})
```## COFFEE FOR BEST PERFORMANCE
**[COFFEE HERE](https://saidqb.github.io/coffee)** for more inovation
OR