Changeset 111
- Timestamp:
- 01/18/07 17:56:16 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/star/StarArchive.php
r93 r111 99 99 $this->writer->open(); 100 100 if (strlen($this->preface) > 0) { 101 $preFace = file_get_contents( 'StarLoader.php');101 $preFace = file_get_contents(dirname(__FILE__) . '/StarLoader.php'); 102 102 $preFace .= "<?php stream_wrapper_register('star', 'StarLoader'); ?>" . trim($this->preface) . "<?php __halt_compiler();"; 103 103 $this->writer->write($preFace); trunk/src/main/php/net/stubbles/star/StarClassRegistry.php
r110 r111 18 18 * @var bool 19 19 */ 20 protected static $initDone = false;20 protected static $initDone = false; 21 21 /** 22 22 * path to star files … … 24 24 * @var string 25 25 */ 26 protected static $libPath = null;26 protected static $libPathes = array(); 27 27 /** 28 28 * list of classes and the file where they are in … … 30 30 * @var array<string,string> 31 31 */ 32 protected static $classes = array();32 protected static $classes = array(); 33 33 /** 34 34 * list of files and the classes they contain … … 36 36 * @var array<string,array<string>> 37 37 */ 38 protected static $files = array();38 protected static $files = array(); 39 39 40 40 /** 41 41 * set the path to the star files 42 42 * 43 * @param string $libPath 43 * @param string $libPath path to lib files 44 * @param bool $recursive optional recurse into sub directories of lib path 44 45 */ 45 public static function setLibPath($libPath)46 public static function addLibPath($libPath, $recursive = true) 46 47 { 47 self::$libPath = $libPath;48 self::$libPathes[$libPath] = $recursive; 48 49 } 49 50 … … 56 57 public static function getFileForClass($fqClassName) 57 58 { 59 self::init(); 58 60 if (isset(self::$classes[$fqClassName]) == true) { 59 61 return self::$classes[$fqClassName]; 62 } 63 64 return null; 65 } 66 67 /** 68 * returns the uri for the given class 69 * 70 * @param string $fqClassName the full qualified class name 71 * @return string 72 */ 73 public static function getUriForClass($fqClassName) 74 { 75 self::init(); 76 if (isset(self::$classes[$fqClassName]) == true) { 77 return 'star://' . self::$classes[$fqClassName] . '?' . $fqClassName; 60 78 } 61 79 … … 71 89 public function getClassNamesFromFile($file) 72 90 { 91 self::init(); 73 92 if (isset(self::$files[$file]) == true) { 74 93 return self::$files[$file]; … … 83 102 protected static function init() 84 103 { 85 if (true == self::$initDone) {104 if (true === self::$initDone) { 86 105 return; 87 106 } 88 107 89 if ( null == self::$libPath) {90 self::$libPath = getcwd();108 if (count(self::$libPathes) == 0) { 109 self::$libPathes[realpath(getcwd() . '/../lib')] = true; 91 110 } 92 111 93 if (file_exists(self::$libPath . '/.cache') == true) { 94 $cache = unserialize(file_get_contents(self::$libPath . '/.cache')); 95 self::$files = $cache['files']; 96 self::$classes = $cache['classes']; 97 self::$initDone = true; 98 return; 99 } 100 101 $dirIt = new DirectoryIterator(self::$libPath); 102 foreach ($dirIt as $file) { 103 if ($file->isFile() == false || substr($file->getPathname(), -5) != '.star') { 112 foreach (self::$libPathes as $libPath => $recursive) { 113 if (file_exists($libPath . '/.cache') == true) { 114 $cache = unserialize(file_get_contents($libPath . '/.cache')); 115 self::$files = array_merge(self::$files, $cache['files']); 116 self::$classes = array_merge(self::$classes, $cache['classes']); 117 self::$initDone = true; 104 118 continue; 105 119 } 106 120 107 $archiveData = StarLoader::acquire($file->getPathname()); 108 if (empty($archiveData) == true) { 109 continue; 121 if (true === $recursive) { 122 $dirIt = new RecursiveDirectoryIterator($libPath); 123 } else { 124 $dirIt = new DirectoryIterator($libPath); 110 125 } 111 126 112 self::$files[$file->getPath()] = array_keys($archiveData); 127 $cache['files'] = array(); 128 $cache['classes'] = array(); 129 foreach ($dirIt as $file) { 130 if ($file->isFile() == false || substr($file->getPathname(), -5) != '.star') { 131 continue; 132 } 133 134 $archiveData = StarLoader::acquire($file->getPathname()); 135 if (empty($archiveData) == true) { 136 continue; 137 } 138 139 $classes = array_keys($archiveData); 140 self::$files[$file->getPath()] = $classes; 141 $cache['files'][$file->getPath()] = $classes; 142 143 foreach ($archiveData as $fqClassName => $storeData) { 144 self::$classes[$fqClassName] = $file->getPathname(); 145 $cache['classes'][$fqClassName] = $file->getPathname(); 146 } 147 } 113 148 114 foreach ($archiveData as $fqClassName => $storeData) { 115 self::$classes[$fqClassName] = $file->getPathname(); 116 } 149 file_put_contents($libPath . '/.cache', serialize($cache)); 150 self::$initDone = true; 117 151 } 118 119 $cache = array('files' => self::$files, 'classes' => self::$classes);120 file_put_contents(self::$libPath . '/.cache', serialize($cache));121 self::$initDone = true;122 152 } 123 153 }
