⬡ Lacelium
⌘K
Version 2.x ▾
Utility Belt

Global Helpers

Lacelium provides a comprehensive collection of autoloaded helper functions and classes to streamline common operations—from environment inspection and database querying to UUID generation and template rendering.

Core Architecture Helpers

These functions are globally autoloaded and accessible in all controllers, models, middleware, console commands, and views without importing any namespaces.

Function Signature Return Type Description
env(string $key, mixed $default = null) mixed Retrieves an environment variable parsed from the root .env file.
app_config(string $key, mixed $default = null) mixed Accesses application configuration keys using dot notation (e.g. app_config('app.name')).
table(string $table, ?string $connection = null) Builder Begins a fluent database query builder instance for the designated table.
uuidV4() string Generates a cryptographically secure Version 4 UUID string.
auth_user() ?User Returns the currently authenticated user model instance, or null.
sqlar() SqlarStorage Returns the global SQLite Archiver virtual filesystem and compression instance.
route(string $name, array $params = []) string Generates a fully qualified URL for a named route.
base_path(string $path = '') string Resolves an absolute filesystem path relative to the application root directory.
base_url(?string $path = null) string Generates an absolute URL from the application base, auto-detecting scheme, host, and /public/ subfolder in Apache/XAMPP environments.
url(?string $path = '') string Alias for base_url(). Generates an application URL. Preferred shorthand for use in controllers and views.
asset(?string $path = '') string Generates a URL to a public asset. Intelligently resolves paths against known asset directories (css/, js/, fonts/, images/, etc.) and falls back to filesystem detection before defaulting to assets/.

Interactive Helper Playground

Test client-side representations of Lacelium's string and UUID utility methods in real time:

Result: building-high-performance-apis-with-lacelium
UUID v4 Generator (uuidV4()): 00000000-0000-4000-8000-000000000000

CommonHelper Static Utility

The App\Helpers\CommonHelper class provides enterprise utilities for data sanitization, file uploads, and formatting:

use App\Helpers\CommonHelper;

// Generate unique identifier
$uuid = CommonHelper::generate_uuid();

// Handle secure file persistence with random hash naming
$savedPath = CommonHelper::fileUpload($_FILES['avatar'], 'uploads/avatars');

// Date and Currency Formatting
$formatted = CommonHelper::formatCurrency(1499.50, 'USD');
$relative  = CommonHelper::timeAgo('2026-09-23 18:30:00');

Twig Template Helpers

These functions are pre-registered into Twig's runtime environment, allowing you to build dynamic layouts with minimal logic:

{# Generate named routes #}
Documentation Home

{# Output CSRF hidden input field #}
{{ csrf_field() }}

{# Inspect environment or application configurations #}
{% if app_config('app.debug') %}
    
Debug Mode Active
{% endif %} {# Auto-discover public CSS and JS asset bundles #} {% for js in public_asset_list('front', 'js') %} {% endfor %}

Helper Usage Guidelines

  • Stateless Pure Functions: Helpers should never maintain hidden static state or perform heavy network blocking without caching.
  • Configuration Over Hardcoding: Always access dynamic variables via env() or app_config() rather than hardcoding credentials or URLs.
  • Twig Separation of Concerns: Use Twig helpers only for rendering and presentation formatting; business logic belongs in Controllers and Services.

Next Steps