00001 <?php
00002
00011 abstract class TKTheme extends SObject {
00012 protected $defaults = array();
00013
00014 public function __construct() {
00015 $this->initialize();
00016 }
00017
00032 public function getDefault($comp, $ctype, $prop) {
00033 if(isset($this->defaults[$comp.$ctype][$prop])) {
00034 return $this->defaults[$comp.$ctype][$prop];
00035 }
00036 else if(isset($this->defaults[$comp."default"][$prop])) {
00037 return $this->defaults[$comp."default"][$prop];
00038 }
00039 else {
00040 return false;
00041 }
00042 }
00043
00054 public function initComponent($comp) {
00055 $class = get_class($comp);
00056 $ctype = $comp->getThemeClass();
00057 foreach($comp->getProperties() as $p) {
00058 $val = $this->getDefault($class, $ctype, $p);
00059 if($val === false)
00060 continue;
00061
00062 $old = $comp->get($p);
00063 if(is_bool($old) || is_object($old))
00064 continue;
00065 if(is_string($old) && $old !== "")
00066 continue;
00067 $comp->append($p, $val, true);
00068 }
00069 }
00070
00094 protected function setThemeDefault($comp, $ctype, $prop, $val = null) {
00095 if($val === null) {
00096
00097 $val = $prop;
00098 $prop = $ctype;
00099 $ctype = 'default';
00100 }
00101 $key = $comp . $ctype;
00102 if(!isset($this->defaults[$key]))
00103 $this->defaults[$key] = array();
00104 $this->defaults[$key][$prop] = $val;
00105 }
00106
00123 protected function inherit($new, $old, $prop = true, $ctype = 'default') {
00124 $newKey = $new . $ctype;
00125 $oldKey = $old . $ctype;
00126 if(!isset($this->defaults[$oldKey]))
00127 return false;
00128 if(!isset($this->defaults[$newKey]))
00129 $this->defaults[$newKey] = array();
00130 if($prop === true) {
00131 if(!isset($this->defaults[$newKey]))
00132 $this->defaults[$newKey] = '';
00133 if(is_array($this->defaults[$oldKey]))
00134 $this->defaults[$newKey] = array_merge($this->defaults[$newKey], $this->defaults[$oldKey]);
00135 else
00136 $this->defaults[$newKey] .= $this->defaults[$oldKey];
00137 }
00138 else if(is_array($prop)) {
00139 foreach($prop as $p) {
00140 if(isset($this->defaults[$oldKey][$p])) {
00141 if(isset($this->defaults[$newKey][$p])) {
00142 if(is_array($this->defaults[$newKey][$p]))
00143 array_merge($this->defaults[$newKey][$p], $this->defaults[$oldKey][$p]);
00144 else
00145 $this->defaults[$newKey][$p] .= $this->defaults[$oldKey][$p];
00146 }
00147 }
00148 }
00149 }
00150 else if(is_string($prop) && isset($this->defaults[$oldKey][$prop]))
00151 $this->defaults[$newKey][$prop] = $this->defaults[$oldKey][$prop];
00152 else
00153 return false;
00154 return true;
00155 }
00156
00166 protected abstract function initialize();
00167 }
00168
00169 ?>