How to Generate License Keys in Lowercase Using SunLicense
Yes, you can generate lowercase license keys by setting the $case parameter to 'lower' when instantiating the SunLicense class.
The SunLicense class in the msbatal/php-license-key-generator repository provides flexible control over license key formatting, including the ability to output alphabetic characters in lowercase. This functionality is controlled through a dedicated case property that integrates seamlessly with the template-based generation system.
Understanding the Case Control Mechanism
The case sensitivity feature is implemented through the $case property defined in SunLicense.php at line 37. By default, this property is set to 'upper', which means all alphabetic characters in generated keys appear as uppercase letters.
When you instantiate the SunLicense class, the constructor accepts a fourth argument that specifies the desired case. As shown in lines 66-68 of SunLicense.php, this value is stored directly in the $case property:
public function __construct($prefix = null, $template = null, $case = 'upper', $count = 1)
{
$this->case = $case;
// ... additional initialization
}
During key generation, the license() method (lines 85-90) checks this flag for every alphabetic placeholder (X in the template). When $case is set to 'lower', the method emits random characters from the lowercase alphabet instead of the default uppercase set.
Generating Lowercase License Keys
To generate lowercase license keys, pass 'lower' as the third argument to the SunLicense constructor. The rest of the workflow—including prefix handling, custom templates, and batch generation—remains unchanged.
Basic Lowercase Key Generation
The simplest approach generates a single key using the default template with lowercase alphabetic characters:
require 'SunLicense.php';
$license = new SunLicense(null, null, 'lower');
echo $license->generate();
// Output example: 8a9b6c-ef12-3h4i-56jk7l
Custom Templates with Lowercase Letters
You can combine the lowercase case setting with custom templates and prefixes to match specific formatting requirements:
require 'SunLicense.php';
$prefix = 'MYAPP';
$template = 'X9XX-XX9X'; // 4 letters, 2 digits
$license = new SunLicense($prefix, $template, 'lower');
echo $license->generate();
// Output example: MYAPP-a9bc-de4f
Batch Generation of Lowercase Keys
To generate multiple lowercase keys at once, pass the desired count as the fourth constructor argument:
require 'SunLicense.php';
$license = new SunLicense(null, null, 'lower', 5);
$keys = $license->generate();
print_r($keys);
// Output: Array of 5 lowercase license strings
Summary
- The
SunLicenseclass supports both uppercase (default) and lowercase alphabetic output through the$caseproperty. - Set the case to
'lower'by passing it as the third argument in the constructor:new SunLicense($prefix, $template, 'lower'). - The case setting affects only alphabetic placeholders (
X) in templates; numeric characters (9) remain unchanged. - Source implementation resides in
SunLicense.phpat lines 37 (property), 66-68 (constructor), and 85-90 (generation logic).
Frequently Asked Questions
What is the default case for SunLicense keys?
By default, the SunLicense class generates keys using uppercase alphabetic characters. The $case property initializes to 'upper' in the class definition at line 37 of SunLicense.php. You must explicitly pass 'lower' as the third constructor argument to change this behavior.
Can I mix uppercase and lowercase in the same license key?
No, the SunLicense class applies a global case setting to all alphabetic characters in a generated key. The $case property controls the entire output; you cannot specify different cases for individual X placeholders within the same template. To achieve mixed case, you would need to post-process the generated string or modify the source code.
Does the case parameter affect numeric characters?
No, the case setting only impacts alphabetic placeholders (X) in the template. Numeric placeholders (9) always generate digits 0-9 regardless of the $case value. This is evident in the license() method implementation at lines 85-90 of SunLicense.php, where the case logic specifically branches for alphabetic character generation while numeric handling remains separate.
Where is the case logic implemented in the source code?
The case control logic is distributed across three locations in SunLicense.php: the property declaration at line 37 defines $case with a default value of 'upper'; the constructor at lines 66-68 accepts and stores the case parameter; and the generation logic at lines 85-90 within the license() method checks $this->case to determine whether to output uppercase or lowercase letters for each X placeholder.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →