TODO

@param $config
@return bool
155
public function save($config)
    {
        if (!file_put_contents($this->filename, Yaml::dump($config))) {
            return false;
        }
        return true;
    }
447630
protected function maybeInvalidConfig(Config $config): ?Error
    {
        $groups = (array) $config->get('groups');

        return empty($groups)
            ? ResultFactory::makeError($this, ['***** Experimental *****', 'Groups is empty.'])
            : null;
    }
1154576
public function check(array $config): bool
    {
        $this->notRunningPrograms = new Collection(Arr::get($config, 'programs', []));
        if ($this->notRunningPrograms->isEmpty()) {
            return true;
        }

        if (!$this->systemFunctions->isFunctionAvailable('shell_exec')) {
            $this->message = trans('self-diagnosis::checks.supervisor_programs_are_running.message.shell_exec_not_available');
            return false;
        }

        if ($this->systemFunctions->isWindowsOperatingSystem()) {
            $this->message = trans('self-diagnosis::checks.supervisor_programs_are_running.message.cannot_run_on_windows');
            return false;
        }

        $programs = $this->systemFunctions->callShellExec('supervisorctl status');
        if ($programs === null || $programs === '') {
            $this->message = trans('self-diagnosis::checks.supervisor_programs_are_running.message.supervisor_command_not_available');
            return false;
        }

        $restartedWithin = Arr::get($config, 'restarted_within', 0);
        $programs = explode("\n" , $programs);
        foreach ($programs as $program) {
            /*
             * Capture groups of regex:
             * (program name) (process id) (uptime hours) (minutes) (seconds)
             */
            $isMatch = preg_match(self::REGEX_SUPERVISORCTL_STATUS, trim($program), $matches);
            if ($isMatch) {
                if ($restartedWithin > 0) {
                    $totalSeconds = $matches[3] * 3600 + $matches[4] * 60 + $matches[5];
                    if ($totalSeconds > $restartedWithin) {
                        continue;
                    }
                }

                $this->notRunningPrograms = $this->notRunningPrograms->reject(function ($item) use ($matches) {
                    return $item === $matches[1];
                });
            }
        }

        return $this->notRunningPrograms->isEmpty();
    }
405284
private function getConfigDepth($config) {
        $total_depth = 1;

        foreach ($config as $data) {
            if (is_array($data)) {
                $depth = $this->getConfigDepth($data) + 1;

                if ($depth > $total_depth) {
                    $total_depth = $depth;
                }
            }
        }

        return $total_depth;
    }
1101803
protected function instantiateConfig($config = null)
    {
        if (is_null($this->config) || ! is_null($config)) {
            $this->config = ! is_null($config)
                ? $config
                : new Config($this->helper);
        }

        return $this->config;
    }
441343
public function loadConfig($config = null)
    {
        $config =
            !is_null($config) || !file_exists($this->configFile)
                ? $this->setConfigFile($this->getConfigFile($config))
                : $this->configFile;

        return $this->loadToLaravelConfig($config);
    }
93086
private function _prepareDir($config)
    {
        $directory = $this->generateDirectoryPath($config);
        $chmod = $config->get('Cache.SerializerPermissions');
        if ($chmod === null) {
            if (!@mkdir($directory) && !is_dir($directory)) {
                trigger_error(
                    'Could not create directory ' . $directory . '',
                    E_USER_WARNING
                );
                return false;
            }
            return true;
        }
        if (!is_dir($directory)) {
            $base = $this->generateBaseDirectoryPath($config);
            if (!is_dir($base)) {
                trigger_error(
                    'Base directory ' . $base . ' does not exist,
                    please create or change using %Cache.SerializerPath',
                    E_USER_WARNING
                );
                return false;
            } elseif (!$this->_testPermissions($base, $chmod)) {
                return false;
            }
            if (!@mkdir($directory, $chmod) && !is_dir($directory)) {
                trigger_error(
                    'Could not create directory ' . $directory . '',
                    E_USER_WARNING
                );
                return false;
            }
            if (!$this->_testPermissions($directory, $chmod)) {
                return false;
            }
        } elseif (!$this->_testPermissions($directory, $chmod)) {
            return false;
        }
        return true;
    }
508892
public function addConfig($config) {
        if (is_array($config)) {
            // array of paths to config files
            if (array_is_indexed($config)) {
                $this->addPaths($config);
            }
            // array of key value configs
            else {
                $this->addRuntimeConfig($config);
            }
        }
        // path to config file
        else if (is_string($config)) {
            $this->addPath($config);
        }
        // config object
        else if ($config instanceof IConfig) {
            $this->addRuntimeConfig($config);
        }

        return $this;
    }
686256
public static function getInstance($config = []){
        if(!(self::$_instance instanceof self)){
            self::$_instance = new self($config);
        }
        return self::$_instance;
    }
1320345
public function init($config = [])
    {
        $this->__init_database();

        $this->_db_name = (string)(($db = $config['session_db_name']) ? $db : $config['db_name']);

        if (!($this->db instanceof MysqlDb)) {
            return false;
        }

        // check if the sql table does exist
        $sql         = (string)"SELECT COUNT(`session_id`) FROM `{$this->_db_name}`.`user_session`";
        $session_res = $this->db->query((string)$sql);
        // if not try to create the session table
        if ($session_res === false) {
            $sql = (string)"CREATE TABLE `{$this->_db_name}`.`user_session` (
                    `session_id` varchar(100) NOT NULL default '',
                    `session_data` LONGTEXT NOT NULL,
                    `expires` int(11) NOT NULL default '0',
                    `created` DATETIME,
                    `updated` DATETIME,
                     PRIMARY KEY (`session_id`)
                    ) ENGINE=InnoDB Collate=utf8_general_ci";

            return $this->db->query((string)$sql);
        }

        return true;
    }
1157288
private function checkConfigKeys($config)
    {
        $config = array_change_key_case($config, CASE_LOWER);
        $config = $this->trimArray($config);

        foreach ($config as $key => $value) {
            if (array_key_exists($key, $this->config)) {
                $this->config[$key] = $value;
            } else {
                throw new \Exception('Key ' . $key . ' is either not part of the configuration or has incorrect Key name.
                check the config array key names to match your key names of your config array', 1);
            }
        }
    }
1273359
protected function resolve($config)
    {
        $name = $config['driver'];

        if (isset($this->instances[$name]) && $this->instances[$name]->getConfig() === $config) {
            return $this->instances[$name];
        }

        return $this->instances[$name] = PayMe::make($config);
    }
899813
public static function init($config = [])
    {
        $config = array_merge([
            'accepts' => [],
            'appendTo' => 'body',
            'showBar' => false,
            'editor' => Debugger::$editor,
            'maxDepth' => Debugger::$maxDepth,
            'maxLength' => Debugger::$maxLength,
            'scream' => true,
            'showLocation' => true,
            'strictMode' => true,
            'currentTime' => $_SERVER['REQUEST_TIME_FLOAT'] ?: microtime(true),
            'editorMapping' => isset(Debugger::$editorMapping) === true ? Debugger::$editorMapping : [],
        ], $config);

        Debugger::$editor = $config['editor'];
        Debugger::$maxDepth = $config['maxDepth'];
        Debugger::$maxLength = $config['maxLength'];
        Debugger::$scream = $config['scream'];
        Debugger::$showLocation = $config['showLocation'];
        Debugger::$strictMode = $config['strictMode'];
        Debugger::$time = $config['currentTime'];

        if (isset(Debugger::$editorMapping) === true) {
            Debugger::$editorMapping = $config['editorMapping'];
        }

        return $config;
    }
1202924
public function addFieldsFromConfig(array $config)
    {
        $i = 1;
        foreach ($config as $name => $field) {
            if (is_numeric($name) && !isset($field[$name]['type'])) {
                $fields = [];
                foreach ($field as $n => $f) {
                    $fields[$n] = Fields::create($n, $f);
                }
                if ($i > 1) {
                    $this->fieldsets[$this->current]->createGroup();
                }
                $this->fieldsets[$this->current]->addFields($fields);
                $i++;
            } else {
                $this->addField(Fields::create($name, $field));
            }
        }
        return $this;
    }
1323398
public function enabled( $config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'name'      => 'enabled',
            'attribs'   => array(),
            'deselect'  => true,
        ))->append(array(
            'selected'  => $config->{$config->name}
        ));

        $translator = $this->getObject('translator');
        $options    = array();

        $options[] = $this->option(array('label' => $translator->translate( 'Enabled' ) , 'value' => 1 ));
        $options[] = $this->option(array('label' => $translator->translate( 'Disabled' ), 'value' => 0 ));

        //Add the options to the config object
        $config->options = $options;

        return $this->optionlist($config);
    }
894626
public function booleanlist($config = array())
    {
        $translator = $this->getObject('translator');

        $config = new KObjectConfigJson($config);
        $config->append(array(
            'name'   	=> '',
            'attribs'	=> array(),
            'true'		=> $translator->translate('Yes'),
            'false'		=> $translator->translate('No'),
            'selected'	=> null,
            'translate'	=> true
        ));

        $name    = $config->name;
        $attribs = $this->buildAttributes($config->attribs);

        $html  = array();

        $html[] = '<div class="k-optionlist k-optionlist--boolean">';
        $html[] = '<div class="k-optionlist__content">';

        $extra = $config->selected ? 'checked="checked"' : '';
        $text  = $config->translate ? $translator->translate( $config->true ) : $config->true;

        $html[] = '<input type="radio" name="'.$name.'" id="'.$name.'1" value="1" '.$extra.' '.$attribs.' />';
        $html[] = '<label for="'.$name.'1"><span>'.$text.'</span></label>';

        $extra = !$config->selected ? 'checked="checked"' : '';
        $text  = $config->translate ? $translator->translate( $config->false ) : $config->false;

        $html[] = '<input type="radio" name="'.$name.'" id="'.$name.'0" value="0" '.$extra.' '.$attribs.' />';
        $html[] = '<label for="'.$name.'0"><span>'.$text.'</span></label>';

        $html[] = '<div class="k-optionlist__focus"></div>';
        $html[] = '</div>';
        $html[] = '</div>';

        return implode(PHP_EOL, $html);
    }
305455
public function initConfig($config)
    {  
        if (is_string($config)) {
            if (file_exists(($configFile = $config)) ||
                file_exists(($configFile = dirname(dirname(__FILE__)).self::DS.$config))
            ) {
                $config = $this->loadConfig($configFile);
            }
        } elseif (!is_array($config) && !is_object($config)) {
            throw new \Exception("Invalid configuration.", 1);
        }

        $this->mergeConfig($config);

        $this->doCallback('configurationInitiated', array($this->_configuration, $this));

        return $this;
    }