sabberworm/php-css-parser
A PHP library that parses CSS files into a manipulable data structure, allowing programmatic editing of rules and declarations before outputting optimized CSS. Supports custom charsets, strict parsing and optional multi-byte functions. Install via Composer.
Architecture fit
CSSList, RuleSet, Rule, Selector, Value) → render. This is useful for controlled server-side CSS transformations: selector prefixing/scoping, rule removal, tenant-specific overrides, size/value adjustments, and formatted output.Integration feasibility
composer require sabberworm/php-css-parser, instantiate Parser, traverse Document, render with OutputFormat. No service provider, migrations, or database changes are required.mbstring availability. The supplied metadata shows a future-dated release and zero reported dependents, so confirm the actual latest tag, Packagist constraints, and downstream usage before pinning.Technical risk
calc()/functions—must be validated against a representative corpus before production use.url() values and CSS injection concerns remain application responsibilities.Key questions
TPM recommendation
Conditional go for controlled, server-side CSS transformation where the input is known and round-trip behavior is tested. No-go for parsing untrusted or modern-CSS-heavy input at request time without a hardening phase and explicit fallback.
Stack fit
CssTransformer interface in a service provider and inject it where needed. Keep Parser, Settings, and OutputFormat construction inside that adapter.Migration path
getAllDeclarationBlocks(), getAllRuleSets(), getAllValues(), removeRule(), render()), and lock output formatting to avoid noisy diffs.Compatibility
mbstring, and Composer platform requirements before adoption.@supports, @layer, @container, @keyframes, and complex values.OutputFormat::createPretty() and createCompact() if output is user-visible or committed to source control.Sequencing
Maintenance
composer audit, and keep the adapter thin so the package can be replaced.Support
Scaling
Failure modes
Ramp-up
How can I help you explore Laravel packages today?