Advertisement
Guest User

Untitled

a guest
Oct 18th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <?php
  2.  
  3. class PHP2CSS {
  4.    
  5.     private static $stylesheet = [];
  6.     private static $setContenttype = false;
  7.    
  8.     public static function contentType($contentType) {
  9.         self::$setContenttype = true;
  10.     }
  11.    
  12.     public static function addStyle() {
  13.         $args = func_get_args();
  14.         $num = func_num_args();
  15.        
  16.         for($i = 1; $i <= $num; ++$i) {
  17.             if($i % 2 != 0) {
  18.                 self::$stylesheet[] = [
  19.                     'name' => $args[$i-1],
  20.                     'styles' => $args[$i]
  21.                 ];
  22.             }
  23.         }
  24.     }
  25.    
  26.     public static function generateStylesheet() {
  27.         if(self::$setContenttype) {
  28.             header('Content-type: '.self::$setContenttype);
  29.         }
  30.         $nStyle = null;
  31.         foreach(self::$stylesheet as $style) {
  32.             $nStyle .= $style['name'].' {'."\n";
  33.                 foreach($style['styles'] as $keyword => $value) {
  34.                     $nStyle .= "\t".$keyword.': '.$value.";\n";
  35.                 }
  36.             $nStyle .= '}'."\n\n";
  37.         }
  38.        
  39.         echo $nStyle;
  40.     }
  41. }
  42.  
  43.  
  44. PHP2CSS::addStyle(
  45. 'body, html', [
  46.     'background-color' => 'rgba(0,0,0,0.05)',
  47.     'font-family' => 'Open Sans'
  48. ],
  49. '.class', [
  50.     'font-size' => '300px'
  51. ],
  52. '.class', [
  53.     'font-size' => '300px'
  54. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement