/** * Converts user rights mask into it's object representation * * @param array $raw_config Raw config * @param array $options Associative array of options * @return \ConfigContainer Config object */ public function objectify(array $raw_config = array(), array $options = array()) { if (!isset($options['access_table'])) { throw new Exception('Access table not provided. Cannot find user rights config!'); } $config = new ConfigContainer(); $access_table = $options['access_table']; $mask = $raw_config[0]; $len = strlen($mask); $bin = ''; $result = array(); for ($cnt = $len; $cnt > 0; $cnt--) { $bin = sprintf('%04b', hexdec($mask[$cnt - 1])) . $bin; } $len = strlen($bin); for ($cnt = $len - 1; $cnt >= 0; $cnt--) { if ($bin[$cnt] == '1') { $result[] = $len - $cnt - 1; } } $variables = array(); foreach ($result as $level) { if ($level === 0) { $variables[] = new ConfigVariable('superuser', true); } if (isset($access_table[$level]['privilege'])) { $variables[] = new ConfigVariable($access_table[$level]['privilege'], true); } } $section = new ConfigSection('privileges'); $section->addVariables($variables); $config->addSection($section); return $config; }
/** * Converts raw ini config into it's object representation * * @param array $raw_config Raw config * @param array $options Options * @return \ConfigContainer Config object */ public function objectify(array $raw_config = array(), array $options = array()) { $config = new ConfigContainer(); foreach ($raw_config as $section_name => $section_variables) { $section = new ConfigSection($section_name); foreach ($section_variables as $variable_name => $variable_value) { $section->addVariable(new ConfigVariable($variable_name, $variable_value)); } $config->addSection($section); } return $config; }
private function addSomeVariablesToSection(\ConfigVariable $variable, $amount = 0, $mutable = false) { for ($i = 0; $i < $amount; $i++) { if ($mutable) { $name = $variable->getVariable() . '_' . $i; $variable = new \ConfigVariable($name, $variable->getValue(), $variable->getComment()); } $this->object->addVariable($variable); } }
/** * Converts user rights array into it's object representation * * @param array $raw_config Raw config * @param array $options Associative array of options * @return \ConfigContainer Config object */ public function objectify(array $raw_config = array(), array $options = array()) { $config = new ConfigContainer(); $rights = $raw_config[0]; $access = AccessRights::getInstance(); $variables = array(); foreach ($rights as $right) { if ($right === 'full_access') { $variables[] = new ConfigVariable('superuser', true); } if ($access->checkPrivilege($right)) { $variables[] = new ConfigVariable($right, true); } } $section = new ConfigSection('privileges'); $section->addVariables($variables); $config->addSection($section); return $config; }
/** * Converts raw ui config into it's object representation * * @param array $raw_config Raw config * @param array $options Associative array of options * @return \ConfigContainer Config object */ public function objectify(array $raw_config = array(), array $options = array()) { $config = new ConfigContainer(); $sections = array(); foreach ($raw_config as $section_variable) { $section_name = $section_variable['section']; $variable_name = $section_variable['var']; $variable_value = $section_variable['value']; $variable_comment = $section_variable['description']; $variable = new ConfigVariable($variable_name, $variable_value, $variable_comment); if (isset($sections[$section_name])) { $sections[$section_name][] = $variable; } else { $sections[$section_name] = array($variable); } } foreach ($sections as $section_name => $section_variables) { $section = new ConfigSection($section_name); $section->addVariables($section_variables); $config->addSection($section); } return $config; }
public function __construct($vals = null) { if (!isset(self::$_TSPEC)) { self::$_TSPEC = array(1 => array('var' => 'name', 'type' => TType::STRING), 2 => array('var' => 'description', 'type' => TType::STRING), 3 => array('var' => 'items', 'type' => TType::LST, 'etype' => TType::STRUCT, 'elem' => array('type' => TType::STRUCT, 'class' => 'ConfigItem'))); } if (is_array($vals)) { if (isset($vals['name'])) { $this->name = $vals['name']; } if (isset($vals['description'])) { $this->description = $vals['description']; } if (isset($vals['items'])) { $this->items = $vals['items']; } } }
private function addSomeSectionsToConfig(ConfigSection $section, $amount = 0, $mutable = false) { for ($i = 0; $i < $amount; $i++) { if ($mutable) { $name = $section->getSectionName() . '_' . $i; $section = new ConfigSection($name); } $this->object->addSection($section); } }
/** * Adds config section to sections container * * @param ConfigSection $section Config sections to add */ public function addSection(ConfigSection $section) { $this->config_sections[$section->getSectionName()] = $section; }
public function read($input) { $xfer = 0; $fname = null; $ftype = 0; $fid = 0; $xfer += $input->readStructBegin($fname); while (true) { $xfer += $input->readFieldBegin($fname, $ftype, $fid); if ($ftype == TType::STOP) { break; } switch ($fid) { case 0: if ($ftype == TType::LST) { $this->success = array(); $_size46 = 0; $_etype49 = 0; $xfer += $input->readListBegin($_etype49, $_size46); for ($_i50 = 0; $_i50 < $_size46; ++$_i50) { $elem51 = null; $elem51 = new ConfigSection(); $xfer += $elem51->read($input); $this->success[] = $elem51; } $xfer += $input->readListEnd(); } else { $xfer += $input->skip($ftype); } break; default: $xfer += $input->skip($ftype); break; } $xfer += $input->readFieldEnd(); } $xfer += $input->readStructEnd(); return $xfer; }