A PHP reusable utilities library for Lacus Solutions' packages.
| Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |
- Type description: Human-readable type strings for error messages (primitives, arrays,
NaN,Infinity) - HTML escaping: Escape
&,<,>,",'for safe output and XSS mitigation - Random sequences: Generate numeric, alphabetic, or alphanumeric sequences of any length
- URI encoding: Percent-encode/decode URI components (path, query, fragment) per RFC 3986
- Zero dependencies: No production dependencies
composer require lacus/utils<?php
use Lacus\Utils\HtmlUtils;
use Lacus\Utils\SequenceGenerator;
use Lacus\Utils\SequenceType;
use Lacus\Utils\TypeDescriber;
use Lacus\Utils\UrlUtils;
TypeDescriber::describe(null); // 'null'
TypeDescriber::describe('hello'); // 'string'
TypeDescriber::describe(42); // 'integer number'
TypeDescriber::describe([1, 2, 3]); // 'number[]'
HtmlUtils::escape('Tom & Jerry'); // 'Tom & Jerry'
HtmlUtils::unescape('Tom & Jerry'); // 'Tom & Jerry'
SequenceGenerator::generate(10, SequenceType::Numeric); // e.g. '9956000611'
SequenceGenerator::generate(6, SequenceType::Alphabetic); // e.g. 'AXQMZB'
UrlUtils::encodeUriComponent('a b'); // 'a%20b'
UrlUtils::decodeUriComponent('a%20b'); // 'a b'All classes live under the Lacus\Utils namespace.
| Class | Method | Description |
|---|---|---|
TypeDescriber |
describe(mixed $value): string |
Type description for error messages |
HtmlUtils |
escape, unescape |
HTML entity escaping and decoding |
SequenceGenerator |
generate(int $size, SequenceType $type): string |
Random sequence generation |
SequenceType |
enum: Numeric, Alphabetic, Alphanumeric |
Sequence kind |
UrlUtils |
encodeUriComponent, decodeUriComponent |
URI component percent-encoding (RFC 3986) |
Same behaviour as JS describeType: null, string, boolean, integer number, float number, NaN, Infinity, Array (empty), number[], (number | string)[], object, resource, etc.
- escape(string $value): string — Escapes HTML special characters:
&→&,<→<,>→>,"→",'→'. Use for safe output and XSS mitigation. - unescape(string $value): string — Decodes those entities (reverse of
escape). Use only on previously escaped or trusted content; decoded output is not safe for direct insertion into HTML.
- Numeric: digits
0-9 - Alphabetic: uppercase
A-Z - Alphanumeric:
0-9andA-Z
- encodeUriComponent(string $value): string — Percent-encode a string for use as any URI component (path segment, query name/value, or fragment). E.g.
a/b→a%2Fb,a b→a%20b. - decodeUriComponent(string $value): string — Decode a percent-encoded URI component (reverse of
encodeUriComponent).