*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule ConfigExists * * Check whether config exists. Use loader to load config and check whether loading fails * * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_ConfigExists extends WBPAT_Forms_Rule { /** * default config values * - loader config loader (File, ConfigTable) * - exists config must exist to be valid * - prefix config file/name prefix * * @var array */ protected $config = array( 'loader' => 'File', 'exists' => '1', 'prefix' => '' ); /** * config loader * @var WBConfig_Loader */ private $loader; /** * Initialize validation codes using gettext * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ public function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('wombat', '"[VALUE]" already exists.'), 2 => patI18n::dgettext('wombat', '"[VALUE]" is missing.'), ); return true; } /** * method called by patForms or any patForms_Element to validate the * element or the form. * * @todo reconsider str_replace for __default and __index * @param patForms_Element $form object * @return bool true on sucess */ public function applyRule(&$element, $type = PATFORMS_RULE_AFTER_VALIDATION) { $exists = intval($this->config['exists']); $value = trim($element->getValue(), '/ '); $info = array('value' => $value); $value = str_replace('*', '__default', $value); if ('site/page' == $this->prefix && empty($value)) { $value = '__index'; } $data = ''; $expire = array(); $this->loader = WBClass::create('WBConfig_Loader_' . $this->config['loader']); if ($this->loader->load($this->config['prefix'] . $value, $data, $expire, true)) { // config must exist if (0 < $exists) { return true; } $this->addValidationError(1, $info); return false; } // config must not exist if (1 > $exists) { return true; } $this->addValidationError(2, $info); return false; } } ?>