PHPackages                             jbzoo/less - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jbzoo/less

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jbzoo/less
==========

PHP wrapper for any less-compilers

7.0.2(9mo ago)594.4k3MITPHPPHP ^8.2CI passing

Since Feb 23Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/JBZoo/Less)[ Packagist](https://packagist.org/packages/jbzoo/less)[ RSS](/packages/jbzoo-less/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (4)Versions (24)Used By (3)

JBZoo / Less
============

[](#jbzoo--less)

[![CI](https://github.com/JBZoo/Less/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Less/actions/workflows/main.yml?query=branch%3Amaster) [![Coverage Status](https://camo.githubusercontent.com/747d773d932db96d3d3863c3818d59643d9b419e4498b6f0d509374e436b0550/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4a425a6f6f2f4c6573732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/JBZoo/Less?branch=master) [![Psalm Coverage](https://camo.githubusercontent.com/d445b6629f34cea85828e00ef9ade1ab527d6d8a5d7a8cb94ad04f7e36b2c19a/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f4c6573732f636f7665726167652e737667)](https://shepherd.dev/github/JBZoo/Less) [![Psalm Level](https://camo.githubusercontent.com/e8516afcfc9002d88aecbe5d75e6fc420204389f34f0051a5c2860d28483e71f/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f4c6573732f6c6576656c2e737667)](https://shepherd.dev/github/JBZoo/Less) [![CodeFactor](https://camo.githubusercontent.com/bd000a65d0bfef435c4483ade704c44abf54f1c95e76f9b77bd26f360bd87e31/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a627a6f6f2f6c6573732f6261646765)](https://www.codefactor.io/repository/github/jbzoo/less/issues)[![Stable Version](https://camo.githubusercontent.com/83cc4d7a366baaf4b2da95bdffed1f5980a26f501cc084cd914b5b34527f80c4/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f6c6573732f76657273696f6e)](https://packagist.org/packages/jbzoo/less/) [![Total Downloads](https://camo.githubusercontent.com/582c06f09cd28745e4facae22ed054624560031d3411f45aa620d918fcdd3aa1/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f6c6573732f646f776e6c6f616473)](https://packagist.org/packages/jbzoo/less/stats) [![Dependents](https://camo.githubusercontent.com/c8aa3d5fdefb7aedd51fcf7b50211239397ac67fc12001dc1517152f7f1bf468/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f6c6573732f646570656e64656e7473)](https://packagist.org/packages/jbzoo/less/dependents?order_by=downloads) [![GitHub License](https://camo.githubusercontent.com/7a6d18685a59f9b4848e1766f4a7201f2c73117701144709314a06b6caa5fd3b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a627a6f6f2f6c657373)](https://github.com/JBZoo/Less/blob/master/LICENSE)

A powerful PHP wrapper for [wikimedia/less.php](https://github.com/wikimedia/less.php) that provides enhanced LESS compilation with caching, advanced configuration options, and streamlined error handling.

Features
--------

[](#features)

- **Smart Caching**: Automatic file-based caching with TTL support
- **Flexible Configuration**: Comprehensive options for paths, variables, and compilation behavior
- **Global Variables**: Define LESS variables available across all compiled files
- **Auto-loading**: Automatically include mixin files before compilation
- **Custom Functions**: Register custom PHP functions for use in LESS files
- **Import Path Management**: Configure multiple import directories with URL mappings
- **Enhanced Error Handling**: Detailed error messages with context

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Composer

Installation
------------

[](#installation)

```
composer require jbzoo/less
```

Quick Start
-----------

[](#quick-start)

```
use JBZoo\Less\Less;

// Basic usage
$less = new Less();
$cssPath = $less->compile('/path/to/styles.less');

// With custom cache directory
$less = new Less(['cache_path' => './custom-cache']);
$cssPath = $less->compile('./assets/styles.less');
```

Advanced Configuration
----------------------

[](#advanced-configuration)

All configuration options are optional and can be customized based on your needs:

```
use JBZoo\Less\Less;

try {
    $less = new Less([
        // Compilation behavior
        'force'        => false,                    // Force recompilation on each call
        'debug'        => false,                    // Enable source maps (future feature)

        // Path configuration
        'root_url'     => 'http://site.com/',       // Root URL for CSS asset references
        'root_path'    => '/full/path/to/site',     // Full path to web root directory

        // LESS features
        'global_vars'  => [                         // Global variables available in all files
            'primary-color' => '#007bff',           // Becomes @primary-color: #007bff;
            'font-size'     => '14px',              // Becomes @font-size: 14px;
        ],

        'autoload'     => [                         // Files automatically included before compilation
            '/full/path/to/mixins.less',
            '/full/path/to/variables.less',
        ],

        'import_paths' => [                         // Directory mappings for @import statements
            '/full/path/to/assets/less/' => 'http://site.com/assets/less/',
            './relative/path/to/less/'   => './relative/path/to/less/',
        ],

        // Caching configuration
        'cache_path'   => './cache',                // Cache directory location
        'cache_ttl'    => 2592000,                  // Cache TTL in seconds (30 days)

        // Custom functions (advanced feature)
        'functions' => [
            'str-reverse' => function ($arg) {
                $arg->value = strrev($arg->value);
                return $arg;
            },
        ],
    ]);

    // Add import paths dynamically
    $less->setImportPath(
        '/additional/import/directory/',
        'http://site.com/additional/directory/'     // URL mapping (optional)
    );

    // Compile LESS files
    $cssPath1 = $less->compile('/full/path/to/styles.less');
    $cssPath2 = $less->compile('./relative/path/to/styles.less');
    $cssPath3 = $less->compile(
        './relative/path/to/styles.less',
        'http://site.com/custom/base/path/'         // Override base path for URLs
    );

} catch (JBZoo\Less\Exception $e) {
    echo 'Compilation error: ' . $e->getMessage();
}
```

Configuration Options
---------------------

[](#configuration-options)

OptionTypeDefaultDescription`force`bool`false`Force recompilation on every call, ignoring cache`debug`bool`false`Enable debug mode (future: source maps)`root_url`stringauto-detectedBase URL for asset references in CSS`root_path`stringauto-detectedFull filesystem path to web root`global_vars`array`[]`Global LESS variables available in all files`autoload`array`[]`LESS files to automatically include before compilation`import_paths`array`[]`Directory mappings for @import resolution`cache_path`string`'./cache'`Directory for storing compiled CSS files`cache_ttl`int`2592000`Cache time-to-live in seconds (30 days)`functions`array`[]`Custom PHP functions callable from LESSDevelopment
-----------

[](#development)

### Running Tests

[](#running-tests)

```
# Install dependencies
make update

# Run all tests and code quality checks
make test-all

# Run only PHPUnit tests
make test

# Run only code style checks
make codestyle
```

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Run tests and ensure code quality (`make test-all`)
4. Commit your changes (`git commit -m 'Add amazing feature'`)
5. Push to the branch (`git push origin feature/amazing-feature`)
6. Open a Pull Request

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) file for details.

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance58

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~159 days

Recently: every ~353 days

Total

23

Last Release

278d ago

Major Versions

1.1.3 → 2.0.02019-11-24

2.0.0 → 3.0.02020-02-19

3.0.0 → 4.0.02020-07-14

4.2.2 → 5.0.02022-06-06

5.0.0 → 7.0.02023-07-09

PHP version history (7 changes)1.0.0PHP &gt;=5.4

2.0.0PHP &gt;=7.1

4.0.0PHP &gt;=7.2

4.0.1PHP ^7.2

5.0.0PHP &gt;=7.4

7.0.0PHP ^8.1

7.0.2PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/75e6de2785f6d099699f430ff58404af4fc0e83060d2953028c9664a54704a5f?d=identicon)[smetdenis](/maintainers/smetdenis)

---

Top Contributors

[![SmetDenis](https://avatars.githubusercontent.com/u/1118678?v=4)](https://github.com/SmetDenis "SmetDenis (58 commits)")

---

Tags

assetscssjbzoolessphpwikimediacsslessstylesheetless.jslesscsscompilerpackagistjbzooleafolesscgpeasy

### Embed Badge

![Health badge](/badges/jbzoo-less/health.svg)

```
[![Health](https://phpackages.com/badges/jbzoo-less/health.svg)](https://phpackages.com/packages/jbzoo-less)
```

###  Alternatives

[wikimedia/less.php

PHP port of the LESS processor

12329.5M132](/packages/wikimedia-lessphp)[scssphp/scssphp

scssphp is a compiler for SCSS written in PHP.

62930.2M317](/packages/scssphp-scssphp)[mishal/iless

Less.js port to PHP

4738.2k3](/packages/mishal-iless)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
