ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

package_paths.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
16 $PackageRelativePathCacheChanged = false;
17 $PackageRelativePathCache = array();
18
41 function _get_package_relative_path( $File )
42 {
43 global $PackageRelativePathCache;
44 if( isset( $PackageRelativePathCache[ $File ] ) )
45 {
46 return( $PackageRelativePathCache[ $File ] );
47 }
48
49 $RelativePath = '';
50 $Dir = dirname( $File );
51 do
52 {
53 $RelativePath = '/packages/'.basename( $Dir ).$RelativePath;
54 $Dir = dirname( dirname( $Dir ) );
55 }
56 while( file_exists( $Dir.'/../../packages/core/data/package_list' ) );
57
58 global $PackageRelativePathCacheChanged;
59 $PackageRelativePathCacheChanged = true;
60
61 return( $PackageRelativePathCache[ $File ] = '.'.$RelativePath );
62 }
63
64 $PackagePathCacheChanged = false;
65 $PackagePathCache = array();
66
93 function get_top_data( $PackageName , $PackageVersion )
94 {
95 try
96 {
99 $PackageName = explode( '::' , $PackageName );
100 $PackageName = array_pop( $PackageName );
101
104 $PackageVersion = explode( '::' , $PackageVersion );
105 $PackageVersion = array_pop( $PackageVersion );
106
107 return( array( $PackageName , $PackageVersion ) );
108 }
109 catch( Exception $e )
110 {
111 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
112 }
113 }
114
115 $FetchPackagePathCacheChanged = false;
116 $FetchPackagePathCache = array();
117
148 function _fetch_package_path( $PackageName , $Version , $ROOT_DIR = INSTALL_DIR )
149 {
150 try
151 {
152 global $PackagePathCache;
153
154 $Info = _load_packages_list( $ROOT_DIR );
155
156 $Version = _get_package_real_version( $PackageName , $Version , $ROOT_DIR );
157
158 $PackageNameAndVersion = $PackageName.'.'.$Version;
159
160 foreach( $Info as $pi )
161 {
162 if( $pi[ 0 ][ 0 ] === $PackageNameAndVersion[ 0 ] && strpos( $pi[ 0 ] , $PackageNameAndVersion ) === 0 )
163 {
164 return( $ROOT_DIR.'/packages/'.$pi[ 1 ] );
165 }
166 }
167
168 throw( new Exception( 'Package '.$PackageName. ' with version '.$Version.' was not found' ) );
169 }
170 catch( Exception $e )
171 {
172 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
173 }
174 }
175
206 function _get_package_path( $PackageName , $PackageVersion , $ROOT_DIR = INSTALL_DIR )
207 {
208 try
209 {
210 global $PackagePathCache;
211 $Key = "$PackageName $PackageVersion $ROOT_DIR";
212
213 if( isset( $PackagePathCache[ $Key ] ) === false )
214 {
215 list( $PackageName , $PackageVersion ) = get_top_data( $PackageName , $PackageVersion );
216
217 global $PackagePathCacheChanged;
218 $PackagePathCacheChanged = true;
219 $PackagePathCache[ $Key ] = _fetch_package_path( $PackageName , $PackageVersion , $ROOT_DIR );
220 }
221
222 return( $PackagePathCache[ $Key ] );
223 }
224 catch( Exception $e )
225 {
226 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
227 }
228 }
229
230 $RootDirCacheChanged = false;
231 $RootDirCache = array();
232
263 function _prepare_data( $thePackageName , $thePackageVersion , $ROOT_DIR = INSTALL_DIR )
264 {
265 try
266 {
267 $PackageNames = explode( '::' , $thePackageName );
268 $PackageVersions = explode( '::' , $thePackageVersion );
269 $PackageName = substr_replace( $thePackageName , '' , 0 , strlen( $PackageNames[ 0 ] ) + 2 );
270 $PackageVersion = substr_replace( $thePackageVersion , '', 0 , strlen( $PackageVersions[ 0 ] ) + 2 );
271
272 $PackagePath = _get_package_path(
273 $PackageNames[ 0 ] ,
274 _get_package_real_version( $PackageNames[ 0 ] , $PackageVersions[ 0 ] , $ROOT_DIR ) , $ROOT_DIR
275 );
276 return( array( $PackagePath , $PackageName , $PackageVersion ) );
277 }
278 catch( Exception $e )
279 {
280 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
281 }
282 }
283
314 function _get_root_dir( $thePackageName , $thePackageVersion , $ROOT_DIR = INSTALL_DIR )
315 {
316 try
317 {
318 global $RootDirCacheChanged , $RootDirCache;
319 $Key = "$thePackageName $thePackageVersion $ROOT_DIR";
320
321 if( isset( $RootDirCache[ $Key ] ) == false )
322 {
323 list( $PackagePath , $PackageName , $PackageVersion ) =
324 _prepare_data( $thePackageName , $thePackageVersion , $ROOT_DIR );
325
326 $RootDirCacheChanged = true;
327
328 $RootDirCache[ $Key ] = $PackageName == '' ? $ROOT_DIR : _get_root_dir(
329 $PackageName , $PackageVersion , $PackagePath
330 );
331 }
332
333 return( $RootDirCache[ $Key ] );
334 }
335 catch( Exception $e )
336 {
337 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
338 }
339 }
340
341 ?>