~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to api/src/Config.php

Preparing to merge in my branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 
3
/**
 
4
 * Helioviewer Configuration Helper Class Definition
 
5
 *
 
6
 * This file defines a class which helps to parse Helioviewer's configuration
 
7
 * file, create global constants which can be used to access those configuration
 
8
 * parameters, and fix data types for known parameters.
 
9
 *
 
10
 * PHP version 5
 
11
 *
 
12
 * @category Configuration
 
13
 * @package  Helioviewer
 
14
 * @author   Keith Hughitt <keith.hughitt@nasa.gov>
 
15
 * @license  http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
 
16
 * @link     http://launchpad.net/helioviewer.org
 
17
 */
 
18
/**
 
19
 * Helioviewer Configuration Helper
 
20
 *
 
21
 * A helper class created to assist in parsing Helioviewer's configuration
 
22
 * file. It creates global constants which can be used to access those configuration
 
23
 * parameters, and fix data types for known parameters.
 
24
 *
 
25
 * @category Configuration
 
26
 * @package  Helioviewer
 
27
 * @author   Keith Hughitt <keith.hughitt@nasa.gov>
 
28
 * @license  http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
 
29
 * @link     http://launchpad.net/helioviewer.org
 
30
 */
 
31
class Config
 
32
{
 
33
    private $_bools  = array("local_tiling_enabled", "distributed_tiling_enabled", "disable_cache");
 
34
    private $_ints   = array("build_num", "bit_depth", "default_timestep", "prefetch_size", "num_colors",
 
35
                             "png_compression_quality", "jpeg_compression_quality", "max_jpx_frames",
 
36
                             "max_movie_frames");
 
37
    private $_floats = array("default_image_scale", "min_image_scale", "max_image_scale");
 
38
 
 
39
    public  $servers;
 
40
 
 
41
    /**
 
42
     * Creates an instance of the Config helper class
 
43
     *
 
44
     * @param string $file Path to configuration file
 
45
     *
 
46
     * @return void
 
47
     */
 
48
    public function __construct($file)
 
49
    {
 
50
        $this->config = parse_ini_file($file);
 
51
 
 
52
        $this->_fixTypes();
 
53
 
 
54
        foreach ($this->config as $key => $value) {
 
55
            if ($key !== "tile_server") {
 
56
                define("HV_" . strtoupper($key), $value);
 
57
            }
 
58
        }
 
59
 
 
60
        define("HV_TILE_SERVER_0", "api/index.php");
 
61
        foreach ($this->config["tile_server"] as $id => $url) {
 
62
            define("HV_TILE_SERVER_" . ($id + 1), $url);
 
63
        }
 
64
 
 
65
        $this->_setAdditionalParams();
 
66
 
 
67
        $this->_setupLogging(true);
 
68
 
 
69
        $dbconfig = substr($file, 0, strripos($file, "/")) . "/Database.php";
 
70
 
 
71
        include_once $dbconfig;
 
72
    }
 
73
 
 
74
    /**
 
75
     * Casts known configuration variables to correct types.
 
76
     *
 
77
     * @return void
 
78
     */
 
79
    private function _fixTypes()
 
80
    {
 
81
        // booleans
 
82
        foreach ($this->_bools as $boolean) {
 
83
            $this->config[$boolean] = (bool) $this->config[$boolean];
 
84
        }
 
85
 
 
86
        // integers
 
87
        foreach ($this->_ints as $int) {
 
88
            $this->config[$int] = (int) $this->config[$int];
 
89
        }
 
90
 
 
91
        // floats
 
92
        foreach ($this->_floats as $float) {
 
93
            $this->config[$float] = (float) $this->config[$float];
 
94
        }
 
95
    }
 
96
 
 
97
    /**
 
98
     * Makes sure that error log exists and selects desired logging verbosity
 
99
     *
 
100
     * @param bool $verbose Whether or not to force verbose logging.
 
101
     *
 
102
     * @return void
 
103
     */
 
104
    private function _setupLogging($verbose)
 
105
    {
 
106
        if ($verbose) {
 
107
            error_reporting(E_ALL | E_STRICT);
 
108
        }
 
109
        $errorLog = HV_ERROR_LOG;
 
110
        if (!file_exists($errorLog)) {
 
111
            touch($errorLog);
 
112
        }
 
113
    }
 
114
 
 
115
    /**
 
116
     * Some useful values can be determined automatically...
 
117
     *
 
118
     * @return void
 
119
     */
 
120
    private function _setAdditionalParams()
 
121
    {
 
122
        //define("HV_ROOT_DIR", substr(getcwd(), 0, -4));
 
123
        //define("HV_WEB_ROOT_URL", "http://" . $_SERVER["SERVER_NAME"]
 
124
        //    . substr($_SERVER["SCRIPT_NAME"], 0, -14));
 
125
        define("HV_CACHE_DIR", HV_ROOT_DIR . "/cache");
 
126
        define("HV_TMP_DIR", HV_ROOT_DIR . "/cache/tmp");
 
127
        define("HV_ERROR_LOG", HV_ROOT_DIR . "/log/error");
 
128
        define("HV_EMPTY_TILE", HV_ROOT_DIR . "/resources/images/transparent_512.png");
 
129
        define("HV_TMP_ROOT_URL", HV_WEB_ROOT_URL . "/cache/tmp");
 
130
    }
 
131
}
 
 
b'\\ No newline at end of file'