jbzoo/less
Composer 安装命令:
composer require jbzoo/less
包简介
PHP wrapper for any less-compilers
README 文档
README
A powerful PHP wrapper for wikimedia/less.php that provides enhanced LESS compilation with caching, advanced configuration options, and streamlined error handling.
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
- PHP 8.2 or higher
- Composer
Installation
composer require jbzoo/less
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
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
| Option | Type | Default | Description |
|---|---|---|---|
force |
bool | false |
Force recompilation on every call, ignoring cache |
debug |
bool | false |
Enable debug mode (future: source maps) |
root_url |
string | auto-detected | Base URL for asset references in CSS |
root_path |
string | auto-detected | Full 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 LESS |
Development
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
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests and ensure code quality (
make test-all) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT License. See LICENSE file for details.
jbzoo/less 适用场景与选型建议
jbzoo/less 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 94.34k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「css」 「less」 「stylesheet」 「less.js」 「lesscss」 「leafo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jbzoo/less 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jbzoo/less 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jbzoo/less 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
ZF2 module that allows automation of compiling your LESS with the extra of minifying the files.
A token based CSS Document parser and minifier written in PHP
Zend Framework 3+ module that provides assets bundling / caching
Define your own css rule-sets for the TYPO3 CMS backend.
统计信息
- 总下载量: 94.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 16
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-22