Returns a form that can be used to edit a store instance.

@param string $plugin
@param string $store
@return cachestore_addinstance_form
@throws coding_exception
165246
public static function get_edit_store_form($plugin, $store) {
        global $CFG; // Needed for includes.
        $plugins = core_component::get_plugin_list('cachestore');
        if (!array_key_exists($plugin, $plugins)) {
            throw new coding_exception('Invalid cache plugin used when trying to create an edit form.');
        }
        $factory = cache_factory::instance();
        $config = $factory->create_config_instance();
        $stores = $config->get_all_stores();
        if (!array_key_exists($store, $stores)) {
            throw new coding_exception('Invalid store name given when trying to create an edit form.');
        }
        $plugindir = $plugins[$plugin];
        $class = 'cachestore_addinstance_form';
        if (file_exists($plugindir.'/addinstanceform.php')) {
            require_once($plugindir.'/addinstanceform.php');
            if (class_exists('cachestore_'.$plugin.'_addinstance_form')) {
                $class = 'cachestore_'.$plugin.'_addinstance_form';
                if (!array_key_exists('cachestore_addinstance_form', class_parents($class))) {
                    throw new coding_exception('Cache plugin add instance forms must extend cachestore_addinstance_form');
                }
            }
        }

        $locks = self::get_possible_locks_for_stores($plugindir, $plugin);

        $url = new moodle_url('/cache/admin.php', array('action' => 'editstore', 'plugin' => $plugin, 'store' => $store));
        $editform = new $class($url, array('plugin' => $plugin, 'store' => $store, 'locks' => $locks));
        if (isset($stores[$store]['lock'])) {
            $editform->set_data(array('lock' => $stores[$store]['lock']));
        }
        // See if the cachestore is going to want to load data for the form.
        // If it has a customised add instance form then it is going to want to.
        $storeclass = 'cachestore_'.$plugin;
        $storedata = $stores[$store];
        if (array_key_exists('configuration', $storedata) && array_key_exists('cache_is_configurable', class_implements($storeclass))) {
            $storeclass::config_set_edit_form_data($editform, $storedata['configuration']);
        }
        return $editform;
    }
124206
protected function update_plugin_instance(assign_plugin $plugin, stdClass $formdata) {
        if ($plugin->is_visible()) {
            $enabledname = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
            if (!empty($formdata->$enabledname)) {
                $plugin->enable();
                if (!$plugin->save_settings($formdata)) {
                    print_error($plugin->get_error());
                    return false;
                }
            } else {
                $plugin->disable();
            }
        }
        return true;
    }
124113
public function add($plugin)
	{
		if (is_array($plugin))
		{
			$this->plugins = array_merge($this->plugins, $plugin);
		}
		else
		{
			$this->plugins[] = $plugin;
		}
		
		return $this;
	}
532961
public static function get_store_plugin_summaries() {
        $return = array();
        $plugins = core_component::get_plugin_list_with_file('cachestore', 'lib.php', true);
        foreach ($plugins as $plugin => $path) {
            $class = 'cachestore_'.$plugin;
            $return[$plugin] = array(
                'name' => get_string('pluginname', 'cachestore_'.$plugin),
                'requirementsmet' => $class::are_requirements_met(),
                'instances' => 0,
                'modes' => array(
                    cache_store::MODE_APPLICATION => ($class::get_supported_modes() & cache_store::MODE_APPLICATION),
                    cache_store::MODE_SESSION => ($class::get_supported_modes() & cache_store::MODE_SESSION),
                    cache_store::MODE_REQUEST => ($class::get_supported_modes() & cache_store::MODE_REQUEST),
                ),
                'supports' => array(
                    'multipleidentifiers' => ($class::get_supported_features() & cache_store::SUPPORTS_MULTIPLE_IDENTIFIERS),
                    'dataguarantee' => ($class::get_supported_features() & cache_store::SUPPORTS_DATA_GUARANTEE),
                    'nativettl' => ($class::get_supported_features() & cache_store::SUPPORTS_NATIVE_TTL),
                    'nativelocking' => (in_array('cache_is_lockable', class_implements($class))),
                    'keyawareness' => (array_key_exists('cache_is_key_aware', class_implements($class))),
                ),
                'canaddinstance' => ($class::can_add_instance() && $class::are_requirements_met())
            );
        }

        $instance = cache_config::instance();
        $stores = $instance->get_all_stores();
        foreach ($stores as $store) {
            $plugin = $store['plugin'];
            if (array_key_exists($plugin, $return)) {
                $return[$plugin]['instances']++;
            }
        }

        return $return;
    }
73418
private function installPluginIfNecessary(Plugin $plugin)
    {
        $pluginName = $plugin->getPluginName();
        $saveConfig = false;

        // is the plugin already installed or is it the first time we activate it?
        $pluginsInstalled = $this->getInstalledPluginsName();

        if (!$this->isPluginInstalled($pluginName)) {
            $this->executePluginInstall($plugin);
            $pluginsInstalled[] = $pluginName;
            $this->updatePluginsInstalledConfig($pluginsInstalled);
            $updater = new Updater();
            $updater->markComponentSuccessfullyUpdated($plugin->getPluginName(), $plugin->getVersion(), $isNew = true);
            $saveConfig = true;

            /**
             * Event triggered after a new plugin has been installed.
             *
             * Note: Might be triggered more than once if the config file is not writable
             *
             * @param string $pluginName The plugin that has been installed.
             */
            Piwik::postEvent('PluginManager.pluginInstalled', array($pluginName));
        }

        if ($saveConfig) {
            PiwikConfig::getInstance()->forceSave();
            $this->clearCache($pluginName);
        }
    }
1144934
public function setStore( &$store ) {
		if ( ! $this->isValidStore( $store ) ) {
			return;
		}

		$this->store = &$store;

		if ( ! isset( $this->store[ $this->store_key ] ) ) {
			$this->store[ $this->store_key ] = [
				static::CURRENT_KEY => [],
				static::NEXT_KEY => [],
			];
		}

		$this->flashed = $store[ $this->store_key ];
	}
1320045
public function setStoreId($store)
    {
        if ($store instanceof Store) {
            $store = $store->getId();
        }
        $this->storeId = $store;

        return $this;
    }
1152051
public function getCacheStore(): ?Store
    {
        if (!$this->hasCacheStore()) {
            $this->setCacheStore($this->getDefaultCacheStore());
        }
        return $this->cacheStore;
    }
1132567
public function editStore($store_id = null)
    {
        $this->setStore($store_id);
        $this->seTitleEditStore();
        $this->setBreadcrumbEditStore();

        $this->setData('store', $this->data_store);
        $this->setData('themes', $this->getListThemeStore());
        $this->setData('is_default', $this->isDefaultStore());
        $this->setData('can_delete', $this->canDeleteStore());
        $this->setData('countries', $this->getCountriesStore());
        $this->setData('collections', $this->getListCollectionStore());
        $this->setData('languages', $this->language->getList(array('enabled' => true)));

        $this->submitEditStore();
        $this->setDataEditStore();

        $this->setJsEditStore();
        $this->outputEditStore();
    }
513147
public static function dispatchPluggableApplication($plugin, $uri = null, $config = array())
    {
        $plugin = ucfirst($plugin);
        $config = array_merge(array(
            'rootDir'             => '', 
            'pluginDir'           => null,
            'resetConfig'         => true, 
            'overwriteDirs'       => true, 
            'overwriteFiles'      => true, 
            'checkPluginIsLoaded' => true,
            'bootstrapFile'       => 'Application.php'
        ), $config);
        
        if ($config['checkPluginIsLoaded'] && !self::isPluginLoaded($plugin)) {
            return false;
        }
        
        $uri = $uri ?: '';
        $rootDir = rtrim('/' . trim($config['rootDir'], '/'), '/');
        if ($config['pluginDir'] === null) {
            $pluginDir = self::$plugins[$plugin];
        } else {
            $pluginDir = rtrim($config['pluginDir'], '/');
        }
        
        $appDir = $pluginDir . $rootDir;
        if (!is_dir($appDir)) {
            throw new AtomikException("To be used as an application, the plugin '$plugin' must use a directory");
        }
        
        $overrideDir = self::findFile($plugin . $rootDir, self::path(self::get('atomik.dirs.overrides')));
        if ($overrideDir === false) {
            $overrideDir = 'overrides/' . $plugin . $rootDir;
        }
        
        if (!self::has('app.running_plugin')) {
            // saves user configuration
            self::set('userapp', self::get('app'));
        }
        self::set('app.running_plugin', $plugin); 
        self::set('request_uri', $uri);
        
        // resets the configuration but keep the layout
        if ($config['resetConfig']) {
            $layout = self::get('app.layout');
            self::reset();
            self::set('app.layout', $layout);
            self::set('app.routes', array());
        }
        
        // rewrite dirs
        $dirs = self::get('atomik.dirs');
        $dirs['actions'] = array($overrideDir . '/actions', $appDir . '/actions');
        $dirs['views'] = array($overrideDir . '/views', $appDir . '/views');
        
        $overwritableDirs = array(
            'layouts'   => array($overrideDir . '/layouts', $overrideDir . '/views', 
                                    $appDir . '/layouts', $appDir . '/views')
        );
        
        if ($config['overwriteDirs']) {
            $dirs = array_merge($dirs, $overwritableDirs);
        } else {
            $dirs = array_merge_recursive($overwritableDirs, $dirs);
        }
        
        // do not overwrite helpers
        $dirs['helpers'] = array_merge(
            array($overrideDir . '/helpers', $appDir . '/helpers'),
            (array) $dirs['helpers']
        );
        
        self::set('atomik.dirs', $dirs);
        
        // rewrite files
        if ($config['overwriteFiles']) {
            $files = self::get('atomik.files');
            $files['pre_dispatch'] = $appDir . '/pre_dispatch.php';
            $files['post_dispatch'] = $appDir . '/post_dispatch.php';
            self::set('atomik.files', $files);
        }
        
        $cancel = false;
        self::fireEvent('Atomik::Dispatchpluginapplication::Ready', array($plugin, &$uri, $config, &$cancel));
        if ($cancel) {
            return true;
        }
        
        $bootstrapFile = $appDir . '/' . $config['bootstrapFile'];
        if (file_exists($bootstrapFile)) {
            $continue = include $bootstrapFile;
            if ($continue === false) {
                return true;
            }
        }
        
        $cancel = false;
        self::fireEvent('Atomik::Dispatchpluginapplication::Start', array($plugin, &$uri, $config, &$cancel));
        if ($cancel) {
            return true;
        }
        
        return self::dispatch($uri, false);
    }
433873
public static function get_lock_configuration_from_data($plugin, $data) {
        global $CFG;
        $file = $CFG->dirroot.'/cache/locks/'.$plugin.'/lib.php';
        if (!file_exists($file)) {
            throw new coding_exception('Invalid cache plugin provided. '.$file);
        }
        require_once($file);
        $class = 'cachelock_'.$plugin;
        if (!class_exists($class)) {
            throw new coding_exception('Invalid cache plugin provided.');
        }
        if (array_key_exists('cache_is_configurable', class_implements($class))) {
            return $class::config_get_configuration_array($data);
        }
        return array();
    }
357855
public static function instance ( $store = 'MySQL', $options = array() )
	{
	    if (!OAuthStore::$instance)
	    {
			// Select the store you want to use
			if (strpos($store, '/') === false)
			{
				$class = 'OAuth1\\store\\OAuthStore'.$store;
				$file  = dirname(__FILE__) . '/store/'.$class.'.php';
			}
			else
			{
				$file  = $store;
				$store = basename($file, '.php');
				$class = $store;
			}

			OAuthStore::$instance = new $class($options);
			// if (is_file($file))
			// {
			// 	require_once $file;
				
			// 	if (class_exists($class))
			// 	{
			// 		OAuthStore::$instance = new $class($options);
			// 	}
			// 	else
			// 	{
			// 		throw new OAuthException2('Could not find class '.$class.' in file '.$file);
			// 	}
			// }
			// else
			// {
			// 	throw new OAuthException2('No OAuthStore for '.$store.' (file '.$file.')');
			// }
	    }
	    return OAuthStore::$instance;	
	}
392830
public function store_instance_summariers(array $stores, array $plugins) {
        $table = new html_table();
        $table->head = array(
            get_string('storename', 'cache'),
            get_string('plugin', 'cache'),
            get_string('storeready', 'cache'),
            get_string('mappings', 'cache'),
            get_string('modes', 'cache'),
            get_string('supports', 'cache'),
            get_string('locking', 'cache') . ' ' . $this->output->help_icon('locking', 'cache'),
            get_string('actions', 'cache'),
        );
        $table->colclasses = array(
            'storename',
            'plugin',
            'storeready',
            'mappings',
            'modes',
            'supports',
            'locking',
            'actions'
        );
        $table->data = array();

        $defaultstoreactions = get_string('defaultstoreactions', 'cache');

        foreach ($stores as $name => $store) {
            $actions = cache_administration_helper::get_store_instance_actions($name, $store);
            $modes = array();
            foreach ($store['modes'] as $mode => $enabled) {
                if ($enabled) {
                    $modes[] = get_string('mode_'.$mode, 'cache');
                }
            }

            $supports = array();
            foreach ($store['supports'] as $support => $enabled) {
                if ($enabled) {
                    $supports[] = get_string('supports_'.$support, 'cache');
                }
            }

            $info = '';
            if (!empty($store['default'])) {
                $info = $this->output->pix_icon('i/info', $defaultstoreactions, '', array('class' => 'icon'));
            }
            $htmlactions = array();
            foreach ($actions as $action) {
                $htmlactions[] = $this->output->action_link($action['url'], $action['text']);
            }

            $isready = $store['isready'] && $store['requirementsmet'];
            $readycell = new html_table_cell;
            if ($isready) {
                $readycell->text = $this->output->pix_icon('i/valid', '1');
            }

            $storename = $store['name'];
            if (!empty($store['default'])) {
                $storename = get_string('store_'.$store['name'], 'cache');
            }
            if (!$isready && (int)$store['mappings'] > 0) {
                $readycell->text = $this->output->help_icon('storerequiresattention', 'cache');
                $readycell->attributes['class'] = 'store-requires-attention';
            }

            $lock = $store['lock']['name'];
            if (!empty($store['lock']['default'])) {
                $lock = get_string($store['lock']['name'], 'cache');
            }

            $row = new html_table_row(array(
                $storename,
                get_string('pluginname', 'cachestore_'.$store['plugin']),
                $readycell,
                $store['mappings'],
                join(', ', $modes),
                join(', ', $supports),
                $lock,
                $info.join(', ', $htmlactions)
            ));
            $row->attributes['class'] = 'store-'.$name;
            if ($store['default']) {
                $row->attributes['class'] .= ' default-store';
            }
            $table->data[] = $row;
        }

        $html  = html_writer::start_tag('div', array('id' => 'core-cache-store-summaries'));
        $html .= $this->output->heading(get_string('storesummaries', 'cache'), 3);
        $html .= html_writer::table($table);
        $html .= html_writer::end_tag('div');
        return $html;
    }
397006
public static function purge_store($storename, cache_config $config = null) {
        if ($config === null) {
            $config = cache_config::instance();
        }

        $stores = $config->get_all_stores();
        if (!array_key_exists($storename, $stores)) {
            // The store does not exist.
            return false;
        }

        $store = $stores[$storename];
        $class = $store['class'];


        // We check are_requirements_met although we expect is_ready is going to check as well.
        if (!$class::are_requirements_met()) {
            return false;
        }
        // Found the store: is it ready?
        /* @var cache_store $instance */
        $instance = new $class($store['name'], $store['configuration']);
        if (!$instance->is_ready()) {
            unset($instance);
            return false;
        }
        foreach ($config->get_definitions_by_store($storename) as $id => $definition) {
            $definition = cache_definition::load($id, $definition);
            $definitioninstance = clone($instance);
            $definitioninstance->initialise($definition);
            $definitioninstance->purge();
            unset($definitioninstance);
        }

        return true;
    }
225362
public static function get_store_configuration_from_data(stdClass $data) {
        global $CFG;
        $file = $CFG->dirroot.'/cache/stores/'.$data->plugin.'/lib.php';
        if (!file_exists($file)) {
            throw new coding_exception('Invalid cache plugin provided. '.$file);
        }
        require_once($file);
        $class = 'cachestore_'.$data->plugin;
        if (!class_exists($class)) {
            throw new coding_exception('Invalid cache plugin provided.');
        }
        if (array_key_exists('cache_is_configurable', class_implements($class))) {
            return $class::config_get_configuration_array($data);
        }
        return array();
    }
864009
public function useStoreCreditConfig($store = null)
    {
        return $this->getScopeConfig()->isSetFlag(
            self::XML_PATH_STORE_CREDIT,
            ScopeInterface::SCOPE_STORE,
            $store
        );
    }
685850
public function addStoreFilter($store, bool $withAdmin = true)
    {
        if (!$this->getFlag('store_filter_added')) {
            if ($store instanceof Store) {
                $store = [$store->getId()];
            }

            if (!is_array($store)) {
                $store = [$store];
            }

            if ($withAdmin) {
                $store[] = Store::DEFAULT_STORE_ID;
            }

            $filterParams = [];

            foreach ($store as $storeId) {
                $filterParams[]['finset'] = $storeId;
            }

            $this->addFilter('store_id', $filterParams, 'public');
        }
        return $this;
    }