Download the PHP package emleons/sim-rating without Composer
On this page you can find all versions of the php package emleons/sim-rating. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download emleons/sim-rating
More information about emleons/sim-rating
Files in emleons/sim-rating
Package sim-rating
Short Description A secure, framework-agnostic 5-star rating rendering library for PHP.
License MIT
Informations about the package sim-rating
Sim-Rating - A Simple 5-Star Rating System for PHP
Documentation: https://emleonstz.github.io/sim-rating/
Sim-Rating is a lightweight,PHP library for displaying and calculating 5-star ratings. It supports multiple display formats (stars, bars, JSON) and is highly customizable and works with any php frame work.
Features
- Works in any framework: Laravel, Symfony, CodeIgniter, or plain PHP
- Multiple output formats (HTML stars, HTML bars, standalone SVG, JSON)
- Customizable colors, sizes and styles (validated & escaped)
- Calculate averages, totals and distributions
- Secure by default — all rendered values are escaped (XSS-safe)
- Type-safe API with backed enums (
StarKey,DisplayType) - Accessible markup (
role="img",aria-label) - Responsive and mobile-friendly
- Fully unit tested, statically analysed (PHPStan level 8) & style-checked (Pint)
Installation
Requirements: PHP 8.3+.
Install via Composer:
Basic Implementation
Output Formats
Customization Options
Star Display Options
Bar Display Options
All Configuration Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
type |
string | Yes | stars |
stars or bars |
color |
string | Yes | #ffc107 |
Main color |
size |
string | Yes | 1em |
Display size |
show_average |
bool | No | true |
Show average rating |
show_total |
bool | No | true |
Show total ratings |
show_summary |
bool | Yes | false |
Show summary text |
interactive |
bool | Yes | false |
Make ratings clickable |
bar_height |
string | No | 20px |
Bar thickness |
bar_spacing |
string | No | 8px |
Space between bars |
bar_show_percentages |
bool | No | true |
Show percentages |
Updating Options
Laravel Blade
Important Tips
- Rating keys are optional by default missing buckets count as
0. Enable thestrictoption if you want to require all five. - Set
show_summarybased on your display needs - Use
interactiveonly when you need user ratings - For bars, customize heights and spacing to match your design
- All
color/sizevalues are validated and escaped automatically — invalid values safely fall back to defaults.
Security
sim-rating escapes every value that ends up in the rendered markup, so it is safe to render data that originates from user input. Colour and size options are validated against strict allow-lists and fall back to safe defaults if they do not match.
Common Errors
Styling
Every rendered element carries a stable, namespaced BEM class so you can
style it from your own CSS file. This is the recommended way to customize the
look it needs no raw-CSS option and carries no injection risk. The legacy
sim-rating* classes are still present (deprecated) for backward compatibility.
Class map
| Element | BEM class | Legacy class (deprecated) |
|---|---|---|
| Root (every widget) | em-sim-rating |
sim-rating |
| Stars wrapper | em-sim-rating__stars |
— |
| Each star | em-sim-rating__star |
sim-rating-star |
| Average | em-sim-rating__average |
sim-rating-average |
| Total | em-sim-rating__total |
sim-rating-total |
| Bars root | em-sim-rating__bars |
sim-rating-bars-container |
| A bar row | em-sim-rating__bar |
sim-rating-bar |
| Bar label | em-sim-rating__bar-label |
sim-rating-bar-label |
| Bar track | em-sim-rating__bar-track |
sim-rating-bar-bg |
| Bar fill | em-sim-rating__bar-fill |
sim-rating-bar-fill |
| Bar percent | em-sim-rating__bar-percent |
sim-rating-bar-percent |
| Summary | em-sim-rating__summary |
sim-rating-summary |
| SVG root | em-sim-rating__svg |
sim-rating-svg |
Option 1 — include the canonical stylesheet
Add the shipped stylesheet once in your layout, then render with inline styles disabled:
Theme it with CSS custom properties on .em-sim-rating:
…or write full rules against the BEM classes:
Option 2 — target a single widget (uniqueness)
Give a widget a stable instance_id; it becomes a data-sim-rating-id
attribute and an em-sim-rating--{id} scope class:
Each widget's default inline CSS is scoped to its own id, so multiple widgets on one page never clash.
Note: there is intentionally no raw
custom_cssoption. Passing raw CSS through a value would re-introduce an injection vector. Style via the BEM classes / custom properties above instead.
Display Types
Stars
Bars
SVG
JSON Output
Advanced Usage
Type-safe display types
Per-render options (without mutating the instance)
Strict validation
Using in Frameworks
Laravel:
Symfony:
CodeIgniter 4:
Documentation
Full guides live at https://emleonstz.github.io/sim-rating/.
Preview locally:
Deploys automatically to GitHub Pages via Docs workflow
on pushes to main touching docs/**, mkdocs.yml, or requirements-docs.txt.
Testing
Run the full quality gate (code style + static analysis + tests):
Or run the pieces individually:
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for the local setup and quality bar, and SECURITY.md for how to report security vulnerabilities.
Changelog
See CHANGELOG.md for a history of notable changes.
License
MIT License. See LICENSE for more information.