iwouldrathercode / php-simple-coupons
PHP package to help generates simple and unique coupon codes using random_bytes
Installs: 12 273
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: >=7.0
Requires (Dev)
- clagiordano/phpunit-result-printer: ^2.0
- jakub-onderka/php-console-color: ^0.2.0
- phpunit/phpunit: ^7.0
- symfony/var-dumper: ^4.1
This package is auto-updated.
Last update: 2024-12-14 08:34:40 UTC
README
PHP package to help generates simple and unique coupon codes.
Installation
composer require iwouldrathercode/php-simple-coupons
Usage
Generating single coupon codes
use Iwouldrathercode\SimpleCoupons\Coupon; . . . // Somewhere in your code... $code = new Coupon(); // Coupon code only $coupon = $code->generate(); // Coupon code with a prefix of `ABC` $coupon = $code->prepend('ABC')->generate(); // Coupon code with a prefix of `ABC` and suffix of `XYZ` $coupon = $code->prepend('ABC')->append('XYZ')->generate(); // Coupon code with a prefix of `ABC` and suffix of `XYZ` and max. char. length as - 10 $coupon = $code->limit(10)->generate(); . .
Generating multiple coupon codes
use Iwouldrathercode\SimpleCoupons\Coupon; . . . // Somewhere in your code... function generateMultipleCodes($limit, $table) { $couponsArray = []; $code = new Coupon(); // Looping through unti limit is reached for($i=1; $i<=$limit; $i++) { // VERY VERY IMPORTANT - TO AVOID MEMORY_LIMIT ISSUES gc_enable(); // Call to function to generate one coupon code generate($code, $couponsArray); // VERY VERY IMPORTANT - TO AVOID MEMORY_LIMIT ISSUES gc_disable(); } // VERY VERY IMPORTANT - TO AVOID MEMORY_LIMIT ISSUES unset($code); return $array; } function generate($code, $couponsArray) { $coupon = $code->limit(12)->generate(); // echo $coloredOutput->apply("color_15", $coupon.PHP_EOL); array_push($couponsArray, $coupon); $code->__destruct(); } // Generate 10 coupon codes $multipleCoupons = generateMultipleCodes(10, $table);
For more examples do refer example.php and performance.php
Credits
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.