Download the PHP package alnaggar/php-css-builder without Composer
On this page you can find all versions of the php package alnaggar/php-css-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alnaggar/php-css-builder
More information about alnaggar/php-css-builder
Files in alnaggar/php-css-builder
Package php-css-builder
Short Description A simple, fluent, structured CSS builder for PHP.
License MIT
Informations about the package php-css-builder
PhpCssBuilder
PHP CSS Builder allows you to programmatically generate CSS using a fluent, chainable API.
It supports:
- Standard CSS rulesets (selectors + declarations)
- Statement at-rules (e.g.
@import,@charset) - Block at-rules (e.g.
@media,@supports,@layer) - Nested CSS statements
- CSS comments
- Embedded CSS (
<style>blocks)
[!WARNING] This package does not perform any form of sanitization, validation, escaping, or filtering of input values.
It is designed purely as a CSS construction and formatting tool and will output exactly what the developer provides.
All responsibility for security, correctness, and safety of the generated output lies with the developer using this package, especially when handling user-provided or untrusted data.
Table of Contents
- Requirements
- Installation
- Usage & Architecture
- Contributing
- Credits
- License
Requirements
- PHP 7.3+
ext-pcrePHP extension
Installation
Install the package using Composer:
Usage & Architecture
This package is a programmatic CSS builder, not a parser, validator, or sanitizer. It allows you to compose CSS using PHP objects, mirroring the actual CSS grammar.
The design is intentionally split into small, focused classes, each representing a real CSS concept.
Core Concepts
-
Every statement is a
CssableEvery statement class implements the
Cssableinterface, meaning it can independently render CSS viatoCss(). -
CSS Is Built From Statements
The package models CSS as a tree of statements.
All CSS statements implement:
Statement Types
-
CssRuleset(Selector Blocks)Represents a standard CSS selector block (e.g.
:root,*::before,h1).Example:
Outputs:
Nesting support:
A ruleset can nest:
-
Other rulesets
- Block at-rules
This allows output suitable for CSS preprocessors:
Outputs:
-
-
CssBlockAtRuleRepresents at-rules that contain blocks (e.g.
@media,@supports,@layer,@page,@top-right).Example:
Outputs:
Nesting support:
A block at-rule can nest:
-
Rulesets
- Other block at-rules
Example:
Outputs:
-
-
CssStatementAtRule(Single-Line At-Rules)Represents non-block at-rules (e.g.
@import@charset@namespace).Example:
Outputs:
Nestable Statements
Only statements that implement NestableCssStatement can be nested.
These are:
CssRuleset
CssBlockAtRule
This ensures:
- Invalid CSS structures are not accidentally created
- Nesting mirrors real CSS grammar
- Output can safely target preprocessors
EmbeddedCss (HTML <style> Container)
EmbeddedCss is the final output container.
It:
- Collects multiple CSS statements
- Outputs a valid
<style>HTML block - Supports optional
<style>tag attributes
Complete Example:
Outputs:
Contributing
If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on the GitHub repository.
Credits
- Palestine banner and badge by Safouene1.
License
PhpCssBuilder is open-sourced software licensed under the MIT license.
All versions of php-css-builder with dependencies
ext-pcre Version *