/**
  * Get path of file the class is stored in
  *
  * @param	string			$className
  * @param	bool			$relative
  *
  * @return	string
  */
 public static function getClassPath($className, $relative = false)
 {
     $fileName = XDT_CLI_Autoloader::getFileName($className);
     if ($relative) {
         return $fileName;
     }
     return XDT_CLI_Application::xfBaseDir() . 'library' . DIRECTORY_SEPARATOR . $fileName;
 }
Beispiel #2
0
 /**
  * Load class under an alias, so that it can be modified without invalidating the class namespace for this session
  *
  * @param		string			$className
  * @param		string|null		$alias
  *
  * @return		bool|string
  */
 public static function loadClassAliased($className, $alias = null)
 {
     if ($alias == null) {
         $alias = $className . '_alias_' . uniqid();
     }
     $path = XDT_CLI_Autoloader::getClassPath($className);
     if (!$path) {
         return false;
     }
     $contents = file_get_contents($path);
     $contents = preg_replace('/(.*class)\\s*?' . $className . '/', '$1 ' . $alias, $contents);
     $filePath = tempnam(sys_get_temp_dir(), 'xfcli');
     XDT_CLI_Helper::writeToFile($filePath, $contents);
     require_once $filePath;
     return $alias;
 }