ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

settings.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
26 class settings_1_0_0{
27
38 var $SettingsList = false;
39
50 var $CachedMultyFS = false;
51 var $SettingsUtilities = false;
52
67 function __construct()
68 {
69 try
70 {
71 $this->SettingsUtilities = get_package( 'settings::settings_utilities' , 'last' , __FILE__ );
72 }
73 catch( Exception $e )
74 {
75 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
76 }
77 }
78
101 function load_settings( $Settings , $Separator = ';' )
102 {
103 try
104 {
105 $this->SettingsList = array();
106 $this->append_settings( $Settings , $Separator );
107 }
108 catch( Exception $e )
109 {
110 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
111 }
112 }
113
132 function delete_setting( $Name )
133 {
134 try
135 {
136 if( isset( $this->SettingsList[ $Name ] ) === false )
137 {
138 return;
139 }
140
141 $New = array();
142 foreach( $this->SettingsList as $Key => $Value )
143 {
144 if( $Key !== $Name )
145 {
146 $New[ $Key ] = $Value;
147 }
148 }
149 $this->SettingsList = $New;
150 }
151 catch( Exception $e )
152 {
153 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
154 }
155 }
156
179 function append_settings( $Settings , $Separator = ';' )
180 {
181 try
182 {
183 if( $Settings === false || $Settings === '' || $Settings === null )
184 {
185 return;
186 }
187
188 if( is_array( $Settings ) === false )
189 {
190 $Settings = $this->SettingsUtilities->transform_settings( $Settings , $Separator );
191 }
192
193 $this->SettingsList = array_merge(
194 $this->SettingsList , $this->SettingsUtilities->load_settings( $Settings )
195 );
196 }
197 catch( Exception $e )
198 {
199 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
200 }
201 }
202
217 function load_from_http()
218 {
219 try
220 {
221 $this->SettingsList = array_merge( $_POST , $_GET );
222 }
223 catch( Exception $e )
224 {
225 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
226 }
227 }
228
247 function get_raw_settings()
248 {
249 try
250 {
251 return( $this->SettingsList );
252 }
253 catch( Exception $e )
254 {
255 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
256 }
257 }
258
277 function add_settings_from_object( &$Settings )
278 {
279 try
280 {
281 $this->SettingsList = array_merge( $this->SettingsList , $Settings->SettingsList );
282 }
283 catch( Exception $e )
284 {
285 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
286 }
287 }
288
307 function load_raw_settings( &$Settings )
308 {
309 try
310 {
311 $this->SettingsList = $Settings;
312 }
313 catch( Exception $e )
314 {
315 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
316 }
317 }
318
337 function append_raw_settings( &$Settings )
338 {
339 try
340 {
341 $this->SettingsList = array_merge( $this->SettingsList , $Settings );
342 }
343 catch( Exception $e )
344 {
345 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
346 }
347 }
348
367 function get_all_settings()
368 {
369 try
370 {
371 $Str = array();
372
373 foreach( $this->SettingsList as $Key => $Value )
374 {
375 $Str [] = "$Key=$Value";
376 }
377
378 $Str = implode( ';' , $Str );
379
380 return( $Str );
381 }
382 catch( Exception $e )
383 {
384 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
385 }
386 }
387
406 private function get_config( $FilePath )
407 {
408 try
409 {
410 if( $this->CachedMultyFS === false )
411 {
412 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
413 }
414
415 return( $this->CachedMultyFS->file_get_contents( $FilePath ) );
416 }
417 catch( Exception $e )
418 {
419 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
420 }
421 }
422
445 function load_file( $FilePath , $Separator = ';' )
446 {
447 try
448 {
449 $this->load_settings( $this->get_config( $FilePath ) , $Separator );
450 }
451 catch( Exception $e )
452 {
453 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
454 }
455 }
456
479 function append_file( $FilePath , $Separator = ';' )
480 {
481 try
482 {
483 $this->append_settings( $this->get_config( $FilePath ) , $Separator );
484 }
485 catch( Exception $e )
486 {
487 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
488 }
489 }
490
517 function load_package_settings( $PackageName , $PackageVersion , $FileName )
518 {
519 try
520 {
521 $PackageDirectory = _get_package_path_ex( $PackageName , $PackageVersion );
522
523 $this->load_file( $PackageDirectory."/conf/$FileName" );
524 }
525 catch( Exception $e )
526 {
527 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
528 }
529 }
530
553 function define( $Name , $DefaultValue = '_throw_exception' )
554 {
555 try
556 {
557 DEFINE( $Name , $this->get_setting( $Name , $DefaultValue ) );
558 }
559 catch( Exception $e )
560 {
561 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
562 }
563 }
564
591 function setting_exists( $Name , $ThrowException = false )
592 {
593 try
594 {
595 if( $this->SettingsList !== false && isset( $this->SettingsList[ $Name ] ) )
596 {
597 return( true );
598 }
599
600 if( $ThrowException )
601 {
602 throw( new Exception( "Setting \"$Name\" does not exist" ) );
603 }
604
605 return( false );
606 }
607 catch( Exception $e )
608 {
609 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
610 }
611 }
612
639 function get_setting( $Name , $DefaultValue = '_throw_exception' )
640 {
641 try
642 {
643 if( $this->SettingsList !== false && isset( $this->SettingsList[ $Name ] ) )
644 {
645 return( $this->SettingsList[ $Name ] );
646 }
647 if( $DefaultValue === '_throw_exception' )
648 {
649 throw( new Exception( 'Setting "'.$Name.'" was not found' ) );
650 }
651
652 return( $DefaultValue );
653 }
654 catch( Exception $e )
655 {
656 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
657 }
658 }
659
686 function get_default_values( $SettingsNames , $DefaultValues )
687 {
688 try
689 {
690 $DefaultValues = explode( ',' , $DefaultValues );
691
692 $c1 = count( $DefaultValues );
693 $c2 = count( $SettingsNames );
694
695 if( $c1 < $c2 )
696 {
697 for( $i = 0 ; $i < $c2 - $c1 ; $i++ )
698 {
699 $DefaultValues [] = '_throw_exception';
700 }
701 }
702
703 return( $DefaultValues );
704 }
705 catch( Exception $e )
706 {
707 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
708 }
709 }
710
737 function get_settings( $SettingsNames , $DefaultValues = '_throw_exception' )
738 {
739 try
740 {
741 $Values = array();
742 $SettingsNames = explode( ',' , $SettingsNames );
743
744 $DefaultValues = $this->get_default_values( $SettingsNames , $DefaultValues );
745
746 foreach( $SettingsNames as $i => $Name )
747 {
748 $Values [] = $this->get_setting( $Name , $DefaultValues[ $i ] );
749 }
750
751 return( $Values );
752 }
753 catch( Exception $e )
754 {
755 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
756 }
757 }
758
781 function set_setting( $Name , $Value )
782 {
783 try
784 {
785 if( $this->SettingsList !== false )
786 {
787 $this->SettingsList[ $Name ] = $Value;
788 }
789 }
790 catch( Exception $e )
791 {
792 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
793 }
794 }
795
818 function set_undefined( $Name , $Value )
819 {
820 try
821 {
822 if( $this->SettingsList !== false && isset( $this->SettingsList[ $Name ] ) === false )
823 {
824 $this->SettingsList[ $Name ] = $Value;
825 }
826 }
827 catch( Exception $e )
828 {
829 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
830 }
831 }
832
849 function clear()
850 {
851 try
852 {
853 $this->SettingsList = array();
854 }
855 catch( Exception $e )
856 {
857 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
858 }
859 }
860
879 function remove_setting( $Name )
880 {
881 try
882 {
883 remove_fields( $this->SettingsList , array( $Name ) );
884 }
885 catch( Exception $e )
886 {
887 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
888 }
889 }
890
909 function __toString()
910 {
911 try
912 {
913 return( serialize( $this->SettingsList ) );
914 }
915 catch( Exception $e )
916 {
917 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
918 }
919 }
920 }
921
922 ?>