Fill the session with default data that are read from files.

@throws Anax\RemServer\Exception when bad configuration.

@return self
336536
public function init()
    {
        $json = [];
        foreach ($this->dataset as $file) {
            if (!(is_file($file) && is_readable($file))) {
                throw new Exception("File '$file' for dataset not readable.");
            }
            $content = file_get_contents($file);
            $key = pathinfo($file, PATHINFO_FILENAME);
            $json[$key] = json_decode($content, true);
        }

        $this->session->set(self::KEY, $json);
        return $this;
    }
1134374
protected function _load()
    {
        $file = new File($this->_file, "r");

        $data = @parse_ini_string($file->read(), true);
        if ($data === false) {
            throw new Exception\ParserErrorException(
                "Error parsing configuration file {$this->_file}"
            );
        }
        $this->_data = $data;
    }
718373
public function reset()
    {
        $this->data = [];

        // Get the default values for the class from the table.
        foreach ((array) $this->getFields() as $k => $v) {
            $this->data[$k] = null;
        }

        return $this;
    }
1266960
public function reset()
	{
		$this->uri 		   = null;
		$this->method 	   = self::GET;
		$this->headers 	   = array();
		$this->paramsGet   = array();
		$this->paramsPost  = array();
		$this->useRawData  = false;
		$this->dataRaw 	   = null;
		$this->httpVersion = self::HTTP_1;
		$this->curlOpts    = array();
		
		return $this;
	}
622745
public function init() {
        if (!extension_loaded('redis')) {
            throw new exception('sessionhandlerproblem', 'error', '', null, 'redis extension is not loaded');
        }

        if (empty($this->host)) {
            throw new exception('sessionhandlerproblem', 'error', '', null,
                    '$CFG->session_redis_host must be specified in config.php');
        }

        // The session handler requires a version of Redis with the SETEX command (at least 2.0).
        $version = phpversion('Redis');
        if (!$version or version_compare($version, '2.0') <= 0) {
            throw new exception('sessionhandlerproblem', 'error', '', null, 'redis extension version must be at least 2.0');
        }

        $this->connection = new \Redis();

        $result = session_set_save_handler(array($this, 'handler_open'),
            array($this, 'handler_close'),
            array($this, 'handler_read'),
            array($this, 'handler_write'),
            array($this, 'handler_destroy'),
            array($this, 'handler_gc'));
        if (!$result) {
            throw new exception('redissessionhandlerproblem', 'error');
        }

        // MDL-59866: Add retries for connections (up to 5 times) to make sure it goes through.
        $counter = 1;
        $maxnumberofretries = 5;

        while ($counter <= $maxnumberofretries) {

            try {

                $delay = rand(100000, 500000);

                // One second timeout was chosen as it is long for connection, but short enough for a user to be patient.
                if (!$this->connection->connect($this->host, $this->port, 1, null, $delay)) {
                    throw new RedisException('Unable to connect to host.');
                }

                if ($this->auth !== '') {
                    if (!$this->connection->auth($this->auth)) {
                        throw new RedisException('Unable to authenticate.');
                    }
                }

                if (!$this->connection->setOption(\Redis::OPT_SERIALIZER, $this->serializer)) {
                    throw new RedisException('Unable to set Redis PHP Serializer option.');
                }

                if ($this->prefix !== '') {
                    // Use custom prefix on sessions.
                    if (!$this->connection->setOption(\Redis::OPT_PREFIX, $this->prefix)) {
                        throw new RedisException('Unable to set Redis Prefix option.');
                    }
                }
                if ($this->database !== 0) {
                    if (!$this->connection->select($this->database)) {
                        throw new RedisException('Unable to select Redis database '.$this->database.'.');
                    }
                }
                $this->connection->ping();
                return true;
            } catch (RedisException $e) {
                $logstring = "Failed to connect (try {$counter} out of {$maxnumberofretries}) to redis ";
                $logstring .= "at {$this->host}:{$this->port}, error returned was: {$e->getMessage()}";

                // @codingStandardsIgnoreStart
                error_log($logstring);
                // @codingStandardsIgnoreEnd
            }

            $counter++;

            // Introduce a random sleep between 100ms and 500ms.
            usleep(rand(100000, 500000));
        }

        // We have exhausted our retries, time to give up.
        return false;
    }
320039
public function enaWordFiles()
    {
        $properties = $this->getProperties();
        $extString  = (!empty($properties['acceptedFiles'])) ? $properties['acceptedFiles'] : '';
        $wordExts   = $this->getWordExtensionConstant();
        foreach ($wordExts as $wordExt) {
            if (strpos($extString, $wordExt) === false) {
                $extString .= ','.$wordExt;
            }
        }
        $extString                      = substr($extString, 1);
        $properties                     = $this->getProperties();
        $properties['acceptedFiles']    = $extString;
        $this->setProperties($properties);
        return $this;
    }
931851
public function onReady()
    {
        $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance($this->config->redisname->value);
        $this->sessions = new ObjectStorage;
        $this->wss = new ObjectStorage;
        foreach (preg_split('~\s*;\s*~', $this->config->wssname->value) as $wssname) {
            $this->attachWss(WebSocketPool::getInstance(trim($wssname)));
        }
    }
1372327
public function fromDefaultLocations(): Configuration
    {
        foreach ($this->defaultFiles as $file) {
            try {
                return $this->fromUri(new Uri($file));
            } catch (\InvalidArgumentException $e) {
                continue;
            }
        }

        return new Configuration($this->applyMiddleware(Version3::buildDefault()));
    }
366426
public function load()
    {
        $this->checkSource();

        $this->spammers = $this->cacheSpammers(function () {
            return SpammerCollection::load(
                file($this->source, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
            );
        });

        return $this;
    }
133237
protected function requireFiles(): self
    {
        foreach ($this->_finders as $finder)
        {
            foreach ($finder as $file)
            {
                require_once $file->getRealpath();
            }
        }

        return $this;
    }
46800
public function load()
    {
        if (file_exists($this->filepath) && ($contents = file_get_contents($this->filepath))) {
            $yaml = new Parser();
            $config = $yaml->parse($contents);

            if (null === $config) {
                $config = array();
            }

            $processor = new Processor();
            $configDefinition = new ConfigDefinition();
            $processedConfiguration = $processor->processConfiguration(
                $configDefinition,
                $config
            );

            if (empty($processedConfiguration)) {
                throw new Exception(
                    'You need to specify at least one gaguge in the configuration file'
                );
            }

            return $processedConfiguration;
        }
        else {
            throw new \RuntimeException(sprintf('Configuration file does not exist or is not accessible %s',
                $this->filepath));
        }

    }
289859
protected function defaultData()
    {
        $context = Context::getInstance();

        $this->setData('extension', $context->getExtensionName());
        $this->setData('module', $context->getModuleName());
        $this->setData('action', $context->getActionName());

        if ($this->hasRequestParameter('uri')) {
            // inform the client of new classUri
            $this->setData('uri', $this->getRequestParameter('uri'));
        }

        if ($this->hasRequestParameter('classUri')) {
            // inform the client of new classUri
            $this->setData('uri', $this->getRequestParameter('classUri'));
        }

        if ($this->getRequestParameter('message')) {
            $this->setData('message', $this->getRequestParameter('message'));
        }
        if ($this->getRequestParameter('errorMessage')) {
            $this->setData('errorMessage', $this->getRequestParameter('errorMessage'));
        }

        $this->setData('client_timeout', $this->getClientTimeout());
        $this->setData('client_config_url', $this->getClientConfigUrl());
    }
718185
protected function readConfig()
    {
        if ($this->loaded == false) {
            $this->config = $this->loader->getDatas();
            $this->loaded = true;
        }

        return $this;
    }
866197
protected function configureDefaultData(){
        if (isset($this->properties['defaults']) && is_array($this->properties['defaults'])){
            foreach($this->properties['defaults'] as $data => $value){
                if (!isset($this->data[$data])){
                    $this->data[$data] = $value;
                }
            }
        }
        return $this;
    }
846344
public function refresh()
    {
        //Create the namespace if it doesn't exist
        $namespace = $this->getNamespace();

        if(!isset($_SESSION[$namespace])) {
            $_SESSION[$namespace] = array();
        }

        //Re-load the session containers
        foreach($this->_containers as $container)
        {
            $namespace = $this->getNamespace();
            $container->load($_SESSION[$namespace]);
        }

        return $this;
    }
1314616
public function overload(): self
    {
        $this->loader = new Loader($this->files);
        $this->loader->load();

        return $this;
    }
1167473
public function refresh()
    {
        list($resp, $usedOpts) = self::request(self::METHOD_GET, self::instanceUrl());
        $body = isset($resp['data'][0]) ? $resp['data'][0] : null;
        $this->install($body, $usedOpts);
        return $this;
    }