File: 0.01.1a/core/IncludeManager.php (View as HTML)

  1: <?php 
  2: /* -------------------------------------------------------------
  3: This file is part of FreeDESK
  4: 
  5: FreeDESK is (C) Copyright 2012 David Cutting
  6: 
  7: FreeDESK is free software: you can redistribute it and/or modify
  8: it under the terms of the GNU General Public License as published by
  9: the Free Software Foundation, either version 3 of the License, or
 10: (at your option) any later version.
 11: 
 12: FreeDESK is distributed in the hope that it will be useful,
 13: but WITHOUT ANY WARRANTY; without even the implied warranty of
 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15: GNU General Public License for more details.
 16: 
 17: You should have received a copy of the GNU General Public License
 18: along with FreeDESK.  If not, see www.gnu.org/licenses
 19: 
 20: For more information see www.purplepixie.org/freedesk/
 21: -------------------------------------------------------------- */
 22: 
 23: /**
 24:  * Include class handles most php source file includes at runtime
 25: **/
 26: 
 27: class IncludeManager
 28: {
 29: 	/**
 30: 	 * Reference to FreeDESK class
 31: 	**/
 32: 	private $DESK = null;
 33: 	/**
 34: 	 * Base directory
 35: 	**/
 36: 	private $baseDir = "./";
 37: 	
 38: 	/**
 39: 	 * Constructor
 40: 	 * @param object $freeDESK freedesk main object
 41: 	 * @param string $baseDir base directory
 42: 	**/
 43: 	function IncludeManager(&$freeDESK, $baseDir)
 44: 	{
 45: 		$this->DESK = &$freeDESK;
 46: 		$this->baseDir = $baseDir;
 47: 	}
 48: 
 49: 	/**
 50: 	 * Include a File
 51: 	 * @param string $filepath Relative filepath from base dir
 52: 	 * @param bool $required Is opened using require() rather than include() (default false)
 53: 	 * @param bool $once Is opened using include_once() (default false)
 54: 	**/
 55: 	function IncludeFile($filepath, $required=false, $once=false)
 56: 	{
 57: 		if ($required)
 58: 		{
 59: 			require($this->baseDir.$filepath);
 60: 				//or die("Failed to open required file ".$filepath);
 61: 		}
 62: 		else if ($once)
 63: 		{
 64: 			include_once($this->baseDir.$filepath);
 65: 		}
 66: 		else
 67: 		{
 68: 			include($this->baseDir.$filepath);
 69: 		}
 70: 	}
 71: 	
 72: 	/**
 73: 	 * Include a file and create a class instance, uses require to open file
 74: 	 * @param string $filepath Path to file
 75: 	 * @param string $classname Name of the class to create
 76: 	 * @param bool $passdesk Pass the FreeDESK object to constructor (optional, default true)
 77: 	 * @return object Newly created class
 78: 	**/
 79: 	function IncludeInstance($filepath, $classname, $passdesk=true)
 80: 	{
 81: 		$this->IncludeFile($filepath,true);
 82: 		$c = null;
 83: 		if ($passdesk)
 84: 			$c=new $classname($this->DESK);
 85: 		else
 86: 			$c=new $classname();
 87: 		return $c;
 88: 	}
 89: 	
 90: 	/**
 91: 	 * Include a file and execute a static method in that class, uses require to open
 92: 	 * @param string $filepath Path to file
 93: 	 * @param string $classname Name of class
 94: 	 * @param string $methodname Name of method (optional, default Exec)
 95: 	 * @param bool $passdesk Pass the FreeDESK object to the method (optional, default true)
 96: 	**/
 97: 	function IncludeExec($filepath, $classname, $methodname="Exec", $passdesk=true)
 98: 	{
 99: 		$this->IncludeFile($filepath,true);
100: 		if ($passdesk)
101: 			$classname::$methodname($this->DESK);
102: 		else
103: 			$classname::$methodname();
104: 	}
105: 
106: }
107: 
108: 
109: 
110: 
111: 
112: 
113: 
114: ?>
115: