<?php
/**
 * cacert is the first class you load.
 * cacert autoloads other classes in the same directory.
 */
class cacert
    {
    protected $base_directory;
    protected $class_directory;
    protected $class_suffix = '.php';
    protected $web_directory;
    protected $database_name;
    protected $database_password;
    protected $database_user;
    protected $host_name;
    protected $host_name_display;
    public function __construct($settings)
        {
        $this->base_directory = $settings['base_directory'];
        $this->class_directory = $settings['class_directory'];
        $this->web_directory = $_SERVER['DOCUMENT_ROOT'];
        if (substr($this->web_directory, -1) != '/') { $this->web_directory .= '/'; }
        if (isset($settings['domain_name'])) { $this->host_name = $settings['domain_name']; }
        else                                 { $this->host_name = $_SERVER['HTTP_HOST']; }
        if (isset($settings['domain_name_display'])) { $this->host_name_display = $settings['domain_name_display']; }
        else                                         { $this->host_name_display = $this->host_name; }
        if (isset($settings['database_name']))     { $this->database_name     = $settings['database_name']; }
        if (isset($settings['database_password'])) { $this->database_password = $settings['database_password']; }
        if (isset($settings['database_user']))     { $this->database_user     = $settings['database_user']; }
        $result = spl_autoload_register ('cacert::autoload');
        }
    protected function autoload($class)
        {
        $file = $this->class_directory . $class . $this->class_suffix;
        if (file_exists($file))
            {
            require_once $file;
            return true;
            }
        return false;
        }
    public function database_name()     { return $this->database_name; }
    public function database_password() { return $this->database_password; }
    public function database_user()     { return $this->database_user; }
    public function host_name()         { return $this->host_name; }
    public function host_name_display() { return $this->host_name_display; }
    public function web_directory()     { return $this->web_directory; }
    }
