PhpConstant is a simple class containing useful functions which you can extend to your constant classes.
For example if you want to have a StatusConst class, which contains all possible statuses as constants, you can extend PhpConstant to use its functions for your StatusConst class.
You can install the package via composer:
composer require kevinpurwito/php-constant
use KevinPurwito\PhpConstant\PhpConstant;
// Class Extends PhpConstant to use its functions
class StatusConst extends PhpConstant
{
const PENDING = 'pending';
const IN_PROCESS = 'in_process';
const COMPLETED = 'completed';
}
/*
|--------------------------------------------------------------------------
| Framework Agnostic Functions
|--------------------------------------------------------------------------
|
| Simple functions not dependent to any framework and can be used in any PHP project.
|
*/
// returns an array like this: ['pending', 'in_process', 'completed']
StatusConst::all();
// returns a key-value array like this: ['pending' => 'Pending', 'in_process' => 'In Process', 'completed' => 'Completed']
StatusConst::options();
// returns a string like this: 'pending,in_process,completed'
StatusConst::asString();
// You can use any char you want as the glue for asString() function
// returns a string like this: 'pending|in_process|completed'
StatusConst::asString('|');
/*
|--------------------------------------------------------------------------
| Laravel Specific Functions
|--------------------------------------------------------------------------
|
| Functions to support [Laravel Collection](https://laravel.com/docs/collections) class.
| Laravel Collection is a class that provides a fluent, convenient wrapper for working with arrays of data.
|
*/
// returns a collection equivalent to: collect(['pending', 'in_process', 'completed'])
StatusConst::collect();
// returns a key-value collection equivalent to: collect(['pending' => 'Pending', 'in_process' => 'In Process', 'completed' => 'Completed'])
StatusConst::collectOptions();
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the PHP Package Boilerplate by Beyond Code with some modifications inspired from PHP Package Skeleton by spatie.