Download the PHP package csstool/css without Composer
On this page you can find all versions of the php package csstool/css. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package css
Another tool to parse CSS, minify and optimize CSS properties and values
https://igorfaria.github.io/CSSTool/
CSS Tool
Another CSS tool in CSS.
This is a CSS optimizer that parse CSS code into a set of associatives arrays.
You can manipulate the CSS with PHP and execute the magic of optimization, outputing the result as a text or save into a file.
Optimizations
- Minify CSS: Replace multiple spaces, break lines and last semicolons
- Optimize Values: Remove zeros when it is not needed (0.3s -> .3s)
- RGB to HEX: Colors rgb to hex (rgb(255,255,255) -> #fff)
- HLS to HEX: Colors hls to hex (hsl(236, 0%, 0%) -> #000)
- Optimize HEX: Abbreviation for hex (#ffcc00 -> #fc0)
- Improve Compatibility: Add prefixes (-webkit-, -moz-, -ms- and -o-)
- Optimize Syntax: Shorthand properties
Installing
You can install via Composer using:
Or you can download the files directly from github.com and include the files that are in the /src/ folder by your own means.
Usage
You can use the CSS Tool to optimize one or multiple CSS files, outputing as a text or saving into a file.
And of course you can do much more, just check the public methods and you can do see that there is a lot more to do with CSS Tool. If you have a task that involve manipulate CSS with PHP or just minify and optimize CSS, this is it.
Methods
These are the public methods:
Method set($cssInput)
$cssInput: string or array
It's used to set initial CSS. It can be used with an array of parsed CSS or the CSS code in a string, it will not append, it will replace the actual data.
You can use the set() method with string, this string could come from a file or whatever.
Output:
Or if you have an set of rules structured in an associative array, you can use that too:
Will output:
Method load($cssFilepath)
$cssFilepath: string with local path or remote URL to a CSS file
It's used load CSS from a file. The subsequently loaded files will be appended to the CSS already in the object.
Loading a CSS file from a local path:
Output:
Loading a CSS file from an URL:
Output:
Method save($cssFilepath)
$cssFilepath: string with pathname to the output file
It's used to save a file with the CSS defined in the object.
Saving into a file:
Method parse($cssStringInput)
$cssStringInput: string
Used to get a CSS in a string parsed into a set of rules in an associative array, to be manipulated and appended or prepended to the CSS later.
Example of parsing:
Output:
Method append($cssInput)
$cssInput: string or array
It's used to add CSS rules at the end of the CSS:
Output:
Method prepend($cssInput)
$cssInput: string or array
It's used to add CSS rules at the beginning of the CSS:
Output:
Method get($format='array',$minified=true)
$format: 'array', 'string' or 'json' $minified: true or false
It's used to get the CSS in the indicated format. The $minified attribute has no effect in the array format.
The default value of the get() parameter is 'array', so the return will be a set of associatives arrays:
Output:
If you need the CSS in a string you have to indicate the $format with the value 'string'
Output:
If you need the CSS in a string but not minified, you have to indicate the $minified atribute as false
Output:
You can also use it with the $format as 'json', but I think you kinda get it.
Configurations
- autoprefixer: (default: true) - add prefixes automatically to specified properties that require vendor prefixes
Example:
- optimize: (default: true) - optimize values and properties of CSS
Example of values not optimized:
After optimization:
If you need for for whatever reason disable the autoprefixer or the otimization, you can:
Tools
- CSS - Manipulate and Optimizes CSS
- Filer - Read, Create and Delete files
- Parser - Parse CSS string into array of parsed CSS
- Optimizer - Optimize properties and values of a parsed CSS
- Minifier - Minify the CSS output
Running the tests
They are in the /tests/ folder. You can run them through a web browser or using the command line.
To use the through browser you need to navigate to domain.com/tests/ :D
For using the command line, you need a to have PHP installed and execute the file show_source.php passing the parameter f=filename.php.
Example:
Hi, my name is Igor Faria :D