├── .github ├── FUNDING.yml └── workflows │ └── php.yml ├── LICENSE ├── README.md ├── composer.json ├── config ├── config.php └── irfa │ └── serial_number.php └── src ├── Core ├── ConfigInit.php ├── SN.php └── SerialNumberGenerator.php ├── Facades └── SerialNumber.php ├── Func └── SerialNumber.php └── SerialNumberGeneratorSeviceProvider.php /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | patreon: irfa 3 | ko_fi: irfaardy 4 | custom: ['https://buymeacoff.ee/irfaardy'] 5 | -------------------------------------------------------------------------------- /.github/workflows/php.yml: -------------------------------------------------------------------------------- 1 | name: PHP Composer 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Setup PHP 17 | uses: shivammathur/setup-php@v2 18 | with: 19 | php-version: '7.4' 20 | - name: Validate composer.json and composer.lock 21 | run: composer validate 22 | 23 | - name: Cache Composer packages 24 | id: composer-cache 25 | uses: actions/cache@v2 26 | with: 27 | path: vendor 28 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} 29 | restore-keys: | 30 | ${{ runner.os }}-php- 31 | 32 | - name: Install dependencies 33 | if: steps.composer-cache.outputs.cache-hit != 'true' 34 | run: composer install --prefer-dist --no-progress --no-suggest 35 | 36 | # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" 37 | # Docs: https://getcomposer.org/doc/articles/scripts.md 38 | 39 | # - name: Run test suite 40 | # run: composer run-script test 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Irfaardy - Irfa Ardiansyah 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # 🚀PHP Serial Number Generator 3 | [![Maintainability](https://api.codeclimate.com/v1/badges/3f4b5d10a870b2301715/maintainability)](https://codeclimate.com/github/irfaardy/php-sn-generator/maintainability) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/irfaardy/php-sn-generator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/irfaardy/php-sn-generator/?branch=master) ![PHP Composer](https://github.com/irfaardy/php-sn-generator/workflows/PHP%20Composer/badge.svg?branch=master) [![Latest Stable Version](https://poser.pugx.org/irfa/php-sn-generator/v)](//packagist.org/packages/irfa/php-sn-generator) [![GitHub license](https://img.shields.io/github/license/irfaardy/encrypt-file-laravel?style=flat-square)](https://github.com/irfaardy/encrypt-file-laravel/blob/master/LICENSE)
4 | [![Support me](https://img.shields.io/badge/Support-Buy%20me%20a%20coffee-yellow.svg?style=flat-square)](https://www.buymeacoffee.com/irfaardy) [![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S6S52P7SN) 5 | [![Packagist Downloads](https://img.shields.io/packagist/dm/irfa/php-sn-generator.svg?label=Downloads)](https://packagist.org/packages/irfa/php-sn-generator) 6 | 7 | Demo https://phpsngenerator.herokuapp.com/ or demo source code https://github.com/irfaardy/php-sn-generator-demo 8 |

Customable Serial Number Generator for PHP.

9 |

Where can this be used? 10 |

    11 |
  1. Serial number on the application
  2. 12 |
  3. Security Token
  4. 13 |
  5. Vouchers Serial
  6. 14 |
  7. Activation Apps Serial
  8. 15 |
  9. Reset Password link token
  10. 16 |
  11. API Key
  12. 17 |
  13. etc.
  14. 18 |
19 |

20 |

🛠️ Installation with Composer

21 | 22 | 23 | 24 | composer require irfa/php-sn-generator 25 | 26 | >You can get Composer [ here]( https://getcomposer.org/download/) 27 | 28 | *** 29 | 30 | 31 |

🛠️ Laravel Setup

32 | 33 |

Add to config/app.php

34 | 35 | ```php 36 | 'providers' => [ 37 | .... 38 | Irfa\SerialNumber\SerialNumberGeneratorSeviceProvider::class, 39 | ]; 40 | ``` 41 | 42 | 43 | 44 |

Add to config/app.php

45 | 46 | ```php 47 | 'aliases' => [ 48 | .... 49 | 'SN' => Irfa\SerialNumber\Facades\SerialNumber::class, 50 | 51 | ], 52 | ``` 53 | 54 |

Publish Vendor

55 | 56 | 57 | ```bash 58 | php artisan vendor:publish --tag=php-serial-number 59 | ``` 60 | 61 |

Config File

62 | 63 |

Config Laravel

64 | 65 | ```bash 66 | config/irfa/serial_number.php 67 | ``` 68 | 69 |

Config non-Laravel or PHP Native

70 | 71 | ```bash 72 | vendor/irfa/php-sn-generator/config/config.php 73 | ``` 74 | 75 | ```php 76 | 4, 89 | 90 | 'segment' => 4, 91 | 92 | 'seperator' => "-", 93 | 94 | 'charset' => "0123456789ABCDEFGHIJKLMNPQRSTUWXYZ", 95 | 96 | ]; 97 | ``` 98 | 99 | 100 | 101 | 102 |

Example Generate Serial Number (Laravel)

103 | 104 | 105 | ```php 106 | Example Generate Serial Number PHP Native 125 | 126 | 127 | ```php 128 | generate(); //result : TP8K-XU63-9YN3-SMSF 135 | 136 | ``` 137 | 138 |

Other Function

139 |

Programmatically Config

140 | 141 | ```php 142 | //Laravel 143 | SN::setConfig([ 144 | 'length' => 5, 145 | 'segment' => 4, 146 | 'seperator' => '-', 147 | 'charset' => "123456789ABCDEFGH"]) 148 | ->generate(); 149 | 150 | //PHP Native 151 | $sn = new SerialNumber(); 152 | 153 | echo $sn->setConfig([ 154 | 'length' => 5, 155 | 'segment' => 4, 156 | 'seperator' => '-', 157 | 'charset' => "123456789ABCDEFGH" 158 | ]) 159 | ->generate(); 160 | ``` 161 | 162 | ---- 163 | 164 | ## How to Contributing? 165 | 166 | 1. Fork it () 167 | 2. Commit your changes (`git commit -m 'New Feature'`) 168 | 3. Push to the branch (`git push origin your-branch) 169 | 4. Create a new Pull Request ` your-branch -> master` 170 | 171 | if you found bug or error, please post here https://github.com/irfaardy/php-sn-generator/issues so that they can be maintained together. 172 | 173 | 174 | 175 | *** 176 | ## Bagaimana cara berkontribusi? 177 | 178 | 1. Lakukan fork di () 179 | 2. Commit perubahan yang anda lakukan (`git commit -m 'Fitur Baru'`) 180 | 3. Push ke branch master (`git push origin branch-kamu) 181 | 4. Buat Pull Request baru `branch-kamu -> master` 182 | 183 | --- 184 | ## Issue 185 | If you found issues or bug please create new issues here https://github.com/irfaardy/php-sn-generator/issues/new 186 | 187 | Jika anda menemukan bug atau error silahkan posting disini https://github.com/irfaardy/php-sn-generator/issues agar dapat diperbaiki bersama-sama. 188 | 189 | *** 190 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "irfa/php-sn-generator", 3 | "description": "\"Serial number generator for web aplication\"", 4 | "type": "package", 5 | "license": "MIT", 6 | "version": "v1.1", 7 | "homepage": "https://github.com/irfaardy/php-sn-generator", 8 | "keywords": ["laravel","randomized","security", "serial number","serial number generator", "decrypt", "secure","upload file"], 9 | "authors": [ 10 | { 11 | "name": "Irfa A", 12 | "email": "irfa.backend@protonmail.com", 13 | "homepage": "https://github.com/irfaardy" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=7.4", 18 | "hidehalo/nanoid-php": "1.1.8", 19 | "ext-json": "*" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "Irfa\\SerialNumber\\": "src/" 24 | } 25 | }, 26 | "extra": { 27 | "laravel": { 28 | "providers": [ 29 | "Irfa\\SerialNumber\\SerialNumberGeneratorSeviceProvider::class" 30 | ] 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | 4, //default : 4 (result:ABCD) 14 | 15 | 'segment' => 4, //default : 4 (result:ABCD-1234-A1B2-CDEF) 16 | 17 | 'seperator' => "-", //default : - (result : ABCD-1234-A1B2-CDEF) 18 | 19 | 'charset' => "0123456789ABCDEFGHIJKLMNPQRSTUWXYZ",//default : 0123456789ABCDEFGHIJKLMNPQRSTUWXYZ 20 | 21 | 22 | 23 | ]; 24 | -------------------------------------------------------------------------------- /config/irfa/serial_number.php: -------------------------------------------------------------------------------- 1 | 4, //default : 4 (result:ABCD) 14 | 15 | 'segment' => 4, //default : 4 (result:ABCD-1234-A1B2-CDEF) 16 | 17 | 'seperator' => "-", //default : - (result : ABCD-1234-A1B2-CDEF) 18 | 19 | 'charset' => "0123456789ABCDEFGHIJKLMNPQRSTUWXYZ", //default : 0123456789ABCDEFGHIJKLMNPQRSTUWXYZ 20 | 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /src/Core/ConfigInit.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | namespace Irfa\SerialNumber\Core; 6 | 7 | class ConfigInit 8 | { 9 | protected $length; 10 | protected $segment; 11 | protected $seperator; 12 | protected $charset; 13 | 14 | protected function runConfig($config_array=null) 15 | { 16 | if(empty($config_array)) 17 | { 18 | $this->setConfig(); 19 | } else { 20 | $this->directConfig($config_array); 21 | } 22 | } 23 | 24 | private function setConfig() 25 | { 26 | if (function_exists('config') and function_exists('app')) {//Load Config For Laravel 27 | if(!empty(config('irfa.serial_number'))) 28 | { 29 | $this->laravelConfig(); 30 | } else{ 31 | $this->generalConfig(); 32 | } 33 | } else{//Load Config for Non-Laravel 34 | $this->generalConfig(); 35 | } 36 | } 37 | private function laravelConfig() 38 | { 39 | $this->length = config('irfa.serial_number.length'); 40 | $this->segment = config('irfa.serial_number.segment'); 41 | $this->seperator = config('irfa.serial_number.seperator'); 42 | $this->charset = config('irfa.serial_number.charset'); 43 | } 44 | 45 | private function generalConfig() 46 | { 47 | require dirname(__DIR__, 2)."/config/config.php"; 48 | 49 | $this->length = $config['length']; 50 | $this->segment = $config['segment']; 51 | $this->seperator = $config['seperator']; 52 | $this->charset = $config['charset']; 53 | } 54 | 55 | private function directConfig($arr) 56 | { 57 | require dirname(__DIR__, 2)."/config/config.php"; 58 | 59 | $this->length = isset($arr['length']) ? $arr['length']:$config['length']; 60 | $this->segment = isset($arr['segment']) ? $arr['segment']:$config['segment']; 61 | $this->seperator = isset($arr['seperator']) ? $arr['seperator']:$config['seperator']; 62 | $this->charset = isset($arr['charset']) ? $arr['charset']:$config['charset']; 63 | } 64 | 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/Core/SN.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | namespace Irfa\SerialNumber\Core; 6 | 7 | class SN extends SerialNumberGenerator 8 | { 9 | private $generated_serial; 10 | private $serial; 11 | 12 | protected function generateSN($json=false) 13 | { 14 | if($json) 15 | { 16 | return json_encode(['sn'=>$this->generatingSN()]); 17 | } 18 | return $this->generatingSN(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/Core/SerialNumberGenerator.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | namespace Irfa\SerialNumber\Core; 6 | 7 | use Hidehalo\Nanoid\Client; 8 | 9 | class SerialNumberGenerator extends ConfigInit 10 | { 11 | private $sn; 12 | 13 | function __construct($config_array=null) 14 | { 15 | $this->runConfig($config_array); 16 | } 17 | 18 | protected function generatingSN() 19 | { 20 | for($i=1;$i<=intval($this->segment);$i++) 21 | { 22 | $this->sn .= $this->sn()->formattedId($this->charset,intval($this->length)).$this->seperator; 23 | } 24 | 25 | $sn = $this->sn; 26 | return rtrim($sn, $this->seperator); 27 | } 28 | 29 | private function sn() 30 | { 31 | $obj = new Client(); 32 | 33 | return $obj; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Facades/SerialNumber.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | namespace Irfa\SerialNumber\Facades; 6 | 7 | use Illuminate\Support\Facades\Facade; 8 | 9 | class SerialNumber extends Facade 10 | { 11 | /** 12 | * Get the registered name of the component. 13 | * 14 | * @return string 15 | */ 16 | protected static function getFacadeAccessor() 17 | { 18 | return \Irfa\SerialNumber\Func\SerialNumber::class; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Func/SerialNumber.php: -------------------------------------------------------------------------------- 1 | 5 | @version: 1.1 6 | */ 7 | namespace Irfa\SerialNumber\Func; 8 | 9 | use Irfa\SerialNumber\Core\SN; 10 | 11 | class SerialNumber extends SN 12 | { 13 | private array $config=[]; 14 | function __construct(array $config=null) 15 | { 16 | if(!empty($config)) 17 | { 18 | $this->setConfig($config); 19 | } 20 | } 21 | public function generate($json_return = false) 22 | { 23 | $sn = new SN($this->config); 24 | return $sn->generateSN($json_return); 25 | } 26 | 27 | public function setConfig(array $config) 28 | { 29 | $this->config = $config; 30 | return $this; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/SerialNumberGeneratorSeviceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 27 | __DIR__.'/../config/irfa/' => config_path('irfa')],'php-serial-number'); 28 | 29 | 30 | } 31 | } 32 | --------------------------------------------------------------------------------