Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezini.php
Go to the documentation of this file.
1 <?php
51 class eZINI
52 {
58 const CONFIG_CACHE_DIR = 'var/cache/ini/';
59
65 const CONFIG_CACHE_REV = 2;
66
67
74 const INJECTED_PATH = 'injected';
75
84 static protected $checkFileMtime = null;
85
92 static protected $filePermission = null;
93
99 static protected $instances = array();
100
106 static protected $cacheEnabled = true;
107
113 static protected $debugEnabled = false;
114
120 static protected $textCodecEnabled = true;
121
132 static protected $injectedSettings = array();
133
146 static protected $injectedMergeSettings = array();
147
162 public function __construct( $fileName = 'site.ini', $rootDir = '', $useTextCodec = null, $useCache = null, $useLocalOverrides = null, $directAccess = false, $addArrayDefinition = false, $load = true )
163 {
164 $this->Charset = 'utf8';
165 if ( $fileName == '' )
166 $fileName = 'site.ini';
167 if ( $rootDir !== false && $rootDir == '' )
168 $rootDir = 'settings';
169 if ( $useCache === null )
170 $useCache = self::isCacheEnabled();
171 if ( eZINI::isNoCacheAdviced() )
172 {
173 $useCache = false;
174 }
175 if ( $useTextCodec === null )
176 $useTextCodec = self::isTextCodecEnabled();
177
178 $this->UseTextCodec = $useTextCodec;
179 $this->Codec = null;
180 $this->FileName = $fileName;
181 $this->RootDir = $rootDir;
182 $this->UseCache = $useCache;
183 $this->DirectAccess = $directAccess;
184 $this->UseLocalOverrides = $useLocalOverrides;
185 $this->AddArrayDefinition = $addArrayDefinition;
186
187 if ( self::$checkFileMtime === null )
188 {
189 if ( defined('EZP_INI_FILEMTIME_CHECK') )
190 self::$checkFileMtime = EZP_INI_FILEMTIME_CHECK;
191 else
192 self::$checkFileMtime = true;
193 }
194
195 if ( self::$GlobalOverrideDirArray === null )
196 {
197 self::$GlobalOverrideDirArray = self::defaultOverrideDirs();
198 }
199
200 if ( $this->UseLocalOverrides == true )
201 {
202 $this->LocalOverrideDirArray = self::$GlobalOverrideDirArray;
203 }
204
205 if ( self::$filePermission === null )
206 {
207 if ( defined( 'EZP_INI_FILE_PERMISSION' ) )
208 self::$filePermission = EZP_INI_FILE_PERMISSION;
209 else
210 self::$filePermission = 0666;
211 }
212
213 if ( $load )
214 $this->load();
215 }
216
220 function filename()
221 {
222 return $this->FileName;
223 }
224
232 static function isCacheEnabled()
233 {
234 return self::$cacheEnabled;
235 }
236
241 static function isNoCacheAdviced()
242 {
243 if ( !isset( $GLOBALS['eZSiteBasics'] ) )
244 return false;
245 $siteBasics = $GLOBALS['eZSiteBasics'];
246 if ( !isset( $siteBasics['no-cache-adviced'] ) )
247 return false;
248 return $siteBasics['no-cache-adviced'];
249 }
250
259 static function setIsCacheEnabled( $enabled )
260 {
261 self::$cacheEnabled = (bool)$enabled;
262 }
263
273 static function isDebugEnabled()
274 {
275 return self::$debugEnabled;
276 }
277
286 static function setIsDebugEnabled( $enabled )
287 {
288 self::$debugEnabled = (bool)$enabled;
289 }
290
299 static function isTextCodecEnabled()
300 {
301 return self::$textCodecEnabled;
302 }
303
311 static function setIsTextCodecEnabled( $enabled )
312 {
313 self::$textCodecEnabled = (bool)$enabled;
314 }
315
326 static function parameterSet( $fileName = null, $rootDir = null, &$section=false, &$parameter=false )
327 {
328 if( $fileName == null )
329 $fileName = 'site.ini';
330
331 if( $rootDir == null )
332 $fileName = 'settings';
333
334 if ( !eZINI::exists( $fileName, $rootDir ) )
335 return false;
336
337 $iniInstance = eZINI::instance( $fileName, $rootDir, null, null, null, true );
338 return $iniInstance->hasVariable( $section, $parameter );
339 }
340
346 static function exists( $fileName = "site.ini", $rootDir = "settings" )
347 {
348 if ( $fileName == "" )
349 $fileName = "site.ini";
350 if ( $rootDir == "" )
351 $rootDir = "settings";
352 if ( $rootDir[0] !== "/" )
353 $rootDir = __DIR__ . "/../../../" . $rootDir;
354 if ( file_exists( $rootDir . '/' . $fileName ) )
355 return true;
356 else if ( file_exists( $rootDir . '/' . $fileName . '.append.php' ) )
357 return true;
358 else if ( file_exists( $rootDir . '/' . $fileName . '.append' ) )
359 return true;
360 return false;
361 }
362
369 public function load( $reset = true )
370 {
371 if ( $this->UseCache )
372 {
373 $this->loadCache( $reset );
374 }
375 else
376 {
377 $this->parse( false, false, $reset );
378 }
379 }
380
388 public function loadPlacement( $reset = true )
389 {
390 if ( $this->UseCache )
391 {
392 $this->loadCache( $reset, true );
393 }
394 else
395 {
396 $this->parse( false, false, $reset, true );
397 }
398 if ( isset( self::$injectedSettings[$this->FileName] ) )
399 {
400 foreach ( self::$injectedSettings[$this->FileName] as $blockName => $variables )
401 {
402 foreach ( $variables as $varName => $varValue )
403 {
404 if ( is_array( $varValue ) )
405 {
406 $this->BlockValuesPlacement[$blockName][$varName] = array_fill_keys(
407 array_keys( $varValue ),
408 self::INJECTED_PATH
409 );
410 }
411 else
412 {
413 $this->BlockValuesPlacement[$blockName][$varName] = self::INJECTED_PATH;
414 }
415 }
416 }
417 }
418
419 if ( isset( self::$injectedMergeSettings[$this->FileName] ) )
420 {
421 foreach ( self::$injectedMergeSettings[$this->FileName] as $blockName => $variables )
422 {
423 foreach ( $variables as $varName => $varValue )
424 {
425 if ( !is_array( $varValue ) || !is_array( $this->BlockValuesPlacement[$blockName][$varName] ) )
426 {
427 throw new RuntimeException( "injected-merge-settings can only reference and contain array values" );
428 }
429
430 $this->BlockValuesPlacement[$blockName][$varName] = array_merge(
431 $this->BlockValuesPlacement[$blockName][$varName],
432 array_fill_keys(
433 array_keys( $varValue ),
434 self::INJECTED_PATH
435 )
436 );
437 }
438 }
439 }
440 }
441
448 function findInputFiles( &$inputFiles, &$iniFile )
449 {
450 $iniFile = __DIR__ . "/../../../";
451 if ( $this->RootDir !== false )
452 $iniFile .= eZDir::path( array( $this->RootDir, $this->FileName ) );
453 else
454 $iniFile .= eZDir::path( array( $this->FileName ) );
455
456 $inputFiles = array();
457
458 if ( $this->FileName === 'override.ini' )
459 {
460 eZExtension::prependExtensionSiteAccesses( false, $this, true, false, false );
461 }
462
463 if ( file_exists( $iniFile ) )
464 $inputFiles[] = $iniFile;
465
466 // try the same file name with '.append.php' replace with '.append'
467 if ( strpos($iniFile, '.append.php') !== false && preg_match('#^(.+.append).php$#i', $iniFile, $matches ) && file_exists( $matches[1] ) )
468 $inputFiles[] = $matches[1];
469
470 if ( strpos($iniFile, '.php') === false && file_exists ( $iniFile . '.php' ) )
471 $inputFiles[] = $iniFile . '.php';
472
473 if ( $this->DirectAccess )
474 {
475 if ( file_exists ( $iniFile . '.append' ) )
476 {
477 // recursion eZDebug::writeStrict( "INI files with *.ini.append suffix is DEPRECATED, use *.ini or *.ini.append.php instead: $iniFile.append", __METHOD__ );
478 $inputFiles[] = $iniFile . '.append';
479 }
480
481 if ( file_exists ( $iniFile . '.append.php' ) )
482 $inputFiles[] = $iniFile . '.append.php';
483 }
484 else
485 {
486 $overrideDirs = $this->overrideDirs();
487 $fileName = $this->FileName;
488 $rootDir = $this->RootDir;
489 foreach ( $overrideDirs as $overrideDirItem )
490 {
491 $overrideDir = $overrideDirItem[0];
492 $isGlobal = $overrideDirItem[1];
493 if ( $isGlobal )
494 $overrideFile = eZDir::path( array( $overrideDir, $fileName ) );
495 else
496 $overrideFile = eZDir::path( array( $rootDir, $overrideDir, $fileName ) );
497
498 if ( file_exists( $overrideFile . '.php' ) )
499 {
500 // recursion eZDebug::writeStrict( "INI files with *.ini.php suffix is DEPRECATED, use *.ini or *.ini.append.php instead: $overrideFile.php", __METHOD__ );
501 $inputFiles[] = $overrideFile . '.php';
502 }
503
504 if ( file_exists( $overrideFile ) )
505 {
506 $inputFiles[] = $overrideFile;
507 }
508
509 if ( file_exists( $overrideFile . '.append.php' ) )
510 {
511 $inputFiles[] = $overrideFile . '.append.php';
512 }
513
514 if ( file_exists( $overrideFile . '.append' ) )
515 {
516 // recursion eZDebug::writeStrict( "INI files with *.ini.append suffix is DEPRECATED, use *.ini or *.ini.append.php instead: $overrideFile.append", __METHOD__ );
517 $inputFiles[] = $overrideFile . '.append';
518 }
519 }
520 }
521 }
522
527 protected function cacheFileName( $placement = false )
528 {
529 $cacheFileName = $this->FileName . '-' . $this->RootDir . '-' . $this->DirectAccess;
530
531 if ( !$this->DirectAccess )
532 {
533 $cacheFileName .= '-' . serialize( $this->overrideDirs() );
534 }
535 if ( $this->UseTextCodec )
536 {
537 $cacheFileName .= '-' . eZTextCodec::internalCharset();
538 }
539 if ( $placement )
540 {
541 $cacheFileName .= '-placement:' . $placement;
542 }
543 $filePreFix = explode( '.', $this->FileName);
544 return $filePreFix[0] . '-' . md5( $cacheFileName ) . '.php';
545 }
546
556 function loadCache( $reset = true, $placement = false )
557 {
558 eZDebug::accumulatorStart( 'ini', 'Ini load', 'Load cache' );
559 if ( $reset )
560 $this->reset();
561 // ### EXP-MULTI-SITE-OVERRIDE-SETTINGS ###
562 // $cachedDir = __DIR__ . "/../../../" . self::CONFIG_CACHE_DIR;
563 if ( !isset( $GLOBALS['eZINI_CONFIG_CACHE_DIR'] ) )
564 $GLOBALS['eZINI_CONFIG_CACHE_DIR'] = __DIR__ . "/../../../" . self::CONFIG_CACHE_DIR;
565 $cachedDir = $GLOBALS['eZINI_CONFIG_CACHE_DIR'];
566
567 $fileName = $this->cacheFileName( $placement );
568 $cachedFile = $cachedDir . $fileName;
569 if ( $placement )
570 {
571 $this->PlacementCacheFile = $cachedFile;
572 }
573 else
574 {
575 $this->CacheFile = $cachedFile;
576 }
577
578 $data = false;// this will contain cache data if cache data is valid
579 if ( file_exists( $cachedFile ) )
580 {
581 if ( self::isDebugEnabled() )
582 eZDebug::writeNotice( "Loading cache '$cachedFile' for file '" . $this->FileName . "'", __METHOD__ );
583
584 include( $cachedFile );
585
586 if ( !isset( $data['rev'] ) || $data['rev'] != eZINI::CONFIG_CACHE_REV )
587 {
588 if ( self::isDebugEnabled() )
589 eZDebug::writeNotice( "Old structure in cache file used, recreating '$cachedFile' to new structure", __METHOD__ );
590 $data = false;
591 $this->reset();
592 }
593 else if ( self::$checkFileMtime === true || self::$checkFileMtime === $this->FileName )
594 {
595 eZDebug::accumulatorStart( 'ini_check_mtime', 'Ini load', 'Check MTime' );
596 $currentTime = time();
597 $cacheCreatedTime = strtotime( $data['created'] );
598 $iniFile = $data['file'];// used by findInputFiles further down
599 $inputFiles = $data['files'];
600 foreach ( $inputFiles as $inputFile )
601 {
602 $fileTime = file_exists( $inputFile ) ? filemtime( $inputFile ) : false;
603 if ( $fileTime === false )// Refresh cache & input files if file is gone
604 {
605 unset( $inputFiles );
606 $data = false;
607 $this->reset();
608 break;
609 }
610 else if ( $fileTime > $currentTime )
611 {
612 eZDebug::writeError( 'Input file "' . $inputFile . '" has a timestamp higher then current time, ignoring to avoid infinite recursion!', __METHOD__ );
613 }
614 else if ( $fileTime > $cacheCreatedTime )// Refresh cache if file has been changed
615 {
616 $data = false;
617 $this->reset();
618 break;
619 }
620 }
621 eZDebug::accumulatorStop( 'ini_check_mtime' );
622 }
623 }
624
625 if ( $data )// if we have cache data on this point, use it
626 {
627 $this->Charset = $data['charset'];
628 $this->ModifiedBlockValues = array();
629 if ( $placement )
630 $this->BlockValuesPlacement = $data['val'];
631 else
632 $this->BlockValues = $data['val'];
633 unset( $data );
634 }
635 else
636 {
637 if ( !isset( $inputFiles ) )// use $inputFiles from cache if defined
638 {
639 eZDebug::accumulatorStart( 'ini_find_files', 'Ini load', 'Find INI Files' );
640 $this->findInputFiles( $inputFiles, $iniFile );
641 eZDebug::accumulatorStop( 'ini_find_files' );
642 if ( count( $inputFiles ) === 0 )
643 {
644 eZDebug::accumulatorStop( 'ini' );
645 return false;
646 }
647 }
648
649 eZDebug::accumulatorStart( 'ini_files_parse', 'Ini load', 'Parse' );
650 $this->parse( $inputFiles, $iniFile, false, $placement );
651 eZDebug::accumulatorStop( 'ini_files_parse' );
652 eZDebug::accumulatorStart( 'ini_files_save', 'Ini load', 'Save Cache' );
653 $cacheSaved = $this->saveCache( $cachedDir, $cachedFile, $placement ? $this->BlockValuesPlacement : $this->BlockValues, $inputFiles, $iniFile );
654 eZDebug::accumulatorStop( 'ini_files_save' );
655
656 if ( $cacheSaved )
657 {
658 // Write log message to storage.log
659 eZLog::writeStorageLog( $fileName, $cachedDir );
660 }
661 }
662
663 eZDebug::accumulatorStop( 'ini' );
664 }
665
676 protected function saveCache( $cachedDir, $cachedFile, array $data, array $inputFiles, $iniFile )
677 {
678 if ( !file_exists( $cachedDir ) )
679 {
680 if ( !eZDir::mkdir( $cachedDir, 0777, true ) )
681 {
682 eZDebug::writeError( "Couldn't create cache directory $cachedDir, perhaps wrong permissions", __METHOD__ );
683 return false;
684 }
685 }
686
687 // Save the data to a temp cached file
688 $tmpCacheFile = $cachedFile . '_' . substr( md5( mt_rand() ), 0, 8 );
689 $fp = @fopen( $tmpCacheFile, "w" );
690 if ( $fp === false )
691 {
692 eZDebug::writeError( "Couldn't create cache file '$cachedFile', perhaps wrong permissions?", __METHOD__ );
693 return false;
694 }
695
696 // Write cache data as a php structure with some meta information for use while reading cache
697 fwrite( $fp, "<?php\n// This is a auto generated ini cache file, time created:" . date( DATE_RFC822 ) . "\n" );
698
699 fwrite( $fp, "\$data = array(\n" );
700 fwrite( $fp, "'rev' => " . eZINI::CONFIG_CACHE_REV . ",\n" );
701 fwrite( $fp, "'created' => '" . date('c') . "',\n" );
702
703 if ( $this->Codec )
704 fwrite( $fp, "'charset' => \"".$this->Codec->RequestedOutputCharsetCode."\",\n" );
705 else
706 fwrite( $fp, "'charset' => \"$this->Charset\",\n" );
707
708 fwrite( $fp, "'files' => " . preg_replace( "@\n[\s]+@", '', var_export( $inputFiles, true ) ) . ",\n" );
709 fwrite( $fp, "'file' => '$iniFile',\n" );
710
711 fwrite( $fp, "'val' => " . preg_replace( "@\n[\s]+@", '', var_export( $data, true ) ) . ");" );
712 fwrite( $fp, "\n?>" );
713 fclose( $fp );
714
715 // Rename cache temp file to final desitination and set permissions
716 if( eZFile::rename( $tmpCacheFile, $cachedFile ) )
717 {
718 chmod( $cachedFile, self::$filePermission );
719 }
720
721 // EZP-22579: php5.5 opcache caches php files very aggressively & needs direct call on invalidation in this case
722 clearstatcache( true, $cachedFile );
723 if ( function_exists( 'opcache_invalidate' ) )
724 opcache_invalidate( $cachedFile, true );
725
726 if ( self::isDebugEnabled() )
727 eZDebug::writeNotice( "Wrote cache file '$cachedFile'", __METHOD__ );
728
729 return true;
730 }
731
737 function parse( $inputFiles = false, $iniFile = false, $reset = true, $placement = false )
738 {
739 if ( $inputFiles === false or
740 $iniFile === false )
741 {
742 eZDebug::accumulatorStart( 'ini_parse_find_files', 'Ini load', 'Find INI Files2' );
743 $this->findInputFiles( $inputFiles, $iniFile );
744 eZDebug::accumulatorStop( 'ini_parse_find_files' );
745 }
746
747 if ( $reset )
748 $this->reset();
749
750 foreach ( $inputFiles as $inputFile )
751 {
752 if ( file_exists( $inputFile ) )
753 {
754 $this->parseFile( $inputFile, $placement );
755 }
756 }
757 }
758
763 function parseFile( $file, $placement = false )
764 {
765 if ( self::isDebugEnabled() )
766 eZDebug::writeNotice( "Parsing file '$file'", __METHOD__ );
767
768 $contents = file_get_contents( $file );
769 if ( $contents === false )
770 {
771 eZDebug::writeError( "Failed opening file '$file' for reading", __METHOD__ );
772 return false;
773 }
774
775 $contents = str_replace( "\r", '', $contents );
776 $endOfLine = strpos( $contents, "\n" );
777 $line = substr( $contents, 0, $endOfLine );
778
779 $currentBlock = "";
780 if ( $line )
781 {
782 // check for charset
783 if ( preg_match( "/#\?ini(.+)\?/", $line, $ini_arr ) )
784 {
785 $args = explode( " ", trim( $ini_arr[1] ) );
786 foreach ( $args as $arg )
787 {
788 $vars = explode( '=', trim( $arg ) );
789 if ( $vars[0] == "charset" )
790 {
791 $val = $vars[1];
792 if ( $val[0] == '"' and
793 strlen( $val ) > 0 and
794 $val[strlen($val)-1] == '"' )
795 $val = substr( $val, 1, strlen($val) - 2 );
796 $this->Charset = $val;
797 }
798 }
799 }
800 }
801
802 unset( $this->Codec );
803 if ( $this->UseTextCodec )
804 {
805 $this->Codec = eZTextCodec::instance( $this->Charset, false, false );
806
807 if ( $this->Codec )
808 {
809 eZDebug::accumulatorStart( 'ini_conversion', false, 'INI string conversion' );
810 $contents = $this->Codec->convertString( $contents );
811 eZDebug::accumulatorStop( 'ini_conversion' );
812 }
813 }
814 else
815 $this->Codec = null;
816
817 foreach ( explode( "\n", $contents ) as $line )
818 {
819 if ( $line == '' or $line[0] == '#' )
820 continue;
821 if ( preg_match( "/^(.+)##.*/", $line, $regs ) )
822 $line = $regs[1];
823 if ( trim( $line ) == '' )
824 continue;
825 // check for new block
826 if ( preg_match("#^\[(.+)\]\s*$#", $line, $newBlockNameArray ) )
827 {
828 $newBlockName = trim( $newBlockNameArray[1] );
829 $currentBlock = $newBlockName;
830 continue;
831 }
832
833 // check for variable
834 if ( preg_match("#^([\w_*@-]+)\\[\\]$#", $line, $valueArray ) )
835 {
836 $varName = trim( $valueArray[1] );
837
838 if ( $placement )
839 {
840 if ( isset( $this->BlockValuesPlacement[$currentBlock][$varName] ) &&
841 !is_array( $this->BlockValuesPlacement[$currentBlock][$varName] ) )
842 {
843 eZDebug::writeError( "Wrong operation on the ini setting array '$varName'", __METHOD__ );
844 continue;
845 }
846
847 $this->BlockValuesPlacement[$currentBlock][$varName][] = $file;
848 }
849 else
850 {
851 $this->BlockValues[$currentBlock][$varName] = array();
852
853 // In direct access mode we create empty elements at the beginning of an array
854 // in case it is redefined in this ini file. So when we will save it, definition
855 // will be created as well.
856 if ( $this->AddArrayDefinition )
857 {
858 $this->BlockValues[$currentBlock][$varName][] = "";
859 }
860 }
861 }
862 else if ( preg_match("#^([\w_*@-]+)(\\[([^\\]]*)\\])?=(.*)$#", $line, $valueArray ) )
863 {
864 $varName = trim( $valueArray[1] );
865 $varValue = $valueArray[4];
866
867 if ( $valueArray[2] )
868 {
869 if ( $valueArray[3] )
870 {
871 $keyName = $valueArray[3];
872 if ( $placement )
873 {
874 $this->BlockValuesPlacement[$currentBlock][$varName][$keyName] = $file;
875 }
876 else
877 {
878 $this->BlockValues[$currentBlock][$varName][$keyName] = $varValue;
879 }
880 }
881 else
882 {
883 if ( $placement )
884 {
885 $this->BlockValuesPlacement[$currentBlock][$varName][] = $file;
886 }
887 else
888 {
889 $this->BlockValues[$currentBlock][$varName][] = $varValue;
890 }
891 }
892 }
893 else
894 {
895 if ( $placement )
896 {
897 $this->BlockValuesPlacement[$currentBlock][$varName] = $file;
898 }
899 else
900 {
901 $this->BlockValues[$currentBlock][$varName] = $varValue;
902 }
903 }
904 }
905 }
906 }
907
911 function resetCache()
912 {
913 if ( $this->CacheFile && file_exists( $this->CacheFile ) )
914 unlink( $this->CacheFile );
915 if ( $this->PlacementCacheFile && file_exists( $this->PlacementCacheFile ) )
916 unlink( $this->PlacementCacheFile );
917 }
918
919
926 function save( $fileName = false, $suffix = false, $useOverride = false,
927 $onlyModified = false, $useRootDir = true, $resetArrays = false,
928 $encapsulateInPHP = true )
929 {
930 $lineSeparator = eZSys::lineSeparator();
931 $pathArray = array();
932 $dirArray = array();
933 if ( $fileName === false )
934 $fileName = $this->FileName;
935 if ( $useRootDir === true )
936 {
937 $pathArray[] = $this->RootDir;
938 $dirArray[] = $this->RootDir;
939 }
940 else if ( is_string( $useRootDir ) )
941 {
942 $pathArray[] = $useRootDir;
943 $dirArray[] = $useRootDir;
944 }
945 if ( $useOverride )
946 {
947 $pathArray[] = 'override';
948 $dirArray[] = 'override';
949 }
950 if ( $useOverride === 'append' )
951 $fileName .= '.append';
952 if ( $suffix !== false )
953 $fileName .= $suffix;
954
955 /* Try to guess which filename would fit better: 'xxx.apend' or 'xxx.append.php'.
956 * We choose 'xxx.append.php' in all cases except when
957 * 'xxx.append' exists already and 'xxx.append.php' does not exist.
958 */
959 if( strstr( $fileName, '.append' ) )
960 {
961 $fnAppend = preg_replace( '#\.php$#', '', $fileName );
962 $fnAppendPhp = $fnAppend.'.php';
963 $fpAppend = eZDir::path( array_merge( $pathArray, array( $fnAppend ) ) );
964 $fpAppendPhp = eZDir::path( array_merge( $pathArray, array( $fnAppendPhp ) ) );
965 $fileName = ( file_exists( $fpAppend ) && !file_exists( $fpAppendPhp ) )
966 ? $fnAppend : $fnAppendPhp;
967 }
968
969 $originalFileName = $fileName;
970 $backupFileName = $originalFileName . eZSys::backupFilename();
971 $fileName .= '.tmp';
972
973 $dirPath = eZDir::path( $dirArray );
974 if ( !file_exists( $dirPath ) )
975 eZDir::mkdir( $dirPath, octdec( '777' ), true );
976
977 $filePath = eZDir::path( array_merge( $pathArray, array( $fileName ) ) );
978 $originalFilePath = eZDir::path( array_merge( $pathArray, array( $originalFileName ) ) );
979 $backupFilePath = eZDir::path( array_merge( $pathArray, array( $backupFileName ) ) );
980
981 $fp = @fopen( $filePath, "w+");
982 if ( !$fp )
983 {
984 eZDebug::writeError( "Failed opening file '$filePath' for writing", __METHOD__ );
985 return false;
986 }
987 $writeOK = true;
988 $written = 0;
989
990 $charset = $this->Codec ? $this->Codec->RequestedOutputCharsetCode : $this->Charset;
991 if ( $encapsulateInPHP )
992 {
993 $written = fwrite( $fp, "<?php /* #?ini charset=\"$charset\"?$lineSeparator$lineSeparator" );
994 }
995 else
996 {
997 $written = fwrite( $fp, "#?ini charset=\"$charset\"?$lineSeparator$lineSeparator" );
998 }
999
1000 if ( $written === false )
1001 $writeOK = false;
1002 $i = 0;
1003 if ( $writeOK )
1004 {
1005 foreach( array_keys( $this->BlockValues ) as $blockName )
1006 {
1007 if ( $onlyModified )
1008 {
1009 $groupHasModified = false;
1010 if ( isset( $this->ModifiedBlockValues[$blockName] ) )
1011 {
1012 foreach ( $this->ModifiedBlockValues[$blockName] as $modifiedValue )
1013 {
1014 if ( $modifiedValue )
1015 $groupHasModified = true;
1016 }
1017 }
1018 if ( !$groupHasModified )
1019 continue;
1020 }
1021 $written = 0;
1022 if ( $i > 0 )
1023 $written = fwrite( $fp, "$lineSeparator" );
1024 if ( $written === false )
1025 {
1026 $writeOK = false;
1027 break;
1028 }
1029 $written = fwrite( $fp, "[$blockName]$lineSeparator" );
1030 if ( $written === false )
1031 {
1032 $writeOK = false;
1033 break;
1034 }
1035 foreach( array_keys( $this->BlockValues[$blockName] ) as $blockVariable )
1036 {
1037 if ( $onlyModified )
1038 {
1039 if ( !isset( $this->ModifiedBlockValues[$blockName][$blockVariable] ) or
1040 !$this->ModifiedBlockValues[$blockName][$blockVariable] )
1041 continue;
1042 }
1043 $varKey = $blockVariable;
1044 $varValue = $this->BlockValues[$blockName][$blockVariable];
1045 if ( is_array( $varValue ) )
1046 {
1047 if ( count( $varValue ) > 0 )
1048 {
1049 $customResetArray = ( isset( $this->BlockValues[$blockName]['ResetArrays'] ) and
1050 $this->BlockValues[$blockName]['ResetArrays'] == 'false' )
1051 ? true
1052 : false;
1053 if ( $resetArrays and !$customResetArray )
1054 $written = fwrite( $fp, "$varKey" . "[]$lineSeparator" );
1055 foreach ( $varValue as $varArrayKey => $varArrayValue )
1056 {
1057 if ( is_string( $varArrayKey ) )
1058 $written = fwrite( $fp, "$varKey" . "[$varArrayKey]=$varArrayValue$lineSeparator" );
1059 else
1060 {
1061 if ( $varArrayValue == NULL )
1062 $written = fwrite( $fp, "$varKey" . "[]$lineSeparator" );
1063 else
1064 $written = fwrite( $fp, "$varKey" . "[]=$varArrayValue$lineSeparator" );
1065 }
1066 if ( $written === false )
1067 break;
1068 }
1069 }
1070 else
1071 $written = fwrite( $fp, "$varKey" . "[]$lineSeparator" );
1072 }
1073 else
1074 {
1075 $written = fwrite( $fp, "$varKey=$varValue$lineSeparator" );
1076 }
1077 if ( $written === false )
1078 {
1079 $writeOK = false;
1080 break;
1081 }
1082 }
1083 if ( !$writeOK )
1084 break;
1085 ++$i;
1086 }
1087 }
1088 if ( $writeOK )
1089 {
1090 if ( $encapsulateInPHP )
1091 {
1092 $written = fwrite( $fp, "*/ ?>" );
1093
1094 if ( $written === false )
1095 $writeOK = false;
1096 }
1097 }
1098 @fclose( $fp );
1099 if ( !$writeOK )
1100 {
1101 unlink( $filePath );
1102 return false;
1103 }
1104
1105 chmod( $filePath, self::$filePermission );
1106
1107 if ( file_exists( $backupFilePath ) )
1108 unlink( $backupFilePath );
1109 if ( file_exists( $originalFilePath ) )
1110 {
1111 if ( !rename( $originalFilePath, $backupFilePath ) )
1112 return false;
1113 }
1114 if ( !rename( $filePath, $originalFilePath ) )
1115 {
1116 rename( $backupFilePath, $originalFilePath );
1117 return false;
1118 }
1119
1120 return true;
1121 }
1122
1126 function reset()
1127 {
1128 $this->BlockValues = array();
1129 $this->ModifiedBlockValues = array();
1130 }
1131
1137 function rootDir()
1138 {
1139 return $this->RootDir;
1140 }
1141
1151 function overrideDirs( $scope = null )
1152 {
1153 if ( $this->UseLocalOverrides == true )
1154 $dirs =& $this->LocalOverrideDirArray;
1155 else
1156 $dirs =& self::$GlobalOverrideDirArray;
1157
1158 return self::overrideDirsByScope( $dirs, $scope );
1159 }
1160
1170 public static function globalOverrideDirs( $scope = null )
1171 {
1172 return self::overrideDirsByScope( self::$GlobalOverrideDirArray, $scope );
1173 }
1174
1185 protected static function overrideDirsByScope( array $dirs, $scope = null )
1186 {
1187 if ( $scope !== null )
1188 {
1189 if ( $scope === false )
1190 return $dirs;
1191 if ( isset( $dirs[$scope] ) )
1192 return $dirs[$scope];
1193 eZDebug::writeWarning( "Undefined override dir scope: '$scope'", __METHOD__ );
1194 }
1195
1196 return array_merge( $dirs['sa-extension'], $dirs['siteaccess'], $dirs['extension'], $dirs['override'] );
1197 }
1198
1209 static public function defaultOverrideDirs()
1210 {
1211 static $def = array(
1212 'sa-extension' => array(),
1213 'siteaccess' => array(),
1214 'extension' => array(),
1215 'override' => array( array( 'override', false ) )
1216 );
1217 return $def;
1218 }
1219
1227 function setOverrideDirs( array $newDirs, $scope = false )
1228 {
1229 if ( $this->UseLocalOverrides == true )
1230 $dirs =& $this->LocalOverrideDirArray;
1231 else
1232 $dirs =& self::$GlobalOverrideDirArray;
1233
1234 if ( $scope === false )
1235 $dirs = $newDirs;
1236 else if ( isset( $dirs[$scope] ) )
1237 $dirs[$scope] = $newDirs;
1238 else
1239 eZDebug::writeWarning( "Undefined override dir scope: '$scope'", __METHOD__ );
1240
1241 $this->CacheFile = false;
1242 }
1243
1247 static public function resetGlobalOverrideDirs()
1248 {
1249 self::$GlobalOverrideDirArray = self::defaultOverrideDirs();
1250 }
1251
1255 public function resetOverrideDirs()
1256 {
1257 $this->setOverrideDirs( self::defaultOverrideDirs() );
1258 }
1259
1268 function removeOverrideDir( $identifier, $scope = 'extension' )
1269 {
1270 if ( $this->UseLocalOverrides == true )
1271 $dirs =& $this->LocalOverrideDirArray;
1272 else
1273 $dirs =& self::$GlobalOverrideDirArray;
1274
1275 if ( !$identifier || !is_string( $identifier ) )
1276 {
1277 eZDebug::writeError( "\$identifier must be a string", __METHOD__ );
1278 return false;
1279 }
1280
1281 if ( !isset( $dirs[$scope] ) )
1282 {
1283 eZDebug::writeWarning( "Undefined override dir scope: '$scope'", __METHOD__ );
1284 $scope = 'extension';
1285 }
1286
1287 $overrideRemoved = false;
1288 if ( isset( $dirs[$scope][$identifier] ) )
1289 {
1290 unset( $dirs[$scope][$identifier] );
1291 $overrideRemoved = true;
1292 $this->CacheFile = false;
1293 }
1294
1295 return $overrideRemoved;
1296 }
1297
1309 function prependOverrideDir( $dir, $globalDir = false, $identifier = false, $scope = null )
1310 {
1311 if ( self::isDebugEnabled() )
1312 eZDebug::writeNotice( "Prepending override dir '$dir'", "eZINI" );
1313
1314 if ( $this->UseLocalOverrides == true )
1315 $dirs =& $this->LocalOverrideDirArray;
1316 else
1317 $dirs =& self::$GlobalOverrideDirArray;
1318
1319 $scope = self::selectOverrideScope( $scope, $identifier, $dir, 'extension' );
1320
1321 // Check if the override with the current identifier already exists
1322 $overrideOverwritten = false;
1323 if ( $identifier && isset( $dirs[$scope][$identifier] ) )
1324 {
1325 $dirs[$scope][$identifier] = array( $dir, $globalDir );
1326 $overrideOverwritten = true;
1327 }
1328 else
1329 {
1330 // array_merge() is to be used below instead of the "+" operator because the
1331 // position of elements in this mixed hash/list is important!
1332 if ( $identifier )
1333 $dirs[$scope] = array_merge( array( $identifier => array( $dir, $globalDir ) ), $dirs[$scope] );
1334 else
1335 $dirs[$scope] = array_merge( array( array( $dir, $globalDir ) ), $dirs[$scope] );
1336 }
1337
1338 $this->CacheFile = false;
1339 return $overrideOverwritten === false;
1340 }
1341
1353 function appendOverrideDir( $dir, $globalDir = false, $identifier = false, $scope = null )
1354 {
1355 if ( self::isDebugEnabled() )
1356 eZDebug::writeNotice( "Appending override dir '$dir'", __METHOD__ );
1357
1358 if ( $this->UseLocalOverrides == true )
1359 $dirs =& $this->LocalOverrideDirArray;
1360 else
1361 $dirs =& self::$GlobalOverrideDirArray;
1362
1363 $scope = self::selectOverrideScope( $scope, $identifier, $dir, 'override' );
1364
1365 // Check if the override with the current identifier already exists
1366 $overrideOverwritten = false;
1367 if ( $identifier && isset( $dirs[$scope][$identifier] ) )
1368 {
1369 $dirs[$scope][$identifier] = array( $dir, $globalDir );
1370 $overrideOverwritten = true;
1371 }
1372 else
1373 {
1374 if ( $identifier )
1375 $dirs[$scope][$identifier] = array( $dir, $globalDir );
1376 else
1377 $dirs[$scope][] = array( $dir, $globalDir );
1378 }
1379
1380 $this->CacheFile = false;
1381 return $overrideOverwritten === false;
1382 }
1383
1394 protected static function selectOverrideScope( $scope, $identifier, $dir, $default )
1395 {
1396 if ( $scope !== null )
1397 {
1398 $def = self::defaultOverrideDirs();
1399 if ( isset( $def[$scope] ) )
1400 return $scope;
1401 eZDebug::writeWarning( "Undefined override dir scope: '$scope' with dir: '$dir'", __METHOD__ );
1402 }
1403 if ( $identifier === 'siteaccess' )
1404 return 'siteaccess';
1405 else if ( $identifier && strpos($identifier, 'extension:') === 0 )
1406 return 'extension';
1407 else if ( strpos($dir, 'siteaccess') !== false )
1408 return 'siteaccess';
1409 else if ( strpos($dir, 'extension') !== false )
1410 return 'extension';
1411
1412 eZDebug::writeStrict( "Could not figgure out INI scope for \$identifier: '$identifier' with \$dir: '$dir', falling back to '$default'", __METHOD__ );
1413 return $default;
1414 }
1415
1420 function assign( $blockName, $varName, &$variable )
1421 {
1422 if ( isset( $this->BlockValues[$blockName][$varName] ) )
1423 $variable = $this->BlockValues[$blockName][$varName];
1424 else
1425 return false;
1426 return true;
1427 }
1428
1438 function variable( $blockName, $varName )
1439 {
1440 if ( isset( $this->BlockValues[$blockName][$varName] ) )
1441 {
1442 $value = $this->BlockValues[$blockName][$varName];
1443 }
1444
1445 if ( isset( self::$injectedSettings[$this->FileName][$blockName][$varName] ) )
1446 {
1447 $value = self::$injectedSettings[$this->FileName][$blockName][$varName];
1448 }
1449
1450 if ( isset( $value ) && isset( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1451 {
1452 if ( !is_array( $value ) || !is_array( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1453 {
1454 throw new RuntimeException( "injected-merge-settings can only reference and contain array values" );
1455 }
1456 $value = array_merge( $value, self::$injectedMergeSettings[$this->FileName][$blockName][$varName] );
1457 }
1458
1459 if ( isset( $value ) )
1460 return $value;
1461
1462 if ( !isset( $this->BlockValues[$blockName] ) )
1463 eZDebug::writeError( "Undefined group: '$blockName' in " . $this->FileName, __METHOD__ );
1464 else
1465 eZDebug::writeError( "Undefined variable: '$varName' in group '$blockName' in " . $this->FileName, __METHOD__ );
1466 return false;
1467 }
1468
1479 function variableMulti( $blockName, $varNames, $signatures = array() )
1480 {
1481 $ret = array();
1482
1483 if ( !isset( $this->BlockValues[$blockName] )
1484 && !isset( self::$injectedSettings[$this->FileName][$blockName] )
1485 )
1486 {
1487 eZDebug::writeError( "Undefined group: '$blockName' in " . $this->FileName, "eZINI" );
1488 return false;
1489 }
1490 foreach ( $varNames as $key => $varName )
1491 {
1492 $ret[$key] = null;
1493
1494 if ( isset( $this->BlockValues[$blockName][$varName] ) )
1495 {
1496 $ret[$key] = $this->BlockValues[$blockName][$varName];
1497 }
1498 if ( isset( self::$injectedSettings[$this->FileName][$blockName][$varName] ) )
1499 {
1500 $ret[$key] = self::$injectedSettings[$this->FileName][$blockName][$varName];
1501 }
1502 if ( isset( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1503 {
1504 if ( !is_array( $ret[$key] ) || !is_array( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1505 {
1506 throw new RuntimeException( "injected-merge-settings can only reference and contain array values" );
1507 }
1508 $ret[$key] = array_merge(
1509 $this->BlockValues[$blockName][$varName],
1510 self::$injectedMergeSettings[$this->FileName][$blockName][$varName]
1511 );
1512 }
1513
1514 if ( isset( $ret[$key] ) && isset( $signatures[$key] ) )
1515 {
1516 switch ( $signatures[$key] )
1517 {
1518 case 'enabled':
1519 $ret[$key] = $this->BlockValues[$blockName][$varName] == 'enabled';
1520 break;
1521 }
1522 }
1523 }
1524
1525 return $ret;
1526 }
1527
1536 function hasVariable( $blockName, $varName )
1537 {
1538 // 1. Check if the variable is set in either injected or regular settings.
1539 if (
1540 !isset( self::$injectedSettings[$this->FileName][$blockName][$varName] )
1541 && !isset( $this->BlockValues[$blockName][$varName] )
1542 )
1543 {
1544 return false;
1545 }
1546
1547 // 2. Check if injected setting isn't strictly false (false being the default value when a variable doesn't exist).
1548 if (
1549 isset( self::$injectedSettings[$this->FileName][$blockName][$varName] )
1550 && self::$injectedSettings[$this->FileName][$blockName][$varName] === false
1551 )
1552 {
1553 return false;
1554 }
1555
1556 return true;
1557 }
1558
1566 function hasSection( $sectionName )
1567 {
1568 return ( isset( $this->BlockValues[$sectionName] )
1569 || isset( self::$injectedSettings[$this->FileName][$sectionName] ) );
1570 }
1571
1575 function isVariableModified( $blockName, $varName )
1576 {
1577 return ( isset( $this->ModifiedBlockValues[$blockName][$varName] ) and
1578 $this->ModifiedBlockValues[$blockName][$varName] );
1579 }
1580
1589 function variableArray( $blockName, $varName )
1590 {
1591 $ret = $this->variable( $blockName, $varName );
1592
1593 if ( is_array( $ret ) )
1594 {
1595 $arr = array();
1596 foreach ( $ret as $key => $retItem )
1597 {
1598 $arr[$key] = explode( ';', $retItem );
1599 }
1600 $ret = $arr;
1601 }
1602 else if ( $ret !== false )
1603 {
1604 $ret = trim( $ret ) === '' ? array() : explode( ';', $ret );
1605 }
1606
1607 return $ret;
1608 }
1609
1616 function hasGroup( $blockName )
1617 {
1618 return $this->hasSection( $blockName );
1619 }
1620
1629 function group( $blockName )
1630 {
1631 if ( !isset( $this->BlockValues[$blockName] ) )
1632 {
1633 eZDebug::writeError( "Unknown group: '$blockName'", __METHOD__ );
1634 $ret = null;
1635 return $ret;
1636 }
1637 if ( isset( self::$injectedSettings[$this->FileName][$blockName] ) )
1638 {
1639 $ret = array_merge(
1640 $this->BlockValues[$blockName],
1641 self::$injectedSettings[$this->FileName][$blockName]
1642 );
1643 }
1644 else
1645 {
1646 $ret = $this->BlockValues[$blockName];
1647 }
1648
1649 return $ret;
1650 }
1651
1652 function isSettingReadOnly( $fileName = false, $blockName = false, $settingName = false )
1653 {
1654 if ( !$this->readOnlySettingsCheck() )
1655 return true;
1656
1657 $ini = eZINI::instance();
1658 if ( !$ini->hasVariable( 'eZINISettings', 'ReadonlySettingList' ) )
1659 return true;
1660
1661 $fileName = $fileName === false ? $ini->FileName : $fileName;
1662 $fileNameExploded = explode( '.', $fileName );
1663 $realFileName = $fileNameExploded[0] . '.' . $fileNameExploded[1];
1664 $blockName = $blockName === false ? '*' : $blockName;
1665 $settingName = $settingName === false ? '*' : $settingName;
1666 $currentSetting = $realFileName . '/' . $blockName . '/' . $settingName;
1667
1668 $settingList = $ini->variable( 'eZINISettings', 'ReadonlySettingList' );
1669 $settingList[] = 'site.ini/eZINISettings/*';
1670
1671 $result = !( in_array( $realFileName . '/*' , $settingList ) or
1672 in_array( $realFileName . '/' . $blockName . '/*' , $settingList ) or
1673 in_array( $realFileName . '/' . $blockName . '/' . $settingName , $settingList ) );
1674
1675 return $result;
1676 }
1680 function removeGroup( $blockName )
1681 {
1682 unset( $this->BlockValues[$blockName] );
1683 unset( $this->BlockValuesPlacement[$blockName] );
1684 }
1685
1686 function removeSetting( $blockName, $settingName )
1687 {
1688 unset( $this->BlockValues[$blockName][$settingName] );
1689 unset( $this->BlockValuesPlacement[$blockName][$settingName] );
1690 if ( $this->BlockValues[$blockName] == null )
1691 $this->removeGroup( $blockName );
1692 }
1693
1701 function groups()
1702 {
1703 if ( isset( self::$injectedSettings[$this->FileName] ) || isset( self::$injectedMergeSettings[$this->FileName] ) )
1704 {
1705 $result = $this->BlockValues;
1706 foreach ( $result as $blockName => $vars )
1707 {
1708 foreach ( $vars as $varName => $varValue )
1709 {
1710 if ( isset( self::$injectedSettings[$this->FileName][$blockName][$varName] ) )
1711 {
1712 $result[$blockName][$varName] = self::$injectedSettings[$this->FileName][$blockName][$varName];
1713 }
1714 if ( isset( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1715 {
1716 if ( !is_array( $result[$blockName][$varName] ) || !is_array( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1717 {
1718 throw new RuntimeException( "injected-merge-settings can only reference and contain array values" );
1719 }
1720
1721 $result[$blockName][$varName] = array_merge(
1722 $varValue,
1723 self::$injectedMergeSettings[$this->FileName][$blockName][$varName]
1724 );
1725 }
1726 }
1727 }
1728 foreach ( self::$injectedSettings[$this->FileName] as $blockName => $vars )
1729 {
1730 if ( !isset( $result[$blockName] ) )
1731 {
1732 $result[$blockName] = $vars;
1733 }
1734 }
1735 return $result;
1736 }
1737 return $this->BlockValues;
1738 }
1739
1743 function &groupPlacements()
1744 {
1745 if ( !$this->BlockValuesPlacement )
1746 {
1747 $this->loadPlacement();
1748 }
1749 return $this->BlockValuesPlacement;
1750 }
1751
1761 function findSettingPlacement( $path )
1762 {
1763 if ( is_array( $path ) )
1764 {
1765 if( isset( $path[0] ) )
1766 {
1767 $path = $path[0];
1768 }
1769 else
1770 {
1771 return 'undefined';
1772 }
1773 }
1774
1775 // changing $path so that it's relative the root eZ Publish (legacy)
1776 $path = str_replace( __DIR__ . "/../../../", "", $path );
1777 $exploded = explode( '/', $path );
1778 $directoryCount = count( $exploded );
1779 switch ( $directoryCount )
1780 {
1781 case 2:
1782 $placement = 'default';
1783 break;
1784 case 3:
1785 $placement = 'override';
1786 break;
1787 case 4:
1788 {
1789 if ( $exploded[0] === 'extension' )
1790 $placement = 'extension:' . $exploded[1];
1791 else
1792 $placement = 'siteaccess';
1793 }
1794 break;
1795 //### EXP-MULTI-SITE-OVERRIDE-SETTINGS ###
1796 case 5:
1797 {
1798 // ext-siteaccess-override
1799 // ext-siteaccess-override__group
1800 $placement = 'ext-siteaccess-'. $exploded[3] .':' . $exploded[1];
1801 }
1802 break;
1803 case 6:
1804 {
1805 $placement = 'ext-siteaccess:' . $exploded[1];
1806 }
1807 break;
1808 default:
1809 if ( $path === self::INJECTED_PATH )
1810 {
1811 $placement = 'injected';
1812 }
1813 else
1814 {
1815 $placement = 'undefined';
1816 }
1817 break;
1818 }
1819 return $placement;
1820 }
1821
1822 function settingType( $settingValue )
1823 {
1824 if ( is_array( $settingValue ) )
1825 return 'array';
1826
1827 if ( is_numeric( $settingValue ) )
1828 return 'numeric';
1829
1830 if ( $settingValue == 'true' or $settingValue == 'false' )
1831 {
1832 return 'true/false';
1833 }
1834 if ( $settingValue == 'enabled' or $settingValue == 'disabled' )
1835 {
1836 return 'enable/disable';
1837 }
1838
1839 return 'string';
1840 }
1841
1845 function setGroups( $groupArray )
1846 {
1847 $resultArray = array();
1848 // Check for readOnly
1849 foreach ( $groupArray as $blockName => $blockVariables )
1850 {
1851 foreach ( $blockVariables as $variableName => $variableValue )
1852 {
1853 if ( !$this->isSettingReadOnly( $this->FileName, $blockName, $variableName ) )
1854 continue;
1855 $resultArray[$blockName][$variableName] = $variableValue;
1856 }
1857 }
1858 $this->BlockValues = $resultArray;
1859 }
1860
1871 function setVariables( $variables )
1872 {
1873 foreach ( $variables as $blockName => $blockVariables )
1874 {
1875 foreach ( $blockVariables as $variableName => $variableValue )
1876 {
1877 $this->setVariable( $blockName, $variableName, $variableValue );
1878 }
1879 }
1880 }
1881
1889 function setVariable( $blockName, $variableName, $variableValue )
1890 {
1891 if ( !$this->isSettingReadOnly( $this->filename(), $blockName, $variableName ) )
1892 return false;
1893
1894 $this->BlockValues[$blockName][$variableName] = $variableValue;
1895 $this->ModifiedBlockValues[$blockName][$variableName] = true;
1896 }
1897
1903 function getNamedArray()
1904 {
1905 if ( isset( self::$injectedSettings[$this->FileName] ) )
1906 {
1907 return array_merge(
1908 $this->BlockValues,
1909 self::$injectedSettings[$this->FileName]
1910 );
1911 }
1912 return $this->BlockValues;
1913 }
1914
1924 static function isLoaded( $fileName = 'site.ini', $rootDir = 'settings', $useLocalOverrides = null )
1925 {
1926 return isset( self::$instances["$rootDir-$fileName-$useLocalOverrides"] );
1927 }
1928
1946 static function instance( $fileName = 'site.ini', $rootDir = 'settings', $useTextCodec = null, $useCache = null, $useLocalOverrides = null, $directAccess = false, $addArrayDefinition = false )
1947 {
1948 if ( $addArrayDefinition !== false || $directAccess !== false || $useTextCodec !== null || $useCache !== null )
1949 {
1950 // Could have trown strict error here but will cause issues if ini system has not been setup yet..
1951 return new eZINI( $fileName, $rootDir, $useTextCodec, $useCache, $useLocalOverrides, $directAccess, $addArrayDefinition );
1952 }
1953
1954 $key = "$rootDir-$fileName-$useLocalOverrides";
1955 if ( !isset( self::$instances[$key] ) )
1956 {
1957 self::$instances[$key] = new eZINI( $fileName, $rootDir, $useTextCodec, $useCache, $useLocalOverrides, $directAccess, $addArrayDefinition );
1958 }
1959 return self::$instances[$key];
1960 }
1961
1966 static function fetchFromFile( $fileName, $useTextCodec = null )
1967 {
1968 return new eZINI( $fileName, false, $useTextCodec, false, false, true );
1969 }
1970
1979 static function getSiteAccessIni( $siteAccess, $iniFile )
1980 {
1981 $saPath = eZSiteAccess::findPathToSiteAccess( $siteAccess );
1982 return self::fetchFromFile( "$saPath/$iniFile" );
1983 }
1984
1989 static function create( $fileName = 'site.ini', $rootDir = 'settings', $useTextCodec = null, $useCache = null, $useLocalOverrides = null )
1990 {
1991 $impl = new eZINI( $fileName, $rootDir, $useTextCodec, $useCache, $useLocalOverrides );
1992 return $impl;
1993 }
1994
1998 function setReadOnlySettingsCheck( $readOnly = true )
1999 {
2000 $this->ReadOnlySettingsCheck = $readOnly;
2001 }
2002
2006 function readOnlySettingsCheck()
2007 {
2008 return $this->ReadOnlySettingsCheck;
2009 }
2010
2022 static function resetGlobals( $fileName = 'site.ini', $rootDir = 'settings', $useLocalOverrides = null )
2023 {
2024 self::resetInstance( $fileName, $rootDir, $useLocalOverrides );
2025 }
2026
2036 static function resetInstance( $fileName = 'site.ini', $rootDir = 'settings', $useLocalOverrides = null )
2037 {
2038 unset( self::$instances["$rootDir-$fileName-$useLocalOverrides"] );
2039 }
2040
2050 static function resetAllGlobals( $resetGlobalOverrideDirs = true )
2051 {
2052 self::resetAllInstances( $resetGlobalOverrideDirs );
2053 }
2054
2062 static function resetAllInstances( $resetGlobalOverrideDirs = true )
2063 {
2064 self::$instances = array();
2065
2066 if ( $resetGlobalOverrideDirs )
2067 self::resetGlobalOverrideDirs();
2068 }
2069
2079 static function injectSettings( array $settings )
2080 {
2081 self::$injectedSettings = $settings;
2082 }
2083
2093 static function injectMergeSettings( array $settings )
2094 {
2095 self::$injectedMergeSettings = $settings;
2096 }
2097
2100 public $Charset;
2101
2103 public $Codec;
2104
2106 public $BlockValues;
2107
2109 public $BlockValuesPlacement;
2110
2112 public $ModifiedBlockValues;
2113
2115 public $FileName;
2116
2118 public $RootDir;
2119
2121 public $UseTextCodec;
2122
2124 public $CacheFile;
2125
2127 public $PlacementCacheFile;
2128
2130 public $UseCache;
2131
2133 public $UseLocalOverrides;
2134
2136 public $LocalOverrideDirArray;
2137
2139 static protected $GlobalOverrideDirArray = null;
2140
2142 public $DirectAccess;
2143
2145 public $AddArrayDefinition;
2146
2148 public $ReadOnlySettingsCheck = true;
2149
2150 }
2151
2152 ?>
eZDebug\writeStrict
static writeStrict( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:414
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZDebug\accumulatorStart
static accumulatorStart( $key, $inGroup=false, $name=false, $recursive=false)
Definition: ezdebug.php:1361
eZDebug\accumulatorStop
static accumulatorStop( $key, $recursive=false)
Definition: ezdebug.php:1389
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZDir\path
static path( $names, $includeEndSeparator=false, $type=self::SEPARATOR_UNIX)
Definition: ezdir.php:237
eZExtension\prependExtensionSiteAccesses
static prependExtensionSiteAccesses( $accessName=false, $ini=false, $globalDir=true, $identifier=null, $order=true)
Definition: ezextension.php:229
eZFile\rename
static rename( $srcFile, $destFile, $mkdir=false, $flags=0)
Definition: ezfile.php:152
eZINI
Reads and writes .ini style configuration files.
eZLog\writeStorageLog
static writeStorageLog( $name, $dir=false)
Definition: ezlog.php:85
eZSiteAccess\findPathToSiteAccess
static findPathToSiteAccess( $siteAccess)
Definition: ezsiteaccess.php:66
eZSys\lineSeparator
static lineSeparator()
Definition: ezsys.php:483
eZSys\backupFilename
static backupFilename()
Definition: ezsys.php:473
eZTextCodec\internalCharset
static internalCharset()
Definition: eztextcodec.php:546
eZTextCodec\instance
static instance( $inputCharsetCode, $outputCharsetCode=false, $alwaysReturn=true)
Definition: eztextcodec.php:446
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.