|
1 | | -# <p align="center"><a href="https://shiftechafrica.com/" target="_blank"><img width="100" src="https://shiftechafrica.com/img/logo.png"></a></p> |
| 1 | +# <p align="center"><a href="https://shiftechafrica.com/" target="_blank"><img width="100" src="https://shiftechafrica.com/img/logo.png" alt="Shiftech Africa Logo"></a></p> |
2 | 2 |
|
3 | 3 | <p align="center"> |
4 | 4 | <b>Be in the next level</b><br> |
5 | 5 | <a href="https://github.com/SHIFTECH-AFRICA/shift-code-generator/issues"> |
6 | | - <img src="https://img.shields.io/github/issues/SHIFTECH-AFRICA/shift-code-generator.svg"> |
| 6 | + <img src="https://img.shields.io/github/issues/SHIFTECH-AFRICA/shift-code-generator.svg"> |
7 | 7 | </a> |
8 | 8 | <a href="https://github.com/SHIFTECH-AFRICA/shift-code-generator/network/members"> |
9 | | - <img src="https://img.shields.io/github/forks/SHIFTECH-AFRICA/shift-code-generator.svg"> |
| 9 | + <img src="https://img.shields.io/github/forks/SHIFTECH-AFRICA/shift-code-generator.svg"> |
10 | 10 | </a> |
11 | 11 | <a href="https://github.com/SHIFTECH-AFRICA/shift-code-generator/stargazers"> |
12 | | - <img src="https://img.shields.io/github/stars/SHIFTECH-AFRICA/shift-code-generator.svg"> |
| 12 | + <img src="https://img.shields.io/github/stars/SHIFTECH-AFRICA/shift-code-generator.svg"> |
13 | 13 | </a> |
14 | 14 | <a href="https://packagist.org/packages/shiftechafrica/shift-code-generator"> |
15 | | - <img src="https://poser.pugx.org/shiftechafrica/shift-code-generator/v/stable"> |
| 15 | + <img src="https://poser.pugx.org/shiftechafrica/shift-code-generator/v/stable"> |
16 | 16 | </a> |
17 | 17 | <a href="https://packagist.org/packages/shiftechafrica/shift-code-generator"> |
18 | | - <img src="https://poser.pugx.org/shiftechafrica/shift-code-generator/downloads"> |
| 18 | + <img src="https://poser.pugx.org/shiftechafrica/shift-code-generator/downloads"> |
19 | 19 | </a> |
20 | 20 | <br><br> |
21 | | - <img src="https://i.pinimg.com/originals/ce/69/4f/ce694f560636dffcf42ecf40d4f2f962.gif"> |
| 21 | + <img src="https://i.pinimg.com/originals/ce/69/4f/ce694f560636dffcf42ecf40d4f2f962.gif" alt="Shift Code Generator Animation"> |
22 | 22 | </p> |
23 | 23 |
|
24 | | -## Introduction |
25 | | -This package generates code in relation to year, date and month. For instance, it uses A - Z letters for months. For example *1E1NKJDQVW* code *1* rep number of years, *E* rep month and *1* rep date while *NKJDQVW* is a random string. |
26 | | -This library mimics the *mpesa-transaction-id*. |
| 24 | +--- |
27 | 25 |
|
28 | | -## Installing |
| 26 | +## 🚀 Introduction |
29 | 27 |
|
30 | | -The recommended way to install shift-code-generator is through |
31 | | -[Composer](http://getcomposer.org). |
| 28 | +**Shift Code Generator** is a lightweight Laravel/PHP package that generates unique alphanumeric codes based on the **year**, **month**, and **day**, followed by a randomized string. |
| 29 | +It’s ideal for applications that require sequential or time-based identifiers — such as **transaction IDs**, **invoice numbers**, or **reference codes**. |
| 30 | + |
| 31 | +For example: |
| 32 | +`1E1NKJDQVW` |
| 33 | +- **1** → Represents the number of years since the start year |
| 34 | +- **E** → Represents the month (A–Z mapping) |
| 35 | +- **1** → Represents the day of the month |
| 36 | +- **NKJDQVW** → Randomly generated string |
| 37 | + |
| 38 | +This logic mimics the behavior of **M-Pesa transaction IDs**, ensuring unique, traceable, and time-bound identifiers. |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## ⚙️ Installation |
| 43 | + |
| 44 | +Install via [Composer](https://getcomposer.org/): |
32 | 45 |
|
33 | 46 | ```bash |
34 | | -# Install package via composer |
35 | 47 | composer require shiftechafrica/shift-code-generator |
36 | 48 | ``` |
37 | 49 |
|
38 | | -Next, run the Composer command to install the latest stable version of *shiftechafrica/shift-code-generator*: |
| 50 | +Update to the latest version: |
39 | 51 |
|
40 | 52 | ```bash |
41 | | -# Update package via composer |
42 | | - composer update shiftechafrica/shift-code-generator --lock |
| 53 | +composer update shiftechafrica/shift-code-generator --lock |
43 | 54 | ``` |
44 | 55 |
|
45 | | -After installing, the package will be auto discovered, But if need you may run: |
| 56 | +If the package isn’t automatically discovered, run: |
46 | 57 |
|
47 | | -```php |
48 | | -# run for auto discovery <-- If the package is not detected automatically --> |
| 58 | +```bash |
49 | 59 | composer dump-autoload |
50 | 60 | ``` |
51 | 61 |
|
52 | | -Then run this, to get the *config/shift-code-generator.php* for your own configurations: |
| 62 | +Publish the configuration file: |
53 | 63 |
|
54 | | -```php |
55 | | -# run this to get the configuration file at config/shift-code-generator.php <-- read through it --> |
| 64 | +```bash |
56 | 65 | php artisan vendor:publish --provider="ShiftechAfrica\CodeGenerator\ShiftCodeGeneratorServiceProvider" |
57 | 66 | ``` |
58 | | -A *config/shift-code-generator.php* file will be created, so if you want to use the database follow the next step on how to seed. The following add to your .env file. |
59 | 67 |
|
60 | | -```php |
61 | | - YEAR_OF_START=2020 #pass the year that your application is launched |
62 | | - USE_DATABASE=false #pass true if you want to use the database and false to use your default YEAR_OF_START |
| 68 | +This will create a config file at: |
| 69 | + |
| 70 | +``` |
| 71 | +config/shift-code-generator.php |
63 | 72 | ``` |
64 | 73 |
|
| 74 | +--- |
| 75 | + |
| 76 | +## ⚙️ Configuration |
65 | 77 |
|
66 | | -You will have to add this in the *database/seeds/DatabaseSeeder*. To ensure we seed some data to set the default dates that will be used in generating the codes: |
| 78 | +In your `.env` file, add the following: |
| 79 | + |
| 80 | +```dotenv |
| 81 | +YEAR_OF_START=2020 # The year your application was launched |
| 82 | +USE_DATABASE=false # Set to true to use database tracking, or false to use static year configuration |
| 83 | +``` |
| 84 | + |
| 85 | +If you enable database tracking, seed the database by adding this entry to your `DatabaseSeeder`: |
67 | 86 |
|
68 | 87 | ```php |
69 | | - /** |
70 | | - * Seed the application's database. |
71 | | - * |
72 | | - * @return void |
73 | | - */ |
74 | | - public function run() |
75 | | - { |
76 | | - // other seeds... |
77 | | - $this->call(\ShiftechAfrica\CodeGenerator\Seeds\ShiftCodeGeneratorFactory::class); |
78 | | - } |
| 88 | +/** |
| 89 | + * Seed the application's database. |
| 90 | + * |
| 91 | + * @return void |
| 92 | + */ |
| 93 | +public function run() |
| 94 | +{ |
| 95 | + // Other seeds... |
| 96 | + $this->call(\ShiftechAfrica\CodeGenerator\Seeds\ShiftCodeGeneratorFactory::class); |
| 97 | +} |
79 | 98 | ``` |
80 | 99 |
|
81 | | -## Usage |
82 | | -Follow the steps below on how to use the shift-code-generator: |
| 100 | +This ensures your application initializes with proper baseline data for generating codes dynamically. |
83 | 101 |
|
84 | | -#### How to use the Library |
85 | | -How to generate the code... |
| 102 | +--- |
| 103 | + |
| 104 | +## 🧩 Usage |
| 105 | + |
| 106 | +Generate unique codes easily within your application. |
86 | 107 |
|
87 | 108 | ```php |
88 | | - use ShiftechAfrica\CodeGenerator\ShiftCodeGenerator; |
89 | | - /** |
90 | | - * ---------------------------- |
91 | | - * Generate the code here |
92 | | - * ----------------------------------------------------------------------- |
93 | | - * Code will be generated in the format of Y-M-D + 7 random characters |
94 | | - * ----------------------------------------------------------------------- |
95 | | - * @return string |
96 | | - */ |
97 | | - public function generateCode() |
98 | | - { |
99 | | - return (new ShiftCodeGenerator())->generate();// in the generate method you can pass an int value like 5,4 or any to get the length of the code you want |
100 | | - } |
| 109 | +use ShiftechAfrica\CodeGenerator\ShiftCodeGenerator; |
| 110 | + |
| 111 | +/** |
| 112 | + * Generate a new Shift Code |
| 113 | + * |
| 114 | + * @return string |
| 115 | + */ |
| 116 | +public function generateCode() |
| 117 | +{ |
| 118 | + return (new ShiftCodeGenerator())->generate(); |
| 119 | + // Optionally pass an integer to set the random length, e.g. ->generate(5) |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +### Example Output |
| 124 | + |
| 125 | +```text |
| 126 | +1E1NKJDQVW |
101 | 127 | ``` |
| 128 | +- **1** = Year offset |
| 129 | +- **E** = Month letter |
| 130 | +- **1** = Day |
| 131 | +- **NKJDQVW** = Random string |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## 🧭 Version Guidance |
| 136 | + |
| 137 | +| Version | Status | Packagist | Namespace | Release | |
| 138 | +|----------|--------|------------|------------|----------| |
| 139 | +| **1.x** | ✅ Latest | `shiftechafrica/shift-code-generator` | `ShiftechAfrica\CodeGenerator` | [v1.5.2](https://github.com/SHIFTECH-AFRICA/shift-code-generator/releases/tag/v1.5.2) | |
| 140 | + |
| 141 | +--- |
102 | 142 |
|
| 143 | +## 🛡️ Security Vulnerabilities |
103 | 144 |
|
104 | | -## Version Guidance |
| 145 | +If you discover a security vulnerability, please contact: |
| 146 | +📧 **[bugs@shiftechafrica.com](mailto:bugs@shiftechafrica.com)** |
105 | 147 |
|
106 | | -| Version | Status | Packagist | Namespace | Repo | |
107 | | -|---------|------------|---------------------|--------------|---------------------------------------------------------------------------------------| |
108 | | -| 1.x | Latest | `shiftechafrica/shift-code-generator` | `ShiftechAfrica\CodeGenerator` | [v1.5.2](https://github.com/SHIFTECH-AFRICA/shift-code-generator/releases/tag/v1.5.2) | |
| 148 | +--- |
109 | 149 |
|
110 | | -[shift-code-generator-repo]: https://github.com/SHIFTECH-AFRICA/shift-code-generator.git |
| 150 | +## 📄 License |
111 | 151 |
|
112 | | -## Security Vulnerabilities |
113 | | - For any security vulnerabilities, please email to [Shiftech Africa](mailto:bugs@shiftechafrica.com). |
114 | | - |
115 | | -## License |
116 | | - This package is open-source, licensed under the [MIT license](https://opensource.org/licenses/MIT). |
| 152 | +This package is open-source software licensed under the |
| 153 | +**[MIT License](https://opensource.org/licenses/MIT)** |
0 commit comments