kevinpurwito / php-constant
PhpConstant is a simple class containing useful functions which you can extend to your constant classes.
Fund package maintenance!
www.paypal.me/kevinpurwito
Installs: 2 809
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.17
- orchestra/testbench: ^6.18
- phpunit/phpunit: ^9.0
- vimeo/psalm: ^4.3
README
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.
Installation
You can install the package via composer:
composer require kevinpurwito/php-constant
Usage
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();
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email kevin.purwito@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
PHP Package Boilerplate
This package was generated using the PHP Package Boilerplate by Beyond Code with some modifications inspired from PHP Package Skeleton by spatie.