CSSMagic  1.0
Criação de CSS dinâmico sem uso de pré-processadores, apenas com PHP 7
Theme.php
Go to the documentation of this file.
1 <?php
2 
3 namespace CSSMagic;
4 
8 class Theme{
9 
13  protected $theme_name = '';
14 
18  protected $selectors = [];
19 
25  public function __construct(string $theme_name){
26  $this->theme_name = $theme_name;
27  }
28 
33  public function getThemeName() : string {
34  return $this->theme_name;
35  }
36 
42  public function addSelector(Selector $selector){
43  $this->selectors[$selector->getSelectorId()] = $selector;
44  }
45 
50  public function getAllSelectors() : array {
51  return $this->selectors;
52  }
53 
59  public function getSelector(string $selector_id) : CSSMagic\Selector {
60  return $this->selectors[$selector_id];
61  }
62 
68  public function hasSelector(string $selector_id) : boolean {
69  return key_exists($selector_id, $this->selectors);
70  }
71 
77  public function removeSelector(string $selector_id){
78  unset($this->selectors[$selector_id]);
79  }
80 
85  public function getThemeString(){
86  $css_str = '/* Gerado com o CSSMagic :-)'.PHP_EOL;
87  $css_str .= " * {$this->getThemeName()}".PHP_EOL;
88  $css_str .= " */".PHP_EOL.PHP_EOL;
89 
90  foreach($this->selectors as $selector){
91  $css_str .= $selector->getSelectorId().' ';
92  $css_str .= '{'.PHP_EOL;
93 
94  $rules = $selector->getAllRules();
95  foreach($rules as $rule){
96  $css_str .= "\t{$rule->getRuleId()}: {$rule->getRuleValue()};".PHP_EOL;
97  }
98 
99  $css_str .= '}'.PHP_EOL;
100 
101  $css_str .= PHP_EOL;
102  }
103 
104  return $css_str;
105  }
106 
107 }
getSelector(string $selector_id)
Definition: Theme.php:59
getAllSelectors()
Definition: Theme.php:50
getThemeName()
Definition: Theme.php:33
Definition: Rule.php:3
__construct(string $theme_name)
Definition: Theme.php:25
getThemeString()
Definition: Theme.php:85
addSelector(Selector $selector)
Definition: Theme.php:42
removeSelector(string $selector_id)
Definition: Theme.php:77
hasSelector(string $selector_id)
Definition: Theme.php:68