Location: PHPKode > projects > Concentr Xml Tools > concentre-0.2.1-beta/fw.php
<?php

  require_once('etc/config.php');

  // {{{ __autoload($class)
  /**
  * __autoload
  *
  * Autoload is ran by PHP when it can't find a class it is trying to load.
  * By naming our classes intelligently we should be able to load most classes
  * dynamically.
  *
  * @author Joe Stump <hide@address.com>
  * @param string $class Class name we're trying to load
  * @return void
  * @package Framework
  */

	define('BASE_PATH',dirname(__FILE__));

  function __autoload($class)
  {
      $file = BASE_PATH.'/lib/' . str_replace('_','/',$class).'.php';   
      if (file_exists($file)) require_once($file);
  }

  // }}}
	$session = Session::singleton();

	$cache = new Cache_File(BASE_PATH . '/var/cache');
	$cache->start();
	
	$logger = Logger::singleton();
	$logger->attachObserver(new Logger_File(BASE_PATH.'/var/log/controler.log'));

	$logger->log(Logger::INFO,'Controler initialization');

	
	try { 
				
	  if (isset($_GET['module'])) {
	    $module = $_GET['module'];

	    define('MODULE_PATH',BASE_PATH. '/modules/'.$module);
	    define('WEB_MODULE_PATH', '/modules/'.$module);
	    
	    $class = @$_GET['class']?$_GET['class']:$module;
			$classFile = MODULE_PATH.'/'.$class.'.php';
						
			if (file_exists($classFile)) {
				require_once($classFile);

				if (class_exists($class)) {
			 		
			 		$instance = new $class();
					$event = @$_GET['event']?$_GET['event']:$instance->defaultEvent;
			 		
			 		if (!Module_Web::isValid($instance)) {
			 			throw new Exception_Http(400,"Requested module is not a valid framework module!");
			 		}
			 		
			 		$instance->moduleName = $module;
					
			 		if (isset($_GET['logout'])) {
			 			$instance->authentication->reset();
			 			$logger->log(Logger::INFO,'reset credentials');
			 		}
			 		
					if ($instance->authentication->isAuthenticated()) {
				 		if ($instance->authentication->isAuthorized()) {
			  			  $instance->$event();
			  			  
  			  		  $view_type = isset($_GET['view'])?$_GET['view']:$instance->defaultViewType;
								$view = View::factory($view_type, $instance);
								$view->display();
								
								//$cache->save();
					 	} else {
							throw new Exception_Http(401,"You do not have access to the requested page!");
					 	}
					}	else {
					 		$instance->__authenticate();
					 		$logger->log(Logger::INFO,'get credentials');
					}
			 	
				} else {
					throw new Exception_Http(400, "A valid module for your request was not found");
				}
				
			} else {
					throw new Exception_Http(400,"Could not find: $classFile");        
			}
	  } else {
	      throw new Exception_Http(400,"A valid module was not specified");
	  }

	} catch (Exception $e)  {
		
		echo $e->getMessage();
		/*
		$instance = new Module_Error($e);
		$instance->__default();
		
		$logger->log(Logger::ERR,$e->getMessage());

	  $view_type = isset($_GET['view'])?$_GET['view']:$instance->defaultViewType;
		$view = View::factory($view_type, $instance);
		$view->display();*/
	}

?>
Return current item: Concentr Xml Tools