PHP Classes

PHP CSS manager: Parse and regenerate CSS stylesheets from arrays

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 375 All time: 6,703 This week: 297Up
Version License PHP version Categories
css-manager 1MIT/X Consortium ...5.4HTML, PHP 5, Parsers
Description Author

This class can parse and regenerate CSS stylesheets from arrays.

It can take a CSS stylesheet as a string and parses it to extract the list of style definitions and their property values into an array.

The class can also take array with the definition of a stylesheet and regenerate the corresponding CSS stylesheet string.

Picture of Daniel Takahashi
Name: Daniel Takahashi <contact>
Classes: 1 package by
Country: Brazil Brazil
Age: ???
All time rank: 3568281 in Brazil Brazil
Week rank: 508 Up28 in Brazil Brazil Up

Details

CssManager

<img title="Build Status Images" src="https://travis-ci.org/danielarbex/css-manager.svg">

CssManager is a class for easy management of class in css files with php.

Use

cssToArray()

/
 * @var $cssContent 
 * .class_name {
 *  width: 100%;
 * }
 */
$cssContent = file_get_contents(__DIR__ . '/css/css.css');
$cssManager->loadCss($cssContent)
           ->cssToArray();
           
/
 * array(1) {
 *  ["main"]=>
 *      array(1) {
 *      [".class_name"]=>
 *          array(1) {
 *          ["width"]=>
 *              string(5) " 100%"
 *          }
 *      }
 * }
 */
var_dump($cssManager->parsed);

arrayToCss()

/
 * @var $cssContent 
 * .class_name {
 *  width: 100%;
 * }
 */
$cssContent = file_get_contents(__DIR__ . '/css/css.css');
$cssString = $cssManager->loadCss($cssContent)
                     ->cssToArray()
                     ->arrayToCss();
           
/
 * string(32) ".class_name {
 *  width:  100%;
 * }
 */
var_dump($cssString);

Changing property

/
 * @var $cssContent 
 * .class_name {
 *  width: 100%;
 * }
 */
$cssContent = file_get_contents(__DIR__ . '/css/css.css');
$cssManager->loadCss($cssContent)
           ->cssToArray();
           
$cssManager->parsed['main']['.class_name']['float'] = ' left';
           
/
 * string(47) ".class_name {
 *  width:  100%;
 *  float:  left;
 * }
 */
var_dump($cssManager->arrayToCss());

License

MIT

Copyright (c) 2015 danielarbex

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Files folder imagetests (1 file, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageCssManager (1 file)

  Files folder image Files  /  src  /  CssManager  
File Role Description
  Plain text file CssManager.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagecss (1 file)
  Accessible without login Plain text file CssManagerTest.php Test Unit test script

  Files folder image Files  /  tests  /  css  
File Role Description
  Accessible without login Plain text file css.css Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:375
This week:0
All time:6,703
This week:297Up
For more information send a message to info at phpclasses dot org.