Loads ini environment for a specific siteaccess

eg: $ini = eZSiteAccess::getIni( 'eng', 'site.ini' );

@since 4.4
@param string $siteAccess
@param string $settingFile
@return eZINI
767716
static function getIni( $siteAccess, $settingFile = 'site.ini' )
    {
        // return global if siteaccess is same as requested or false
        if ( isset( $GLOBALS['eZCurrentAccess']['name'] )
          && $GLOBALS['eZCurrentAccess']['name'] === $siteAccess )
        {
            return eZINI::instance( $settingFile );
        }
        else if ( !$siteAccess )
        {
            return eZINI::instance( $settingFile );
        }

        // create a site ini instance using $useLocalOverrides = true
        $siteIni = new eZINI( 'site.ini', 'settings', null, null, true );

        // create a dummy access definition (not used as long as $siteIni is sent to self::load() )
        $access = array( 'name' => $siteAccess,
                         'type' => eZSiteAccess::TYPE_STATIC,
                         'uri_part' => array() );

        // Load siteaccess but on our locale instance of site.ini only
        $access = self::load( $access, $siteIni );

        // if site.ini, return with no further work needed
        if ( $settingFile === 'site.ini' )
        {
            return $siteIni;
        }

        // load settings file with $useLocalOverrides = true
        $ini = new eZINI( $settingFile,'settings', null, null, true );
        $ini->setOverrideDirs( $siteIni->overrideDirs( false ) );
        $ini->load();

        return $ini;
    }
405583
private function getMainLanguagesBySiteAccesses(array $siteAccesses)
    {
        $languages = array();

        foreach ($siteAccesses as $siteAccess) {
            $languageList = $this->configResolver->getParameter(
                'languages',
                '',
                $siteAccess !== 'default' ? $siteAccess : null
            );
            $mainLanguage = reset($languageList);

            if ($mainLanguage) {
                $languages[$mainLanguage] = $mainLanguage;
            }
        }

        return array_keys($languages);
    }
1348775
private function loadFromLocation($location)
    {
        Logger::get()->debug('Loading settings...');
        // Add the trailing slash to the folder if it is missing.
        if (substr($location, -1) != DIRECTORY_SEPARATOR) {
            $location .= DIRECTORY_SEPARATOR;
        }
        $settingsLocation = $location . 'settings.json';

        if (!is_readable($settingsLocation)) {
            Logger::get()->error(
                'Settings file %s cannot be read.',
                $settingsLocation
            );
            throw new Settings\Exception("Settings file $settingsLocation is unavailable.");
        }

        // Load the settings.
        $settings = json_decode(file_get_contents($settingsLocation), true);
        if (empty($settings)) {
            throw new Settings\Exception('Settings file cannot be parsed.');
        }

        // Load settings customised for the current environment.
        $environmentSettings = null;
        $environment = self::getEnvironment();
        if ($environment) {
            $environmentSettingsLocation = sprintf(
                '%ssettings-%s.json',
                $location,
                strtolower($environment)
            );

            if (is_readable($environmentSettingsLocation)) {
                $environmentSettings = json_decode(file_get_contents($environmentSettingsLocation), true);
                if (!empty($environmentSettings)) {
                    $settings = self::mergeSettings($settings, $environmentSettings);
                }
            }
        }

        $this->settings = self::objectify($settings);

    }
783034
public static function findOrCreateBySettingName($settingName)
    {
        try {
            return self::findBySettingName($settingName);
        } catch (RecordNotFoundException $er) {
            $setting = new self();
            $setting->SettingName = $settingName;

            return $setting;
        }
    }
1373695
public function setSiteAccess(SiteAccess $siteAccess = null)
    {
        if ($this->logger) {
            $this->logger->debug('Changing SiteAccess in view providers');
        }

        $providers = array_merge(
            $this->getAllLocationViewProviders(),
            $this->getAllContentViewProviders(),
            $this->getAllBlockViewProviders()
        );
        foreach ($providers as $provider) {
            if ($provider instanceof SiteAccessAware) {
                $provider->setSiteAccess($siteAccess);
            }
        }
    }
1003303
public function getMappingSetting(Mapping $inquirerMapping, $propertyName, $settingKey)
    {
        foreach ($this as $memberMapping) {
            /** @var $memberMapping Mapping */
            if ($inquirerMapping->getType()->getName() === $memberMapping->getType()->getName()
                && $inquirerMapping->getType()->getIndex()->getName() === $memberMapping->getType()->getIndex()->getName()
            ) {
                return $memberMapping->getPropertyByPath([$propertyName, $settingKey]);
            }
        }

        return null;
    }
124560
public function getRootLocationsBySiteAccesses(array $siteAccesses)
    {
        $rootLocations = [];

        foreach ($siteAccesses as $siteAccess) {
            $rootLocationId = $this->getRootLocationBySiteAccessName($siteAccess);

            $rootLocations[$rootLocationId] = $rootLocationId;
        }

        return array_keys($rootLocations);
    }
52330
public static function configureWithPreset($preset, $settings = null)
    {
        // Load from JSON file if string provided
        if (is_string($settings)) {
            return self::configureWithPreset($preset, json_decode(file_get_contents($settings), true));
        }

        // Ensure preset is initialized
        if (!array_key_exists($preset, self::$config) || is_null(self::$config[$preset])) {
            self::$config[$preset] = array();
        }

        //-------------------------------
        // Dev Platform Config
        //-------------------------------
        self::configureDevPlatformSetting('dev-platform', 'host', 'MNO_DEVPL_HOST', $preset, $settings);
        self::configureDevPlatformSetting('dev-platform', 'api_path', 'MNO_DEVPL_API_PATH', $preset, $settings);
        self::configureDevPlatformSetting('environment', 'api_key', 'MNO_DEVPL_ENV_KEY', $preset, $settings);
        self::configureDevPlatformSetting('environment', 'api_secret', 'MNO_DEVPL_ENV_SECRET', $preset, $settings);

        return self::$config[$preset];
    }
176797
static function allDesignBases( $siteAccess = false )
    {
        // in memory caching
        if ( $siteAccess )
        {
            if ( isset( $GLOBALS['eZTemplateDesignResourceSiteAccessBases'] ) )
            {
                if ( isset( $GLOBALS['eZTemplateDesignResourceSiteAccessBases'][$siteAccess] ) )
                {
                    return $GLOBALS['eZTemplateDesignResourceSiteAccessBases'][$siteAccess];
                }
            }
            else
            {
                $GLOBALS['eZTemplateDesignResourceSiteAccessBases'] = array();
            }
        }
        else
        {
            if ( isset( $GLOBALS['eZTemplateDesignResourceBases'] ) )
            {
                return $GLOBALS['eZTemplateDesignResourceBases'];
            }
        }

        if ( eZINI::instance( 'site.ini' )->variable( 'DesignSettings', 'DesignLocationCache' ) === 'enabled' )
        {
            // Using current SA if none given
            $siteAccessName = $siteAccess !== false ? $siteAccess : $GLOBALS['eZCurrentAccess']['name'];

            $cachePath = eZSys::cacheDirectory()
                         . '/'
                         . self::DESIGN_BASE_CACHE_NAME
                         . md5( $siteAccessName )
                         . '.php';

            $clusterFileHandler = eZClusterFileHandler::instance( $cachePath );

            if( $clusterFileHandler->fileExists( $cachePath ) )
            {
                $designBaseList = unserialize( $clusterFileHandler->fetchContents() );

                self::savesMemoryCache( $designBaseList, $siteAccess );
            }
            else
            {
                // find design locations
                $designBaseList = self::findDesignBase( eZINI::instance( 'file.ini' ), $siteAccess );

                // stores it on the disk
                $clusterFileHandler->fileStoreContents( $cachePath,
                                                        serialize( $designBaseList ),
                                                        'designbases',
                                                        'php' );

                self::savesMemoryCache( $designBaseList, $siteAccess );
            }
        }
        else
        {
            // find design locations
            $designBaseList = self::findDesignBase( eZINI::instance( 'file.ini' ), $siteAccess );

            self::savesMemoryCache( $designBaseList, $siteAccess );
        }

        return $designBaseList;
    }
1056222
private function getSettingsFromRepository(SettingsOwnerInterface $owner = null)
    {
        $settings = array();

        foreach (array_keys($this->settingsConfiguration) as $name) {
            try {
                $this->validateSetting($name, $owner);
                $settings[$name] = null;
            } catch (WrongScopeException $e) {
                continue;
            }
        }

        /** @var Setting $setting */
        foreach ($this->repository->findBy(
            array('ownerId' => $owner === null ? null : $owner->getSettingIdentifier())
        ) as $setting) {
            if (array_key_exists($setting->getName(), $settings)) {
                $settings[$setting->getName()] = $this->serializer->unserialize($setting->getValue());
            }
        }

        return $settings;
    }
1193625
static public function getPathPrefix()
    {
        $ini = eZINI::instance();

        return $ini->hasVariable( 'SiteAccessSettings', 'PathPrefix' ) &&
            $ini->variable( 'SiteAccessSettings', 'PathPrefix' ) != ''
            ? eZURLAliasML::cleanURL( $ini->variable( 'SiteAccessSettings', 'PathPrefix' ) )
            : false;
    }
171074
static function overrideArray( $siteAccess = false )
    {

        if ( $siteAccess === false and self::$overrideArrayCache !== null )
        {
            return self::$overrideArrayCache;
        }

        $bases = eZTemplateDesignResource::allDesignBases( $siteAccess );

        // fetch the override array from a specific siteacces
        if ( $siteAccess )
        {
            $overrideINI = eZSiteAccess::getIni( $siteAccess, 'override.ini' );
        }
        else
        {
            $overrideINI = eZINI::instance( 'override.ini' );
        }

        $designStartPath = eZTemplateDesignResource::designStartPath();

        // Generate match cache for all templates

        // Build arrays of available files, start with standard design and end with most prefered design
        $matchFileArray = array();

        $reverseBases = array_reverse( $bases );

        foreach ( $reverseBases as $base )
        {
            $templateResource = $base . '/templates';
            $sourceFileArray = eZDir::recursiveFindRelative( $templateResource, "",  "tpl" );
            foreach ( $sourceFileArray as $source )
            {
                $matchFileArray[$source]['base_dir'] = $templateResource;
                $matchFileArray[$source]['template'] = $source;
            }
        }

        // Load override templates
        $overrideSettingGroups = $overrideINI->groups();
        if ( isset( $GLOBALS['eZDesignOverrides'] ) )
        {
            $overrideSettingGroups = array_merge( $overrideSettingGroups, $GLOBALS['eZDesignOverrides'] );
        }

        foreach ( $overrideSettingGroups as $overrideName => $overrideSetting )
        {
            if( !isset( $overrideSetting['Source'] ) )
            {
                continue;
            }
            $overrideSource = "/" . $overrideSetting['Source'];
            $overrideMatchFile = $overrideSetting['MatchFile'];

            // Find the matching file in the available resources
            $triedFiles = array();
            $fileInfo = eZTemplateDesignResource::fileMatch( $bases, 'override/templates', $overrideMatchFile, $triedFiles );

            $resourceInUse = is_array( $fileInfo ) ? $fileInfo['resource'] : false;
            $overrideMatchFilePath = is_array( $fileInfo ) ? $fileInfo['path'] : false;

            // if the override template is not found
            // then we probably shouldn't use it
            // there should be added a check around the following code
            // if ( $overrideMatchFilePath )
            // {
            $customMatchArray = array();
            $customMatchArray['conditions'] = isset( $overrideSetting['Match'] ) ? $overrideSetting['Match'] : null;
            $customMatchArray['match_file'] = $overrideMatchFilePath;
            $customMatchArray['override_name'] = $overrideName;

            $matchFileArray[$overrideSource]['custom_match'][] = $customMatchArray;
            // }

            // if overriding a non-existing template
            // then we use the override template as main template
            // this code should probably be removed
            // because we should not allow an override if the main template is missing
            if ( $resourceInUse && !isset( $matchFileArray[$overrideSource]['base_dir'] ) )
            {
                $matchFileArray[$overrideSource]['base_dir'] = $resourceInUse;
                $matchFileArray[$overrideSource]['template'] = $overrideSource;
            }

            if ( ! $overrideMatchFilePath )
            {
                eZDebug::writeError( "Custom match file: path '$overrideMatchFile' not found in any resource. Check the template settings in settings/override.ini", __METHOD__ );
                eZDebug::writeError( implode( ', ', $triedFiles ), __METHOD__ . ' tried files' );
            }

        }

        if ( $siteAccess === false )
        {
            self::$overrideArrayCache = $matchFileArray;
        }

        return $matchFileArray;
    }
745428
protected function getImageVariationsForSiteaccess($siteaccess)
    {
        $variations = [];
        $imageAliasesList = $this->getGroup('AliasSettings', 'image.ini', $siteaccess);
        foreach ($imageAliasesList['AliasList'] as $imageAliasIdentifier) {
            $variationSettings = ['reference' => null, 'filters' => []];
            $aliasSettings = $this->getGroup($imageAliasIdentifier, 'image.ini', $siteaccess);
            if (isset($aliasSettings['Reference']) && $aliasSettings['Reference'] != '') {
                $variationSettings['reference'] = $aliasSettings['Reference'];
            }
            if (isset($aliasSettings['Filters']) && \is_array($aliasSettings['Filters'])) {
                // parse filters. Format: filtername=param1;param2...paramN
                foreach ($aliasSettings['Filters'] as $filterString) {
                    $filteringSettings = [];

                    if (strstr($filterString, '=') !== false) {
                        list($filteringSettings['name'], $filterParams) = explode('=', $filterString);
                        $filterParams = explode(';', $filterParams);

                        // make sure integers are actually integers, not strings
                        array_walk(
                            $filterParams,
                            static function (&$value) {
                                if (preg_match('/^[0-9]+$/', $value)) {
                                    $value = (int)$value;
                                }
                            }
                        );

                        $filteringSettings['params'] = $filterParams;
                    } else {
                        $filteringSettings['name'] = $filterString;
                    }

                    $variationSettings['filters'][] = $filteringSettings;
                }
            }
            $variations[$imageAliasIdentifier] = $variationSettings;
        }

        return $variations;
    }
1356728
public function getConfigSetting($setting) {
		$source = $this->getConfigData();
		foreach(func_get_args() as $setting) {
			if(empty($source[$setting])) return null;
			$source = $source[$setting];
		}
		return $source;
	}
228178
public static function setup(Settings $settings, ConnectionInterface $connection = null)
    {
        return static::getInstance($settings)->load($connection);
    }
619284
public function get_setting() {
        $site = course_get_format(get_site())->get_course();
        return $site->{$this->name} != '' ? $site->{$this->name} : NULL;
    }
243180
private function _loadSettingsFromFile()
    {
        $filename = $this->getConfigPath().'settings.php';

        if (!file_exists($filename)) {
            throw new OneLogin_Saml2_Error(
                'Settings file not found: %s',
                OneLogin_Saml2_Error::SETTINGS_FILE_NOT_FOUND,
                array($filename)
            );
        }

        /** @var array $settings */
        include $filename;

        // Add advance_settings if exists

        $advancedFilename = $this->getConfigPath().'advanced_settings.php';

        if (file_exists($advancedFilename)) {
            /** @var array $advancedSettings */
            include $advancedFilename;
            $settings = array_merge($settings, $advancedSettings);
        }


        return $this->_loadSettingsFromArray($settings);
    }