What Is the Default Template Used by SunLicense When No Template Is Provided?
When you instantiate SunLicense without providing a custom template, the class automatically uses the built‑in default pattern 'X9XX99-XX99-9X9X-99XX9X' defined in the $template property.
The msbatal/php-license-key-generator repository provides a lightweight PHP solution for generating software license keys. Understanding the default template used by SunLicense ensures you know exactly what format to expect when generating keys without custom configuration.
Default Template Structure and Syntax
The default template is declared as a private property in SunLicense.php at line 31:
private $template = 'X9XX99-XX99-9X9X-99XX9X';
This string uses placeholder characters that the generate() method substitutes at runtime:
- X – Replaced with a random letter (A–Z). The case depends on the
$caseparameter (upperorlower). - 9 – Replaced with a random digit (0–9).
- - – Literal dash used as a separator between sections.
When processed, the template produces keys such as Q7JH56-QR78-0U5L-23MN5K.
How the Default Template Is Applied
The SunLicense constructor accepts a $template parameter as its second argument. If you pass null or omit the argument entirely, the class falls back to the default value stored in the $template property.
// Uses the default template 'X9XX99-XX99-9X9X-99XX9X'
$license = new SunLicense();
echo $license->generate();
// Output example: AB3CD7-AB34-7C9D-99EF1G
The constructor signature is:
public function __construct($prefix = null, $template = null, $case = 'upper', $count = 1)
Because the default value for $template is null, the internal logic uses the pre‑defined property value rather than an empty string.
Customizing the License Key Format
You can override the default template used by SunLicense by passing a custom pattern string to the constructor. This allows you to define different segment lengths, separator styles, or character distributions.
// Custom template with three segments
$customTemplate = 'XXX-999-XXX';
$license = new SunLicense(null, $customTemplate);
print_r($license->generate());
// Possible output: ["ABC-123-XYZ"]
When generating multiple keys with a prefix and specific case settings, the custom template (or default) is applied to every generated key:
// Generate 3 keys with "PROD" prefix and lowercase letters
$license = new SunLicense('PROD', null, 'lower', 3);
print_r($license->generate());
// Example output:
// [
// "prod-g5hj23-kw09-5m1n-78pqr7",
// "prod-d8kl90-za12-3b4c-56def8",
// "prod-mn4op7-qw23-1z2x-9c8v7b"
// ]
Summary
- The default template used by SunLicense is
'X9XX99-XX99-9X9X-99XX9X', defined in the$templateproperty ofSunLicense.phpat line 31. - X placeholders become random letters; 9 placeholders become random digits; hyphens are literal separators.
- If the constructor receives
nullfor the$templateargument, the class automatically uses this built‑in pattern. - You can override the default by passing any custom string to the constructor to control segment length and formatting.
Frequently Asked Questions
What characters does the SunLicense default template use?
The default template 'X9XX99-XX99-9X9X-99XX9X' uses three types of characters: X (which generates a random letter A–Z), 9 (which generates a random digit 0–9), and literal hyphens that act as separators between segments.
How do I override the default template in SunLicense?
Pass a custom pattern string as the second argument to the SunLicense constructor. For example: $license = new SunLicense(null, 'XXX-999-XXX'); replaces the default template with your custom format. If you pass null, the class uses the built‑in default.
What do X and 9 represent in SunLicense templates?
In any template string provided to SunLicense, X is a placeholder for a random alphabetic character and 9 is a placeholder for a random numeric character. The generate() method iterates through the template and substitutes each placeholder with a randomly selected character from the appropriate set.
Where is the default template defined in the source code?
The default template is defined as a private property in the file SunLicense.php at line 31 within the msbatal/php-license-key-generator repository. The specific declaration is private $template = 'X9XX99-XX99-9X9X-99XX9X';.
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 →