PHP Classes

CSS Magic: Compose CSS style sheets programatically

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 335 All time: 7,107 This week: 488Up
Version License PHP version Categories
css-magic 1.0.1Custom (specified...7HTML, PHP 7
Description 

Author

This package can compose CSS style sheets programatically.

The theme class composes style sheets. The selector class defines styles to be added to style sheets. The rule class defines properties to be added to styles.

The theme class assembles all the added styles and returns it as a single string.

Innovation Award
PHP Programming Innovation award nominee
May 2016
Number 11


Prize: One copy of DWebPro Standard License
Usually Web applications use CSS style sheets defined as static files or templates.

However, when your application needs to generate custom CSS that manipulates certain styles and properties, the static CSS approach is not very convenient.

This class provides means to define CSS programmatically by allowing to define style sheets, styles and properties as parameters defined at PHP run time.

Manuel Lemos
Picture of Everton da Rosa
  Performance   Level  
Name: Everton da Rosa <contact>
Classes: 17 packages by
Country: Brazil Brazil
Age: 43
All time rank: 78355 in Brazil Brazil
Week rank: 22 Up3 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php
if(isset($_GET['cor'])){
   
$theme = $_GET['cor'];
}else{
   
$theme = 'red';
}

$themes = [];

$themes['red']['background-color'] = '#ff3333';
$themes['red']['color'] = '#ffcccc';
$themes['red']['border-color'] = '#ff0000';

$themes['green']['background-color'] = '#00e600';
$themes['green']['color'] = '#ccffcc';
$themes['green']['border-color'] = '#008000';

$themes['blue']['background-color'] = '#4d94ff';
$themes['blue']['color'] = '#e6f0ff';
$themes['blue']['border-color'] = '#0052cc';

require
'../CSSMagic.php';

$mytheme = new CSSMagic\Theme('My first theme');

$selector1 = new CSSMagic\Selector('body');
$selector1->addRule(new CSSMagic\Rule('color', $themes[$theme]['color']));
$selector1->addRule(new CSSMagic\Rule('background-color', $themes[$theme]['background-color']));

$selector2 = new CSSMagic\Selector('#paragrafo');
$selector2->addRule(new CSSMagic\Rule('font-style', 'italic'));

$selector3 = new CSSMagic\Selector('.myclass');
$selector3->addRule(new CSSMagic\Rule('border', 'thin solid'));
$selector3->addRule(new CSSMagic\Rule('border-color', $themes[$theme]['border-color']));

$mytheme->addSelector($selector1);
$mytheme->addSelector($selector2);
$mytheme->addSelector($selector3);

header("Content-Type: text/css");

echo
$mytheme->getThemeString();


  Files folder image Files (124)  
File Role Description
Files folder imagedoc (1 directory)
Files folder imagesamples (2 files)
Accessible without login Plain text file CSSMagic.geany Data Auxiliary data
Accessible without login Plain text file CSSMagic.php Aux. Auxiliary script
Accessible without login Plain text file Doxyfile Data Auxiliary data
Accessible without login Plain text file LICENCE.pdf Data Auxiliary data
Accessible without login Plain text file LICENCE.txt Lic. License text
Plain text file Rule.php Class Class source
Plain text file Selector.php Class Class source
Plain text file Theme.php Class Class source

  Files folder image Files (124)  /  doc  
File Role Description
Files folder imagehtml (57 files, 1 directory)

  Files folder image Files (124)  /  doc  /  html  
File Role Description
Files folder imagesearch (57 files)
  Accessible without login HTML file annotated.html Doc. Documentation
  Accessible without login Plain text file annotated_dup.js Data Auxiliary data
  Accessible without login Image file arrowdown.png Icon Icon image
  Accessible without login Image file arrowright.png Icon Icon image
  Accessible without login Image file bc_s.png Icon Icon image
  Accessible without login Image file bdwn.png Icon Icon image
  Accessible without login HTML file classes.html Doc. Documentation
  Accessible without login HTML file class_c_s_s_magic_1_1_rule.html Doc. Documentation
  Accessible without login Plain text file class_c_s_s_magic_1_1_rule.js Data Auxiliary data
  Accessible without login HTML file class_c_s_s_magic_1_1_selector.html Doc. Documentation
  Accessible without login Plain text file class_c_s_s_magic_1_1_selector.js Data Auxiliary data
  Accessible without login HTML file class_c_s_s_magic_1_1_theme.html Doc. Documentation
  Accessible without login Plain text file class_c_s_s_magic_1_1_theme.js Data Auxiliary data
  Accessible without login Image file closed.png Icon Icon image
  Accessible without login Image file css.png Icon Icon image
  Accessible without login Image file doc.png Icon Icon image
  Accessible without login Plain text file doxygen.css Data Auxiliary data
  Accessible without login Image file doxygen.png Icon Icon image
  Accessible without login Plain text file dynsections.js Data Auxiliary data
  Accessible without login HTML file files.html Doc. Documentation
  Accessible without login Plain text file files.js Data Auxiliary data
  Accessible without login Image file folderclosed.png Icon Icon image
  Accessible without login Image file folderopen.png Icon Icon image
  Accessible without login HTML file functions.html Doc. Documentation
  Accessible without login HTML file functions_func.html Doc. Documentation
  Accessible without login HTML file functions_vars.html Doc. Documentation
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login Plain text file jquery.js Data Auxiliary data
  Accessible without login HTML file namespaces.html Doc. Documentation
  Accessible without login Plain text file namespaces.js Data Auxiliary data
  Accessible without login HTML file namespace_c_s_s_magic.html Doc. Documentation
  Accessible without login Plain text file namespace_c_s_s_magic.js Data Auxiliary data
  Accessible without login Plain text file navtree.css Data Auxiliary data
  Accessible without login Plain text file navtree.js Data Auxiliary data
  Accessible without login Plain text file navtreedata.js Data Auxiliary data
  Accessible without login Plain text file navtreeindex0.js Data Auxiliary data
  Accessible without login Image file nav_f.png Icon Icon image
  Accessible without login Image file nav_g.png Icon Icon image
  Accessible without login Image file nav_h.png Icon Icon image
  Accessible without login Image file open.png Icon Icon image
  Accessible without login Plain text file resize.js Data Auxiliary data
  Accessible without login Image file splitbar.png Data Auxiliary data
  Accessible without login Image file sync_off.png Icon Icon image
  Accessible without login Image file sync_on.png Icon Icon image
  Accessible without login Plain text file tabs.css Data Auxiliary data
  Accessible without login Image file tab_a.png Icon Icon image
  Accessible without login Image file tab_b.png Icon Icon image
  Accessible without login Image file tab_h.png Icon Icon image
  Accessible without login Image file tab_s.png Icon Icon image
  Accessible without login HTML file _c_s_s_magic_8php.html Doc. Documentation
  Accessible without login HTML file _c_s_s_magic_8php_source.html Doc. Documentation
  Accessible without login HTML file _rule_8php.html Doc. Documentation
  Accessible without login HTML file _rule_8php_source.html Doc. Documentation
  Accessible without login HTML file _selector_8php.html Doc. Documentation
  Accessible without login HTML file _selector_8php_source.html Doc. Documentation
  Accessible without login HTML file _theme_8php.html Doc. Documentation
  Accessible without login HTML file _theme_8php_source.html Doc. Documentation

  Files folder image Files (124)  /  doc  /  html  /  search  
File Role Description
  Accessible without login HTML file all_0.html Doc. Documentation
  Accessible without login Plain text file all_0.js Data Auxiliary data
  Accessible without login HTML file all_1.html Doc. Documentation
  Accessible without login Plain text file all_1.js Data Auxiliary data
  Accessible without login HTML file all_2.html Doc. Documentation
  Accessible without login Plain text file all_2.js Data Auxiliary data
  Accessible without login HTML file all_3.html Doc. Documentation
  Accessible without login Plain text file all_3.js Data Auxiliary data
  Accessible without login HTML file all_4.html Doc. Documentation
  Accessible without login Plain text file all_4.js Data Auxiliary data
  Accessible without login HTML file all_5.html Doc. Documentation
  Accessible without login Plain text file all_5.js Data Auxiliary data
  Accessible without login HTML file all_6.html Doc. Documentation
  Accessible without login Plain text file all_6.js Data Auxiliary data
  Accessible without login HTML file all_7.html Doc. Documentation
  Accessible without login Plain text file all_7.js Data Auxiliary data
  Accessible without login HTML file all_8.html Doc. Documentation
  Accessible without login Plain text file all_8.js Data Auxiliary data
  Accessible without login HTML file classes_0.html Doc. Documentation
  Accessible without login Plain text file classes_0.js Data Auxiliary data
  Accessible without login HTML file classes_1.html Doc. Documentation
  Accessible without login Plain text file classes_1.js Data Auxiliary data
  Accessible without login HTML file classes_2.html Doc. Documentation
  Accessible without login Plain text file classes_2.js Data Auxiliary data
  Accessible without login Image file close.png Icon Icon image
  Accessible without login HTML file files_0.html Doc. Documentation
  Accessible without login Plain text file files_0.js Data Auxiliary data
  Accessible without login HTML file files_1.html Doc. Documentation
  Accessible without login Plain text file files_1.js Data Auxiliary data
  Accessible without login HTML file files_2.html Doc. Documentation
  Accessible without login Plain text file files_2.js Data Auxiliary data
  Accessible without login HTML file files_3.html Doc. Documentation
  Accessible without login Plain text file files_3.js Data Auxiliary data
  Accessible without login HTML file functions_0.html Doc. Documentation
  Accessible without login Plain text file functions_0.js Data Auxiliary data
  Accessible without login HTML file functions_1.html Doc. Documentation
  Accessible without login Plain text file functions_1.js Data Auxiliary data
  Accessible without login HTML file functions_2.html Doc. Documentation
  Accessible without login Plain text file functions_2.js Data Auxiliary data
  Accessible without login HTML file functions_3.html Doc. Documentation
  Accessible without login Plain text file functions_3.js Data Auxiliary data
  Accessible without login HTML file functions_4.html Doc. Documentation
  Accessible without login Plain text file functions_4.js Data Auxiliary data
  Accessible without login HTML file functions_5.html Doc. Documentation
  Accessible without login Plain text file functions_5.js Data Auxiliary data
  Accessible without login Image file mag_sel.png Icon Icon image
  Accessible without login HTML file namespaces_0.html Doc. Documentation
  Accessible without login Plain text file namespaces_0.js Data Auxiliary data
  Accessible without login HTML file nomatches.html Doc. Documentation
  Accessible without login Plain text file search.css Data Auxiliary data
  Accessible without login Plain text file search.js Data Auxiliary data
  Accessible without login Plain text file searchdata.js Data Auxiliary data
  Accessible without login Image file search_l.png Icon Icon image
  Accessible without login Image file search_m.png Icon Icon image
  Accessible without login Image file search_r.png Icon Icon image
  Accessible without login HTML file variables_0.html Doc. Documentation
  Accessible without login Plain text file variables_0.js Data Auxiliary data

  Files folder image Files (124)  /  samples  
File Role Description
  Accessible without login Plain text file sample.php Aux. Auxiliary script
  Accessible without login Plain text file theme.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:335
This week:0
All time:7,107
This week:488Up