Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 19... Línea 19...
19
     *
19
     *
20
     * @param string $key      Configuration key to be used when attempting
20
     * @param string $key      Configuration key to be used when attempting
21
     *                         to retrieve value from the environment or ini file.
21
     *                         to retrieve value from the environment or ini file.
22
     * @param mixed $defaultValue
22
     * @param mixed $defaultValue
23
     * @param string $expectedType  The expected type of the retrieved value.
23
     * @param string $expectedType  The expected type of the retrieved value.
24
     * @param array $config
-
 
25
     * @param array $additionalArgs
24
     * @param array $config additional configuration options.
26
     *
25
     *
27
     * @return mixed
26
     * @return mixed
28
     */
27
     */
29
    public static function resolve(
28
    public static function resolve(
30
        $key,
29
        $key,
31
        $defaultValue,
30
        $defaultValue,
32
        $expectedType,
31
        $expectedType,
33
        $config = []
32
        $config = []
34
    )
33
    )
35
    {
34
    {
-
 
35
        $iniOptions = isset($config['ini_resolver_options'])
-
 
36
            ? $config['ini_resolver_options']
-
 
37
            : [];
-
 
38
 
36
        $envValue = self::env($key, $expectedType);
39
        $envValue = self::env($key, $expectedType);
37
        if (!is_null($envValue)) {
40
        if (!is_null($envValue)) {
38
            return $envValue;
41
            return $envValue;
39
        }
42
        }
Línea 40... Línea 43...
40
 
43
 
41
        if (!isset($config['use_aws_shared_config_files'])
44
        if (!isset($config['use_aws_shared_config_files'])
42
            || $config['use_aws_shared_config_files'] != false
45
            || $config['use_aws_shared_config_files'] != false
43
        ) {
46
        ) {
-
 
47
            $iniValue = self::ini(
-
 
48
                $key,
-
 
49
                $expectedType,
-
 
50
                null,
-
 
51
                null,
-
 
52
                $iniOptions
44
            $iniValue = self::ini($key, $expectedType);
53
            );
45
            if(!is_null($iniValue)) {
54
            if(!is_null($iniValue)) {
46
                return $iniValue;
55
                return $iniValue;
47
            }
56
            }
Línea 87... Línea 96...
87
     * @param string|null $filename If provided, uses a custom filename rather
96
     * @param string|null $filename If provided, uses a custom filename rather
88
     *                              than looking in the default directory.
97
     *                              than looking in the default directory.
89
     *
98
     *
90
     * @return null | mixed
99
     * @return null | mixed
91
     */
100
     */
92
    public static function ini($key, $expectedType, $profile = null, $filename = null)
101
    public static function ini(
-
 
102
        $key,
-
 
103
        $expectedType,
-
 
104
        $profile = null,
-
 
105
        $filename = null,
-
 
106
        $options = []
93
    {
107
    ){
94
        $filename = $filename ?: (self::getDefaultConfigFilename());
108
        $filename = $filename ?: (self::getDefaultConfigFilename());
95
        $profile = $profile ?: (getenv(self::ENV_PROFILE) ?: 'default');
109
        $profile = $profile ?: (getenv(self::ENV_PROFILE) ?: 'default');
Línea 96... Línea 110...
96
 
110
 
97
        if (!@is_readable($filename)) {
111
        if (!@is_readable($filename)) {
98
            return null;
112
            return null;
99
        }
113
        }
100
        // Use INI_SCANNER_NORMAL instead of INI_SCANNER_TYPED for PHP 5.5 compatibility
114
        // Use INI_SCANNER_NORMAL instead of INI_SCANNER_TYPED for PHP 5.5 compatibility
101
        //TODO change after deprecation
115
        //TODO change after deprecation
-
 
116
        $data = @\Aws\parse_ini_file($filename, true, INI_SCANNER_NORMAL);
-
 
117
 
-
 
118
        if (isset($options['section'])
-
 
119
            && isset($options['subsection'])
-
 
120
            && isset($options['key']))
-
 
121
        {
-
 
122
            return self::retrieveValueFromIniSubsection(
-
 
123
                $data,
-
 
124
                $profile,
-
 
125
                $filename,
-
 
126
                $expectedType,
-
 
127
                $options
-
 
128
            );
-
 
129
        }
102
        $data = @\Aws\parse_ini_file($filename, true, INI_SCANNER_NORMAL);
130
 
103
        if ($data === false
131
        if ($data === false
104
            || !isset($data[$profile])
132
            || !isset($data[$profile])
105
            || !isset($data[$profile][$key])
133
            || !isset($data[$profile][$key])
106
        ) {
134
        ) {
Línea 175... Línea 203...
175
        ) {
203
        ) {
176
            $value = intVal($value);
204
            $value = intVal($value);
177
        }
205
        }
178
        return $value;
206
        return $value;
179
    }
207
    }
180
}
-
 
181
208
 
-
 
209
    /**
-
 
210
     * Normalizes string values pulled out of ini files and
-
 
211
     * environment variables.
-
 
212
     *
-
 
213
     * @param array $data The data retrieved the ini file
-
 
214
     * @param string $profile The specified ini profile
-
 
215
     * @param string $filename The full path to the ini file
-
 
216
     * @param array $options Additional arguments passed to the configuration resolver
-
 
217
     *
-
 
218
     * @return mixed
-
 
219
     */
-
 
220
    private static function retrieveValueFromIniSubsection(
-
 
221
        $data,
-
 
222
        $profile,
-
 
223
        $filename,
-
 
224
        $expectedType,
-
 
225
        $options
-
 
226
    ){
-
 
227
        $section = $options['section'];
-
 
228
        if ($data === false
-
 
229
            || !isset($data[$profile][$section])
-
 
230
            || !isset($data["{$section} {$data[$profile][$section]}"])
-
 
231
        ) {
-
 
232
            return null;
-
 
233
        }
-
 
234
 
-
 
235
        $services_section = \Aws\parse_ini_section_with_subsections(
-
 
236
            $filename,
-
 
237
            "services {$data[$profile]['services']}"
-
 
238
        );
-
 
239
 
-
 
240
        if (!isset($services_section[$options['subsection']][$options['key']])
-
 
241
        ) {
-
 
242
            return null;
-
 
243
        }
-
 
244
 
-
 
245
        return self::convertType(
-
 
246
            $services_section[$options['subsection']][$options['key']],
-
 
247
            $expectedType
-
 
248
        );
-
 
249
    }
-
 
250
}
-
 
251