Example #1
0
/**
 * Return authentication credentials for the specified database connection.
 *
 * @param string $conn_name The name of the db connection you want to retrieve
 * @param boolean $lack_of_creds_is_fatal defaults to true for historical purposes
 * @return array Array with all the db connection info defined for the specified named connection.
 */
function _legacy_get_db_credentials($conn_name, $lack_of_creds_is_fatal = true)
{
    static $db_info;
    // if db_info has not been set, this is the first time this function has been run.
    if (!isset($db_info)) {
        trigger_warning('Using _legacy_get_db_credentials - please upgrade to PHP 5.1 or later to use faster XML functions.');
        if (!defined('DB_CREDENTIALS_FILEPATH')) {
            trigger_fatal_error('The DB_CREDENTIALS_FILEPATH constant is not defined.');
        }
        $db_info = array();
        require_once INCLUDE_PATH . 'xml/xmlparser.php';
        if (file_exists(DB_CREDENTIALS_FILEPATH) && ($xml = trim(file_get_contents(DB_CREDENTIALS_FILEPATH)))) {
            $xml_parse = new XMLParser($xml);
            $parse = $xml_parse->Parse();
            if (isset($xml_parse->document->database)) {
                foreach ($xml_parse->document->database as $database) {
                    $tmp = array();
                    $db_conn_name = isset($database->connection_name[0]->tagData) ? $database->connection_name[0]->tagData : false;
                    $tmp['db'] = isset($database->db[0]->tagData) ? $database->db[0]->tagData : false;
                    $tmp['user'] = isset($database->user[0]->tagData) ? $database->user[0]->tagData : false;
                    $tmp['password'] = isset($database->password[0]->tagData) ? $database->password[0]->tagData : false;
                    $tmp['host'] = isset($database->host[0]->tagData) ? $database->host[0]->tagData : false;
                    if ($db_conn_name && $tmp['db'] !== false && $tmp['user'] !== false && $tmp['password'] !== false && $tmp['host'] !== false) {
                        $db_info[$db_conn_name] = $tmp;
                    } else {
                        $invalid_entries[] = $db_conn_name;
                    }
                }
            }
            if (isset($invalid_entries)) {
                $invalid_str = $invalid_entries == 1 ? $invalid_entries . ' entry appears' : $invalid_entries . ' entries appear';
                turn_carl_util_error_context_off();
                foreach ($invalid_entries as $conn_name) {
                    if (!empty($conn_name)) {
                        trigger_error('The connection ' . $conn_name . ' in the db credentials XML file (' . DB_CREDENTIALS_FILEPATH . ') appears to have missing or invalid values.', WARNING);
                    } else {
                        trigger_error('An entry without a connection name is defined in the db credentials XML file (' . DB_CREDENTIALS_FILEPATH . ')', WARNING);
                    }
                }
                turn_carl_util_error_context_on();
            }
            if (empty($db_info)) {
                trigger_error('Check the xml in the db credentials XML file (' . DB_CREDENTIALS_FILEPATH . ') - no valid database connection information could be built.', WARNING);
            }
        } else {
            trigger_fatal_error('The DB_CREDENTIALS_FILEPATH (' . DB_CREDENTIALS_FILEPATH . ') refers to a file that is missing or does not have any content.');
        }
    }
    // if this was the first time, the code above should have run successfully so db_info is populated.
    // if this is not the first time, then the code above should have been skipped since it was populated the first
    // run of the function.
    if (isset($db_info[$conn_name])) {
        return $db_info[$conn_name];
    } else {
        // disable context display so we do not show passwords on screen.
        turn_carl_util_error_context_off();
        if ($lack_of_creds_is_fatal) {
            trigger_fatal_error('Unable to use database connection ' . $conn_name . ' - No credential information found for the connection named ' . $conn_name . ' in database credential file (' . DB_CREDENTIALS_FILEPATH . ').', 2);
        } else {
            trigger_warning('Unable to use database connection ' . $conn_name . ' - No credential information found for the connection named ' . $conn_name . ' in database credential file (' . DB_CREDENTIALS_FILEPATH . ').', 2);
        }
        turn_carl_util_error_context_on();
    }
    return false;
}
Example #2
0
 /**
  * A model should clearly document what it returns and it should never be NULL
  *
  * Some examples of what a model might return:
  *
  * - an object that implements an interface.
  * - an array with a predictable set of contents.
  * - an xml string.
  *
  * @param boolean force the build method to be called again for the model - default false.
  */
 final function get($force_rebuild = false)
 {
     if (is_null($this->data) || $force_rebuild) {
         $this->data = $this->build();
         if (is_null($this->data)) {
             trigger_fatal_error('The model build() method must return a non null value.');
         }
     }
     return $this->data;
 }
Example #3
0
/** @access private */
function _parse_async_upload_authenticator($auth)
{
    if (!is_array($auth) || empty($auth)) {
        trigger_fatal_error("upload authenticator must be specified as an " . "array as per the reason_create_async_upload_session API docs; " . "instead got " . var_export($auth, true), 2);
    }
    $callback = array_shift($auth);
    if ($inc_type = _detect_filename($callback)) {
        $filename = $callback;
        $callback = array_shift($auth);
    } else {
        $filename = null;
    }
    if ($filename) {
        if ($inc_type == "absolute" && !file_exists($filename)) {
            trigger_fatal_error("upload authenticator file " . var_export($filename, true) . " does not exist", 2);
        } else {
            if ($inc_type == "relative") {
                if (!reason_file_exists($filename)) {
                    trigger_fatal_error("upload authenticator file " . var_export($filename, true) . " does not exist in either " . "the local or the core Reason lib directory", 2);
                }
                $filename = reason_resolve_path($filename);
            }
        }
    }
    return array("file" => $filename, "callback" => $callback, "arguments" => $auth);
}