/** * Applies the theme to a particular control. * The control's class name and SkinID value will be used to * identify which skin to be applied. If the control's SkinID is empty, * the default skin will be applied. * @param TControl the control to be applied with a skin * @return boolean if a skin is successfully applied * @throws TConfigurationException if any error happened during the skin application */ public function applySkin($control) { $type = get_class($control); if (($id = $control->getSkinID()) === '') { $id = 0; } if (isset($this->_skins[$type][$id])) { foreach ($this->_skins[$type][$id] as $name => $value) { Prado::trace("Applying skin {$name} to {$type}", 'Prado\\Web\\UI\\TThemeManager'); if (is_array($value)) { switch ($value[0]) { case TTemplate::CONFIG_EXPRESSION: $value = $this->evaluateExpression($value[1]); break; case TTemplate::CONFIG_ASSET: $value = $this->_themeUrl . '/' . ltrim($value[1], '/'); break; case TTemplate::CONFIG_DATABIND: $control->bindProperty($name, $value[1]); break; case TTemplate::CONFIG_PARAMETER: $control->setSubProperty($name, $this->getApplication()->getParameters()->itemAt($value[1])); break; case TTemplate::CONFIG_TEMPLATE: $control->setSubProperty($name, $value[1]); break; case TTemplate::CONFIG_LOCALIZATION: $control->setSubProperty($name, Prado::localize($value[1])); break; default: throw new TConfigurationException('theme_tag_unexpected', $name, $value[0]); break; } } if (!is_array($value)) { if (strpos($name, '.') === false) { if ($control->hasProperty($name)) { if ($control->canSetProperty($name)) { $setter = 'set' . $name; $control->{$setter}($value); } else { throw new TConfigurationException('theme_property_readonly', $type, $name); } } else { throw new TConfigurationException('theme_property_undefined', $type, $name); } } else { // complex property $control->setSubProperty($name, $value); } } } return true; } else { return false; } }
/** * Configures a subproperty for a component. * @param TComponent component to be configured * @param string subproperty name * @param mixed subproperty initial value */ protected function configureSubProperty($component, $name, $value) { if (is_array($value)) { switch ($value[0]) { case self::CONFIG_DATABIND: // databinding $component->bindProperty($name, $value[1]); break; case self::CONFIG_EXPRESSION: // expression if ($component instanceof TControl) { $component->autoBindProperty($name, $value[1]); } else { $component->setSubProperty($name, $this->_tplControl->evaluateExpression($value[1])); } break; case self::CONFIG_TEMPLATE: $component->setSubProperty($name, $value[1]); break; case self::CONFIG_ASSET: // asset URL $url = $this->publishFilePath($this->_contextPath . DIRECTORY_SEPARATOR . $value[1]); $component->setSubProperty($name, $url); break; case self::CONFIG_PARAMETER: // application parameter $component->setSubProperty($name, $this->getApplication()->getParameters()->itemAt($value[1])); break; case self::CONFIG_LOCALIZATION: $component->setSubProperty($name, Prado::localize($value[1])); break; default: // an error if reaching here throw new TConfigurationException('template_tag_unexpected', $name, $value[1]); break; } } else { $component->setSubProperty($name, $value); } }