/** * Get a single configuration value that is stored (hopefully). * * @return mixed */ public function get($confKey) { if (!isset($this->cachedConfigValues[$confKey])) { if (!is_string($confKey)) { trigger_error('Config_base::get() unable to get configuration value, key given is not a string', E_USER_NOTICE); return false; } $configSplit = preg_split('#(?<!\\\\)/#', trim($confKey, '/')); foreach ($configSplit as $val) { $val = stripslashes($val); if (!isset($tmpConfVal) && isset($this->configValues[$val])) { $tmpConfVal = $this->configValues[$val]; } else { if (isset($tmpConfVal) && is_array($tmpConfVal) && isset($tmpConfVal[$val])) { $tmpConfVal = $tmpConfVal[$val]; } else { throw new Config_KeyNoExist('configuration value "' . stripslashes($confKey) . '" does not exist'); } } } zula_normalize($tmpConfVal); $this->cachedConfigValues[$confKey] = $tmpConfVal; } return $this->cachedConfigValues[$confKey]; }
/** * Normalizes a value, in such that strings that look like * bools will be convereted to a bool, ie - 'true' -> true * * Strings that look like ints will be cast to int, same * goes for floats. * * @param mixed $values * @return bool */ function zula_normalize(&$value) { if (is_array($value)) { $wasArray = true; } else { $value = array($value); $wasArray = false; } foreach ($value as $key => $val) { if (is_array($val)) { zula_normalize($val); } else { if (is_string($val)) { $val = trim($val); if ($val === 'true') { $val = true; } else { if ($val === 'false') { $val = false; } else { if (ctype_digit($val)) { $val = $val[0] === '0' ? $val : (int) $val; } else { if (is_numeric($val)) { $val = (double) $val; } } } } } } $value[$key] = $val; } if ($wasArray === false) { $value = $value[0]; } return true; }
/** * Gets all controllers in the layout file. If a sector is specified * then get only those attached to that sector. * * @param string $inSector * @return array */ public function getControllers($inSector = null) { if (empty($this->controllers)) { $cacheKey = 'layout_cntrlrs_' . $this->name; if (($this->controllers = $this->_cache->get($cacheKey)) == false) { $this->controllers = array(); foreach ($this->dom->getElementsByTagName('controller') as $node) { // Gather all configuration values $config = array('displayTitle' => true, 'customTitle' => null, 'htmlWrapClass' => null); foreach ($node->getElementsByTagName('config')->item(0)->childNodes as $confNode) { $config[$confNode->nodeName] = $confNode->nodeValue; } // 2.3.51 changed attr 'for_sector' into 'sector', use older if exists if (($sector = $node->getAttribute('for_sector')) == false) { $sector = $node->getAttribute('sector'); } // Store the controllers $cid = $node->getAttribute('id'); $this->controllers[$cid] = array('id' => $cid, 'order' => (int) $node->getAttribute('order'), 'sector' => strtoupper($sector), 'mod' => $node->getElementsByTagName('mod')->item(0)->nodeValue, 'con' => $node->getElementsByTagName('con')->item(0)->nodeValue, 'sec' => $node->getElementsByTagName('sec')->item(0)->nodeValue, 'config' => $config); } // Normalize, order and cache the controllers zula_normalize($this->controllers); uasort($this->controllers, array($this, 'orderControllers')); $this->_cache->add($cacheKey, $this->controllers); } } if ($inSector == null) { return $this->controllers; } else { $inSector = strtoupper($inSector); $controllers = array(); foreach ($this->controllers as $cntrlr) { if ($cntrlr['sector'] == $inSector) { $controllers[$cntrlr['id']] = $cntrlr; } } return $controllers; } }