Processes the given menu config, structures it and checks for permissions

@param string|array $config Either the config file to load or the menu config as an array
@return array
499444
public function prepareMenuConfig($config): array
    {
        if (is_string($config)) {
            Configure::load($config);
            $config = Configure::read($this->_defaultConfig['configKey']);
        }

        foreach ($config as $mainItem => &$mainData) {
            if (isset($mainData['url']) && !$this->Auth->urlAllowed($mainData['url'])) {
                unset($config[$mainItem]);
                continue;
            }

            if (!empty($mainData['children']) && !$this->_hasAllowedChildren($mainData['children'])) {
                unset($config[$mainItem]);
                continue;
            }

            if (isset($mainData['shouldRender']) && !$mainData['shouldRender']()) {
                unset($config[$mainItem]);
                continue;
            }

            $this->_isItemActive($mainData);

            $visibleChildCount = 0;
            if (!empty($mainData['children'])) {
                $activeChildCount = 0;
                $visibleChildCount = count($mainData['children']);
                foreach ($mainData['children'] as $subItem => &$subData) {
                    if (isset($subData['shouldRender']) && !$subData['shouldRender']()) {
                        unset($mainData['children'][$subItem]);
                        $visibleChildCount--;
                        continue;
                    }

                    $allowed = (!isset($subData['url']) || (isset($subData['url']) && $this->Auth->urlAllowed($subData['url'])));

                    if ($allowed) {
                        if ($this->_isItemActive($subData)) {
                            $activeChildCount++;
                        }
                    } else {
                        $visibleChildCount--;
                    }
                }
                unset($subData);

                if ($activeChildCount > 1) {
                    foreach ($mainData['children'] as $subItem => &$subData) {
                        $subData['active'] = false;
                    }
                    unset($subData);
                }
            }

            // if the main item has no displayable children, remove it.
            if ($visibleChildCount === 0 && isset($config['children']) && count($config['children']) > 0) {
                unset($config[$mainItem]);
            }
        }
        unset($mainData, $subData);

        //set active status
        if (empty($this->_controllerActive)) {
            $this->_controllerActive = $this->_currentUrl['controller'];
        }
        foreach ($config as &$mainData) {
            $mainData['active'] = '';
            if (!empty($this->_actionActive) && !empty($mainData['url'])) {
                if ($mainData['url']['controller'] == $this->_controllerActive && $mainData['url']['action'] == $this->_actionActive) {
                    $mainData['active'] = true;
                }
            } elseif (!empty($mainData['url']) && $mainData['url']['controller'] == $this->_controllerActive) {
                $mainData['active'] = true;
            }
            if (!empty($mainData['children'])) {
                foreach ($mainData['children'] as &$subData) {
                    $subData['active'] = '';
                    if (!empty($this->_actionActive) && !empty($subData['url'])) {
                        if ($subData['url']['controller'] == $this->_controllerActive && $subData['url']['action'] == $this->_actionActive) {
                            $subData['active'] = true;
                            $mainData['active'] = true;
                        }
                    } elseif (!empty($subData['url']) && $subData['url']['controller'] == $this->_controllerActive) {
                        $mainData['active'] = true;
                    }
                }
            }
        }

        return $config;
    }
1032380
protected function processConfig(array $config)
    {
        // set defaults as an array if not provided
        if (!isset($config['defaults'])) {
            $config['defaults'] = [];
        }
        
        // Use the passed in command factory or a custom factory if provided
        $this->commandFactory = isset($config['command_factory'])
            ? $config['command_factory']
            : self::defaultCommandFactory($this->description);

        // Add event listeners based on the configuration option
        $emitter = $this->getEmitter();

        if (!isset($config['validate']) ||
            $config['validate'] === true
        ) {
            $emitter->attach(new ValidateInput($this->description));
        }

        $this->serializer = isset($config['serializer'])
            ? $config['serializer']
            : new Serializer($this->description);

        if (!isset($config['process']) ||
            $config['process'] === true
        ) {
            $emitter->attach(
                new ProcessResponse(
                    $this->description,
                    isset($config['response_locations'])
                        ? $config['response_locations']
                        : []
                )
            );
        }
    }
139425
protected function assignRole(array $config)
    {
        if (!($name = ArrayHelper::get($config, 'name')) || !($role  = $this->authManager->getRole($name))){
            return false;
        }
        if (!($child = ArrayHelper::get($config, 'child'))) {
            return $role;
        }
        if ($childRoles = ArrayHelper::get($child, 'roles')) {
            foreach ($childRoles as $name) {
                if ($roleChild = $this->authManager->getRole($name)) {
                    try {
                        $this->authManager->addChild($role, $roleChild);
                        $this->stdout("\tAssign child role: {$name} - success\n", Console::FG_GREEN);
                    } catch(\Exception $e) {
                        $this->stdout("\t- already exist\n");
                    }
                }
            }
        }
        if ($childPermissions = ArrayHelper::get($child, 'permissions')) {
            foreach ($childPermissions as $name) {
                if ($permissionChild = $this->authManager->getPermission($name)) {
                    try {
                        $this->authManager->addChild($role, $permissionChild);
                        $this->stdout("\tAssign child permission: {$name} - success\n", Console::FG_GREEN);
                    } catch(\Exception $e) {
                        $this->stdout("\t- already exist\n");
                    }
                }
            }
        }
        return $role;
    }
1314077
protected function assignPermissions(array $config) : void
    {
        $this->stdout("Assign permissions: " . count($config) . "\n", Console::FG_YELLOW);
        foreach ($config as $item) {
            if (!$permission = $this->assignPermission($item)) {
                $this->stdout("\t- error assigned permission: " . Json::encode($item) . "\n", Console::FG_RED);
            }
        }
    }
644136
public function navigation($config = array())
    {
        $config = array_merge($config, array(
          'tabs' => array(
              'about' => array(
                  'label' => 'COM-SETTINGS-ABOUT',
                  'url' => 'option=com_settings&view=about'
              ),
              'settings' => array(
                  'label' => 'COM-SETTINGS-SYSTEM',
                  'url' => 'option=com_settings&view=settings'
              ),
              'apps' => array(
                  'label' => 'COM-SETTINGS-APPS',
                  'url' => 'option=com_settings&view=apps'
              ),
              'assignments' => array(
                  'label' => 'COM-SETTINGS-ASSIGNMENTS',
                  'url' => 'option=com_settings&view=assignments'
              ),
              'plugins' => array(
                  'label' => 'COM-SETTINGS-PLUGINS',
                  'url' => 'option=com_settings&view=plugins'
              ),
              'templates' => array(
                  'label' => 'COM-SETTINGS-TEMPLATES',
                  'url' => 'option=com_settings&view=templates'
              ),
          ),
        ));

        if(!isset($config['selected'])) {
          $config['selected'] = 'settings';
        }

        return $this->_render('navigation', $config);
    }
897469
public static function getConfig(array $appConfig = []) : array
  {
    $configs = DEPConfig::$appdir . 'config' . DIRECTORY_SEPARATOR . '*.php';

    foreach (\glob($configs) as $config) {
      $service = require $config;

      if (is_array($service)) {
        $path = basename($config);
        $name = \substr($path, 0, strlen($path) - 4);
        $appConfig = array_merge($appConfig, [$name => $service]);
      }
    }

    return $appConfig;
  }
469376
public function configure(array $config = []) {
        $this->_config = [
            'request_path' => filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING),
            'request_queries' => filter_input(INPUT_SERVER, 'QUERY_STRINGS', FILTER_SANITIZE_STRING),
            'request_controller' => FALSE,
            'request_action' => FALSE,
            'root_dir' => NULL,
            'default_controller' => 'index',
            'default_action' => 'index'
        ] + $config;
        
        if ( $this->_config['request_controller'] === FALSE || $this->_config['request_action'] === FALSE) {
            $url = explode('/', $this->_config['request_path']);
            $this->_config['request_controller'] = array_shift($url);
            $this->_config['request_action'] = array_shift($url);
        }
    }
115466
public function postProcessConfiguration(array $config): array
    {
        $config = $this->fixUpViewConfig($config);

        $processor = new ConfigurationProcessor($this->container, $this->extension->getAlias());
        foreach (array_keys($config) as $key) {
            if ($key === 'system' || !in_array($key, self::SITEACCCESS_AWARE_SETTINGS, true)) {
                continue;
            }

            is_array($config[$key]) ?
                $processor->mapConfigArray($key, $config, ContextualizerInterface::MERGE_FROM_SECOND_LEVEL) :
                $processor->mapSetting($key, $config);
        }

        $designList = array_keys($config['design_list']);
        foreach ($config['system'] as $scopeConfig) {
            $this->validateCurrentDesign($scopeConfig['design'], $designList);
        }

        return $config;
    }
1122738
protected function processConfig(array $config)
    {
        $config['command_factory'] = self::defaultCommandFactory($this->getDescription());

        // we'll add our own patched processor after this
        parent::processConfig(
            array_merge(
                $config,
                [
                    'process' => false,
                ]
            )
        );

        if (!isset($config['process']) || $config['process'] === true) {
            $this->getEmitter()->attach(
                new ProcessResponse(
                    isset($config['debug']) ? $config['debug'] : false,
                    isset($config['response_locations']) ? $config['response_locations'] : []
                )
            );
        }
    }
964918
protected function normalize($config)
    {
        // Validate the config entry
        $this->validateRootElements($config);

        // For single value elements, normalize all class name and options, remove null entry
        foreach (array('vcs', 'version-generator', 'version-persister') as $configKey) {
            $value = $config[$configKey];
            if ($value == null) {
                unset($config[$configKey]);
                continue;
            }
            $config[$configKey] = $this->getClassAndOptions($value, $configKey);
        }

        // Same process but for list value elements
        foreach (array('prerequisites', 'pre-release-actions', 'post-release-actions') as $configKey) {
            foreach ($config[$configKey] as $key => $item) {

                // Accept the element to be define by key or by value
                if (!is_numeric($key)) {
                    if ($item == null) {
                        $item = array();
                    }
                    $item['name'] = $key;
                }

                $config[$configKey][$key] = $this->getClassAndOptions($item, $configKey.'_'.$key);
            }
        }

        return $config;
    }
769137
final public function get(array $appConfig): array
    {
        $defaults = $this->getSettings();

        $policiesFolder   = $defaults[static::KEY_POLICIES_FOLDER] ?? null;
        $policiesFileMask = $defaults[static::KEY_POLICIES_FILE_MASK] ?? null;

        assert(
            $policiesFolder !== null && empty(glob($policiesFolder)) === false,
            "Invalid Policies folder `$policiesFolder`."
        );
        assert(empty($policiesFileMask) === false, "Invalid Policies file mask `$policiesFileMask`.");
        $policiesPath = $policiesFolder . DIRECTORY_SEPARATOR . $policiesFileMask;

        $topPolicyName = $defaults[static::KEY_TOP_POLICY_NAME];

        $loader = (new AuthorizationRulesLoader($policiesPath, $topPolicyName));

        return $defaults + [
                static::KEY_POLICIES_DATA => $loader->getRulesData(),
            ];
    }
1194174
protected function getAuth(array $config)
	{
		if (isset($config['key']) && trim($config['key']) != '')
		{
			return array('key' => $config['key'], 'keyphrase' => $config['keyphrase']);
		}
		elseif (isset($config['keytext']) && trim($config['keytext']) != '')
		{
			return array('keytext' => $config['keytext']);
		}
		elseif (isset($config['password']))
		{
			return array('password' => $config['password']);
		}

		throw new \InvalidArgumentException('Password / key is required.');
	}
332129
protected function applyPermissions(array $config) : void
    {
        $this->stdout("Init permissions: " . count($config) . "\n", Console::FG_YELLOW);
        foreach ($config as $item) {
            if ($permission = $this->applyPermission($item)) {
                $this->stdout("\t- success: " . $permission->name . "\n", Console::FG_GREEN);
            } else {
                $this->stdout("\t- error config permission: " . Json::encode($item) . "\n", Console::FG_RED);
            }
        }
    }
1186745
protected function parseConfig($config)
    {
        if (array_key_exists('paths', $config) && array_key_exists('absolute', $config['paths'])) {
            $this->loadThemes($config['paths']['absolute']);
        }
        if (array_key_exists('active', $config)) {
            $this->setCurrent($config['active']);
        }
    }
337760
protected function parseProcessors(array $config): array
    {
        $processors = [];

        if (isset($config['processors']) && is_array($config['processors'])) {
            foreach ($config['processors'] as $processor) {
                $processors[] = $processor;
            }
        }

        return $processors;
    }
1110482
public function load(array $config)
    {
        $config = $this->getParsedConfig(
            $config,
            $this->config,
            $this->yamlConfigMap,
            $this->required
        );
        $this->setParsedConfig($config);

        return $this;
    }
115115
public function initialize(array $config)
    {
        $this->table('users');
        $this->displayField('email');
        $this->primaryKey('id');
        $this->addBehavior('Timestamp');

        $this->belongsTo('Users.Roles');

        $this->postType = [
            'formFields' => [
                'id',
                'email',
                'new_password' => [
                    'type' => 'password',
                ],
                'confirm_password' => [
                    'type' => 'password'
                ],
                'role_id',
                'active' => [
                    'type' => 'checkbox'
                ],
            ],
            'tableColumns' => [
                'id' => [],
                'email' => [],
                'role_id' => [
                    'get' => 'role.name'
                ],
                'active',
                'created' => []
            ],
            'filters' => [
                'email'
            ],
            'query' => function ($query) {

                $query->contain(['Roles']);

                return $query;
            },
        ];
    }