Location: PHPKode > projects > Concentr Xml Tools > concentre-0.2.1-beta/fwcli.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);
  }

  // }}}

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

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

	$arguments = new CliArguments();
	
	try { 
		
	  if ($arguments->module) {
	    $module = $arguments->module;

	    define('MODULE_PATH',BASE_PATH. '/modules/'.$module);
	    define('WEB_MODULE_PATH', '/modules/'.$module);
	    
	    $event = $arguments->event?$arguments->event:'__default';
	    $class = $arguments->class?$arguments->class:$module;
	
			$classFile = MODULE_PATH.'/'.$class.'.php';
			
			if (file_exists($classFile)) {
				require_once($classFile);
				if (class_exists($class)) {
			 		
			 		$instance = new $class();
			 		
			 		if (!Module_Console::isValid($instance)) {
			 			throw new Exception("Requested module is not a valid framework module!");
			 		}
			 		
			 		$instance->moduleName = $module;
					
					/* maybe useless in console mode ?
			 		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 = $arguments->view?$arguments->view:$instance->defaultViewType;
								$view = View::factory($view_type, $instance);
								$view->display();
								
								//$cache->save();
					 	} else {
							throw new Exception("You do not have access to the requested page!");
					 	}
					}	else {
					 		$instance->__authenticate();
					 		$logger->log(Logger::INFO,'get credentials');
					}
			 	
				} else {
					throw new Exception("A valid module for your request was not found");
				}
				
			} else {
					throw new Exception("Could not find: $classFile");        
			}
	  } else {
	      throw new Exception("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