PHP Classes
elePHPant
Icontem

File: code/includes/configuration.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Junaid Hassan  >  PHP MVC  >  code/includes/configuration.php  >  Download  
File: code/includes/configuration.php
Role: Class source
Content type: text/plain
Description: configuration.php
Class: PHP MVC
MVC framework that loads XML configuration files
Author: By
Last change:
Date: 2 years ago
Size: 2,233 bytes
 

Contents

Class file image Download
<?php
/* Class name : Configuration
 * Inherited from :
 * Created by : Junaid Hassan (email : junaidhassanalvi@gmail.com , blog : junaidhassanalvi.wordpress.com)
 * Created On : 15-April-2103
 * Description : It is created to load and add configuration and to perfrom initial steps for configuration
 *
 * Change Logs :
 *
 */
class Configuration {

    var
$config;

    function
__construct() {
       
$this->load();
    }

   
//jha-- load configuration for xml configuration file
    //jha-- add some additional configuration, defined in php code, in configuration object
   
function load() {

        if (
is_object($this->config))
            return;

       
$base_path = dirname(str_replace('\\', '/', dirname(__FILE__)));
       
$base_url = dirname((strpos(strtolower($_SERVER['SERVER_PROTOCOL']), 'https') === FALSE ? 'http://' :
                       
'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']);
       
$this->config = simplexml_load_file($base_path . '/' . INCLUDES . '/' . 'config.xml');
       
$this->config->paths->addChild('includes', INCLUDES);
       
$this->config->addChild('base_url', $base_url);
       
$this->config->addChild('base_path', $base_path);
    }

   
//jha-- load includes and helpers defined in configuration for perform various necessary site operations.
   
public function preload() {
        if (isset(
$this->config->preload->includes->class)) {
            foreach (
$this->config->preload->includes->class as $classes) {
               
$inc_path = $this->config->base_path . '/' . $this->config->paths->includes . '/' . $classes . '.php';
                if (
file_exists($inc_path)) {
                    require_once(
$inc_path);
                }
            }
        }

        if (isset(
$this->config->preload->helpers->class)) {
            foreach (
$this->config->preload->helpers->class as $helpers) {
               
$inc_path = $this->config->base_path . '/' . $this->config->paths->helpers . '/' . $helpers . '.php';
                if (
file_exists($inc_path)) {
                    require_once(
$inc_path);
                }
            }
        }
    }

}

?>