Download the PHP package vsent/codegenerator without Composer

On this page you can find all versions of the php package vsent/codegenerator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package codegenerator

VsE/codegenerator - Dynamic Unique Code Generator for Laravel A robust, flexible, and pattern-based package to generate unique identifiers (codes) for various entities within your Laravel application (e.g., order numbers, invoice IDs, tracking codes). It features thread-safe sequence management, configurable patterns, and supports different types of unique components (sequential, random, UUIDs).

Installation Add to your project: If developing locally within your packages directory: Add the following to your main composer.json file in the autoload section:

"autoload": { "psr-4": { "App\": "app/", "vsent\\Codegenerator\": "packages/vse/codegenerator/src/" // Add this line } }, "repositories": [ { "type": "path", "url": "./packages/vse/codegenerator" } ]

Then run composer dump-autoload.

If installing via Packagist (after publishing your package):

composer require vse/codegenerator

Publish Configuration & Migrations: After installation, publish the package's configuration file and database migrations:

php artisan vendor:publish --tag=codegenerator-config php artisan vendor:publish --tag=codegenerator-migrations

This will create config/codegenerator.php and a migration file in database/migrations.

Run Migrations: Execute the migrations to create the code_sequences table:

php artisan migrate

Configuration (config/codegenerator.php) The config/codegenerator.php file (published in step 2) is where you define global settings and specific patterns for your codes. Refer to the extensive comments within that file for detailed explanations of each option and placeholder.

Usage You can use the CodeGenerator Facade to generate codes.

  1. Generating a Predefined Code Type This is the most common and recommended way to generate codes, using patterns defined in your config/codegenerator.php.

use vsent\Codegenerator\Facades\CodeGenerator;

// Generate an Order Code (uses 'order' pattern from config) try { $orderCode = CodeGenerator::generateFor('order'); // Example: ORD-250609-HQ-0001 } catch (\RuntimeException $e) { // Handle error (e.g., max attempts reached, database error) echo "Error generating order code: " . $e->getMessage(); }

// Generate an Invoice Number (uses 'invoice' pattern from config) try { $invoiceNumber = CodeGenerator::generateFor('invoice'); // Example: INV-202506-MUM-00001 } catch (\RuntimeException $e) { echo "Error generating invoice: " . $e->getMessage(); }

// Generate a Tracking ID (uses 'tracking_id' pattern, which generates UUIDs) try { $trackingId = CodeGenerator::generateFor('tracking_id'); // Example: TRK-a1b2c3d4-e5f6-7890-1234-567890abcdef } catch (\RuntimeException $e) { echo "Error generating tracking ID: " . $e->getMessage(); }

  1. Generating with Runtime Overrides You can temporarily override specific configuration settings for a single generation call.

use vsent\Codegenerator\Facades\CodeGenerator;

// Generate a Purchase Order code, but specify a different location for this instance try { $poCodeForLondon = CodeGenerator::generateFor('purchase_order', [ 'location' => 'LDN', // Override the default 'NYC' for this generation 'sequence_length' => 6 // Override default 5-digit sequence ]); // Example: PO/LDN/20250609/000001 } catch (\RuntimeException $e) { echo "Error generating PO code: " . $e->getMessage(); }

  1. Generating with an Inline (Ad-Hoc) Pattern For one-off or dynamic code structures not defined in the config, you can pass the pattern directly.

use vsent\Codegenerator\Facades\CodeGenerator;

// Generate a custom short code for an event registration try { $eventCode = CodeGenerator::generateFor('EVT-{DATE:md}-{RANDOM:4}', [ 'type' => 'EVENT', // Type used for placeholder and sequence tracking if applicable 'code_length' => 12 // Ensure total length is 12 ]); // Example: EVT-0609-ABCD0000 } catch (\RuntimeException $e) { echo "Error generating event code: " . $e->getMessage(); }

  1. Confirming Usage for Sequential Codes (Crucial!) For any code generated using the {SEQUENCE} placeholder, it's CRUCIAL to call confirmUsage() once the code has been successfully processed and committed in your application (e.g., after saving an order to the database). This updates the sequence in the code_sequences table, ensuring proper sequential numbering and preventing gaps in your confirmed sequences if a generated code isn't actually used.

use vsent\Codegenerator\Facades\CodeGenerator; use Illuminate\Support\Facades\DB; // Example of wrapping in a transaction

try { DB::beginTransaction();

$orderCode = CodeGenerator::generateFor('order');
// ... logic to save the order to your 'orders' table using $orderCode ...

if (CodeGenerator::confirmUsage($orderCode)) {
    DB::commit();
    echo "Order created and code confirmed: " . $orderCode;
} else {
    DB::rollBack();
    echo "Failed to confirm order code usage. Transaction rolled back.";
}

} catch (\RuntimeException $e) { DB::rollBack(); echo "Error during order creation: " . $e->getMessage(); }

// Note: For codes generated with {UUID} or {RANDOM}, confirmUsage() is generally not needed, // as their uniqueness is inherent and not managed by a shared sequence counter.

Contributing Feel free to open issues or pull requests on the GitHub repository.

License This package is open-sourced software licensed under the MIT license.


All versions of codegenerator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/contracts Version ^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vsent/codegenerator contains the following files

Loading the files please wait ...