How rajeshmk/string-utils works
1. This is a small PHP 8.3 library package, not an application. The architecture is centered on two static utility classes under src/: StrTo for string normalization/manipulation and Hash for monotonic unique hash generation.
2. The public API is intentionally narrow:
- Hatchyu\String\StrTo exposes slugging, casing, path conversion, and UTF-8 substring helpers.
- Hatchyu\String\Hash exposes uniqueHash().
Consumers call these stateless-looking helpers directly; there is no service container, controller layer, database, or HTTP boundary.
3. StrTo is the main subsystem and likely contains the package’s core string-processing pipeline. Its job is to take technical or identifier-like input and normalize it into different output formats: slug, snake, kebab, dotted, headline/title case, StudlyCase, camelCase, upper/lower, and first-letter variants.
4. The slugging pipeline is the key architectural behavior. According to the README, it does more than simple delimiter replacement: it recognizes camelCase/StudlyCase boundaries, acronym boundaries, number-to-word transitions, punctuation like @, and path-like separators. The output is word-preserving and separator-aware rather than a flattened transliteration.
5. Compound words are an important internal boundary in StrTo. setCompoundWords() changes package-wide static state for the current PHP process, so slugging behavior can be globally altered for brand/domain-specific terms such as MySQL, iPhone, or GraphQL. This means the library has one mutable configuration axis, and all other helpers likely read from that shared list.
6. Unicode handling is a second major concern in StrTo. The README explicitly makes ext-intl optional but recommended for transliteration. That means the architecture has a portability fallback: basic splitting/formatting works without intl, while ASCII transliteration quality improves when intl is available. This materially affects output for non-Latin scripts and accented text.
7. StrTo::dotPath() is a distinct path-normalization helper, not just another alias. It converts slash-separated or namespace-like paths into dot notation while kebab-casing segments. That suggests the library is useful for code identifiers, file-like paths, and config-style dotted keys, not only for SEO slugs.
8. The casing helpers form a separate transformation family from slugging. words()/headline() preserve technical tokens better than generic title-casing, while studly() and camel() likely reuse the same tokenization engine and then reassemble tokens with casing rules. This reuse is an important diagram point: one tokenization core feeding multiple output formats.
9. Hash is independent from StrTo except for package namespace and utility style. Its uniqueHash($length = 40) produces a time-derived, monotonic identifier with random padding and a minimum length constraint of 24. Architecturally, this is a separate data path from string normalization and likely has no dependency on transliteration or compound-word rules.
10. There is no external infrastructure. No database, queue, cache, filesystem persistence, or network service is described. The only runtime dependency that materially changes behavior is PHP itself plus optional ext-intl.
11. The tests/ directory contains PHPUnit coverage for both major subsystems: StrToTest.php and HashTest.php. These tests are the behavioral contract for the library’s normalization rules, edge cases, and hash length/uniqueness guarantees. For architecture, they function as executable specification rather than integration tests.
12. The repository shape is conventional Composer packaging: composer.json defines the library metadata and autoloading, phpunit.xml.dist defines the test runner config, and README.md documents the API and examples. The package is designed to be embedded into other PHP codebases as a utility dependency, with static state being the main caveat.
13. If you are drawing the architecture diagram, the clearest boundaries are:
- External caller → StrTo public API
- StrTo tokenization/formatting core → output format helpers
- optional setCompoundWords() configuration → all subsequent StrTo transforms
- External caller → Hash::uniqueHash() → time/random-based string output
- PHPUnit tests validating both public surfaces
Main entry points: StrTo.php StrTo · Hash.php Hash · composer.json composer.json · phpunit.xml.dist phpunit.xml
Components 19
Public API
Stateless helper classes consumed directly by package users.
- StrTo · Main string normalization and formatting API.
src/StrTo.php - Hash · Monotonic unique hash generator.
src/Hash.php - Tokenize · Detects word boundaries in identifiers, acronyms, numbers, punctuation, and path-like input.
src/StrTo.php - Compound Words · Package-wide mutable compound-word list that changes slug and casing behavior.
src/StrTo.php - Transliterate · Optional intl-backed normalization for accented and non-Latin text.
src/StrTo.php - Slug · Builds separator-aware slugs from normalized tokens.
src/StrTo.php - Dot Path · Converts slash or namespace-like paths into dot notation with kebab-cased segments.
src/StrTo.php - Casing · Reassembles tokens as snake, kebab, dotted, headline, title, studly, camel, upper, lower, and first-letter variants.
src/StrTo.php - Words · Token-preserving word formatting used by headline/title-style helpers.
src/StrTo.php - Camel/Studly · Identifier-style output built from shared tokenization and casing rules.
src/StrTo.php - UTF-8 Substrings · Multibyte-safe substring helpers for string slicing.
src/StrTo.php - uniqueHash · Time-derived monotonic identifier with random padding and minimum length enforcement.
src/Hash.php
Package Support
Composer metadata, documentation, and test runner configuration.
- ext-intl · Improves transliteration quality when available.
- composer.json · Defines package metadata and autoloading.
composer.json - phpunit.xml · Configures the PHPUnit test runner.
phpunit.xml.dist - README · Documents API behavior, examples, and optional dependencies.
README.md
Tests
Executable specification for the public API behavior.
Other components
- PHP 8.3 · Primary language runtime for the library.
Connections 22
- PHP 8.3 → StrTo: runs on · StrTo executes within the PHP runtime.
- PHP 8.3 → Hash: runs on · Hash executes within the PHP runtime.
- StrTo → Tokenize: uses · Shared tokenization engine feeds most transforms.
- StrTo → Compound Words: reads · Compound-word state alters normalization results.
- StrTo → Transliterate: optionally uses · Unicode transliteration improves when ext-intl is present.
- Tokenize → Slug: feeds · Token boundaries are reassembled into slug output.
- Tokenize → Dot Path: feeds · Path segments are normalized before dot-path output.
- Tokenize → Casing: feeds · The same tokens are reused across casing variants.
- Tokenize → Words: feeds · Word formatting preserves technical tokens from the core splitter.
- Casing → Camel/Studly: specializes · Camel and Studly are identifier-oriented case outputs.
- Casing → UTF-8 Substrings: uses · Multibyte-safe slicing supports character-aware helpers.
- StrTo → UTF-8 Substrings: exposes · UTF-8 substring helpers are part of the public API.
- Hash → uniqueHash: exposes · uniqueHash is the single public entry point.
- ext-intl → Transliterate: enhances · Optional extension improves transliteration quality.
- composer.json → StrTo: autoloads · Composer metadata exposes the library classes.
- composer.json → Hash: autoloads · Composer metadata exposes the library classes.
- phpunit.xml → StrToTest: runs · PHPUnit configuration runs StrTo coverage.
- phpunit.xml → HashTest: runs · PHPUnit configuration runs Hash coverage.
- StrToTest → StrTo: validates · Tests document and lock the public string API.
- HashTest → uniqueHash: validates · Tests document and lock hash output guarantees.
- README → StrTo: documents · README describes normalization and casing helpers.
- README → Hash: documents · README describes unique hash generation.