Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 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);
     }
 }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
 /**
  * @param array $values
  */
 public function __construct(array $values = [])
 {
     $defaultFont = __DIR__ . '/Resources/' . self::$DEFAULT_FONT;
     parent::__construct($values, ['font' => $defaultFont, 'size' => 22, 'color' => '#000000', 'align' => Drawer::TEXT_ALIGN_LEFT]);
 }
Пример #7
0
 /**
  * Adds sections from one config to another
  * 
  * @param ConfigContainer $primary_config Primary config
  * @param ConfigContainer $secondary_config Secondary config
  * @return \ConfigContainer Primary config
  */
 private static function appendOneConfigSectionsToAnother(ConfigContainer $primary_config, ConfigContainer $secondary_config)
 {
     $primary_config->addSections($secondary_config->getSections());
     return $primary_config;
 }