ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

core.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 require_once( dirname( __FILE__ ).'/include/php/settings.php' );
17
18 require_once( dirname( __FILE__ ).'/include/php/core_utilities.php' );
19
20 require_once( dirname( __FILE__ ).'/include/php/package_manipulation.php' );
21
22 $PackageCache = array();
23
24 $RequestedClassName = '';
25
26 require_once( dirname( __FILE__ ).'/include/php/package_paths.php' );
27
28 require_once( dirname( __FILE__ ).'/include/php/package_version.php' );
29
60 function _get_full_class_name( $Name , $Version , $ROOT_DIR )
61 {
62 try
63 {
64 global $FullClassNameCache;
65 if( isset( $FullClassNameCache[ "$Name.$Version.$ROOT_DIR" ] ) )
66 {
67 return( $FullClassNameCache[ "$Name.$Version.$ROOT_DIR" ] );
68 }
69
70 $TopVersion = explode( '::' , $Version );
71 $TopVersion = array_pop( $TopVersion );
72
73 $RealPackageVersion = _get_package_real_version( $Name , $TopVersion , $ROOT_DIR );
74
75 $PackageClassName = str_replace( '.' , '_' , $Name.'_'.$RealPackageVersion );
76
77 global $FullClassNameCacheChanged;
78 $FullClassNameCacheChanged = true;
79
80 return( $FullClassNameCache[ "$Name.$Version.$ROOT_DIR" ] = $PackageClassName );
81 }
82 catch( Exception $e )
83 {
84 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
85 }
86 }
87
88 $TopPackageNameCacheChanged = false;
89 $TopPackageNameCache = array();
90
113 function _get_top_package_name( $PackageName )
114 {
115 try
116 {
117 global $TopPackageNameCache;
118 if( isset( $TopPackageNameCache[ $PackageName ] ) )
119 {
120 return( $TopPackageNameCache[ $PackageName ] );
121 }
122
123 $TopPackageName = explode( '::' , $PackageName );
124
125 global $TopPackageNameCacheChanged;
126 $TopPackageNameCacheChanged = true;
127
128 return( $TopPackageNameCache[ $PackageName ] = array_pop( $TopPackageName ) );
129 }
130 catch( Exception $e )
131 {
132 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
133 }
134 }
135
146 function _get_requested_class_name()
147 {
148 global $RequestedClassName;
149
150 return( $RequestedClassName );
151 }
152
163 $ObjectLabel = 'default';
164
183 function _set_object_label( $theObjectLabel )
184 {
185 try
186 {
187 global $ObjectLabel;
188 $ObjectLabel = $theObjectLabel;
189 }
190 catch( Exception $e )
191 {
192 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
193 }
194 }
195
196 require_once( dirname( __FILE__ ).'/include/php/rewrites.php' );
197
228 function _get_package_path_ex( $PackageName , $PackageRealVersion )
229 {
230 try
231 {
232 list( $PackageName , $PackageRealVersion ) = _get_package_info_after_rewrites(
233 $PackageName , $PackageRealVersion , __FILE__
234 );
235
236 $ROOT_DIR = _get_root_dir( $PackageName , $PackageRealVersion , INSTALL_DIR );
237
238 return( _get_package_path( $PackageName , $PackageRealVersion , $ROOT_DIR ) );
239 }
240 catch( Exception $e )
241 {
242 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
243 }
244 }
245
246 $PackagePathsCacheChanged = false;
247 $PackagePathsCache = array();
248
279 function _get_load_script_data( $PackageName , $PackageVersion , $PackageScriptPath )
280 {
281 try
282 {
283 $RootDirectory = _get_root_dir( $PackageName , $PackageVersion , INSTALL_DIR );
284 $PackageDirectory = _get_package_path( $PackageName , $PackageVersion , $RootDirectory );
285 $TopPackageName = _get_top_package_name( $PackageName );
286
287 $PackageClassName = 'unexisting_class';
288 $Exists = false;
289
290 if( file_exists( $PackageDirectory.'/'.$TopPackageName.'.php' ) )
291 {
292 $PackageClassName = _get_full_class_name( $TopPackageName , $PackageVersion , $RootDirectory );
293 $Exists = true;
294 }
295
296 return(
297 array( $PackageDirectory.'/'.$TopPackageName.'.php' , $Exists , $PackageClassName , $TopPackageName )
298 );
299 }
300 catch( Exception $e )
301 {
302 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
303 }
304 }
305
332 function _fill_package_paths_data( $PackageName , $PackageVersion , $PackageScriptPath )
333 {
334 try
335 {
336 global $ObjectLabel;
337 $Key = "$PackageName $PackageVersion $ObjectLabel";
338
339 global $PackagePathsCache;
340
341 list( $RPackageName , $RPackageVersion ) = _get_package_info_after_rewrites(
342 $PackageName , $PackageVersion , $PackageScriptPath
343 );
344
345 list( $ScriptPath , $Exists , $PackageClassName , $TopPackageName ) = _get_load_script_data(
346 $RPackageName , $RPackageVersion , $PackageScriptPath
347 );
348
349 $PackagePathsCache[ $Key ] = array(
350 'path' => $ScriptPath , 'exists' => $Exists ,
351 'class_name' => $PackageClassName , 'top_package_name' => $TopPackageName
352 );
353 }
354 catch( Exception $e )
355 {
356 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
357 }
358 }
359
386 function _fill_package_paths_cache( $PackageName , $PackageVersion , $PackageScriptPath )
387 {
388 try
389 {
390 global $ObjectLabel;
391 $Key = "$PackageName $PackageVersion $ObjectLabel";
392
393 global $PackagePathsCache;
394 if( isset( $PackagePathsCache[ $Key ] ) )return;
395
396 _fill_package_paths_data( $PackageName , $PackageVersion , $PackageScriptPath );
397
398 global $PackagePathsCacheChanged;
399 $PackagePathsCacheChanged = true;
400 }
401 catch( Exception $e )
402 {
403 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
404 }
405 }
406
437 function _try_fetch_from_cache( $PackageName , $PackageVersion )
438 {
439 try
440 {
441 global $ObjectLabel;
442 $Key = "$PackageName $PackageVersion $ObjectLabel";
443
444 global $PackagePathsCache;
445 if( isset( $PackagePathsCache[ $Key ] ) )
446 {
447 global $PackageCache;
448 if( isset( $PackageCache[ $PackagePathsCache[ $Key ][ 'path' ] ] ) )
449 {
450 global $RequestedClassName;
451 $RequestedClassName = $PackagePathsCache[ $Key ][ 'class_name' ];
452
453 return( array( true , $PackageCache[ $PackagePathsCache[ $Key ][ 'path' ] ] ) );
454 }
455 }
456
457 return( array( false , false ) );
458 }
459 catch( Exception $e )
460 {
461 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
462 }
463 }
464
491 function _package_script_fast_load( $PackageName , $PackageVersion )
492 {
493 try
494 {
495 /* на этом этапе мы уже знаем где лежит пакет $PackageName.$PackageVersion */
496 global $ObjectLabel;
497 $Key = "$PackageName $PackageVersion $ObjectLabel";
498
499 global $PackagePathsCache;
500 $PackageInfo = $PackagePathsCache[ $Key ];
501
502 if( $PackageInfo[ 'exists' ] )
503 {
504 require_once( $PackageInfo[ 'path' ] );
505
506 $RootDirectory = _get_root_dir( $PackageName , $PackageVersion , INSTALL_DIR );
507
508 return( _get_full_class_name( $PackageInfo[ 'top_package_name' ] , $PackageVersion , $RootDirectory ) );
509 }
510 else
511 {
512 return( 'unexisting_class' );
513 }
514 }
515 catch( Exception $e )
516 {
517 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
518 }
519 }
520
547 function _get_package_directory( $PackageName , $PackageVersion )
548 {
549 try
550 {
551 $RootDirectory = _get_root_dir( $PackageName , $PackageVersion , INSTALL_DIR );
552 $PackageDirectory = _get_package_path( $PackageName , $PackageVersion , $RootDirectory );
553 $TopPackageName = _get_top_package_name( $PackageName );
554
555 return( $PackageDirectory );
556 }
557 catch( Exception $e )
558 {
559 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
560 }
561 }
562
585 function _fill_package_cache( $PackageClassName , $Key )
586 {
587 try
588 {
589 global $PackageCache;
590 if( isset( $PackageCache[ $Key ] ) === false )
591 {
592 global $RequestedClassName;
593 $RequestedClassName = false;
594 $PackageCache[ $Key ] = false;
595 if( class_exists( $PackageClassName ) )
596 {
597 $PackageCache[ $Key ] = new $PackageClassName();
598 $RequestedClassName = $PackageClassName;
599 }
600 }
601 }
602 catch( Exception $e )
603 {
604 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
605 }
606 }
607
630 function _store_package_object( $PackageClassName , $Key )
631 {
632 try
633 {
634 _fill_package_cache( $PackageClassName , $Key );
635
636 global $PackageCache;
637 global $PackagePathsCache;
638 if( isset( $PackagePathsCache[ $Key ] ) )
639 {
640 $PackageInfo = $PackagePathsCache[ $Key ];
641 if( isset( $PackageCache[ $PackageInfo[ 'path' ] ] ) === false )
642 {
643 $PackageCache[ $PackageInfo[ 'path' ] ] = $PackageCache[ $Key ];
644 }
645 }
646 else
647 {
648 throw( new Exception( "The path for key $Key does not exist" ) );
649 }
650 }
651 catch( Exception $e )
652 {
653 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
654 }
655 }
656
679 function _store_package_path( $PackageName , $PackageVersion )
680 {
681 try
682 {
683 $PackageDirectory = _get_package_directory( $PackageName , $PackageVersion );
684
685 global $LoadedPackagesPaths;
686 $LoadedPackagesPaths [ "$PackageName.$PackageVersion" ] = array(
687 'directory' => $PackageDirectory , 'package_name' => $PackageName , 'package_version' => $PackageVersion
688 );
689 }
690 catch( Exception $e )
691 {
692 $Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
693 }
694 }
695
722 function _get_package_relative_path_ex( $PackageName , $PackageVersion )
723 {
724 try
725 {
726 return(
727 _get_package_relative_path( _get_package_path_ex( $PackageName , $PackageVersion ).'/unexisting_file' )
728 );
729 }
730 catch( Exception $e )
731 {
732 $Args = func_get_args();
733 _throw_exception_object( __FUNCTION__ , $Args , $e );
734 }
735 }
736
737 require_once( dirname( __FILE__ ).'/include/php/core_cache.php' );
738 require_once( dirname( __FILE__ ).'/include/php/functional_programming.php' );
739 require_once( dirname( __FILE__ ).'/include/php/array_functions.php' );
740 require_once( dirname( __FILE__ ).'/include/php/core_public_api.php' );
741
742 ?>