eZ Publish  [4.0]
ezclusterfilehandler.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZClusterFileHandler class
00004 //
00005 // Created on: <07-Mar-2006 16:14:02 vs>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezclusterfilehandler.php
00032 */
00033 
00034 class eZClusterFileHandler
00035 {
00036     /**
00037      * \public
00038      * \static
00039      * \return filehandler
00040      */
00041     static function instance( $filename = false )
00042     {
00043         // Determine handler to use and cache its name in a global variable.
00044         if ( !isset( $GLOBALS['eZClusterFileHandler_chosen_handler_class'] ) )
00045         {
00046             require_once( 'lib/ezutils/classes/ezini.php' );
00047             $fileINI = eZINI::instance( 'file.ini' );
00048             $handlerName = 'ezfs';
00049             if ( $fileINI->hasVariable( 'ClusteringSettings', 'FileHandler' ) )
00050                 $handlerName = $fileINI->variable( 'ClusteringSettings', 'FileHandler' );
00051 
00052             // Create list of directories used to search cluster file handlers for.
00053             $searchPathArray = eZClusterFileHandler::searchPathArray();
00054 
00055             // Find chosen handler.
00056             $handlerClass = $handlerName . 'filehandler';
00057             foreach ( $searchPathArray as $searchPath )
00058             {
00059                 $includeFileName = $searchPath . '/' . $handlerClass . '.php';
00060                 if ( is_readable( $includeFileName ) )
00061                 {
00062                     include_once( $includeFileName );
00063                     $GLOBALS['eZClusterFileHandler_chosen_handler_class'] = $handlerClass;
00064                     break;
00065                 }
00066             }
00067 
00068             if ( !isset( $GLOBALS['eZClusterFileHandler_chosen_handler_class'] ) )
00069             {
00070                 eZDebug::writeError( "Cannot find cluster file handler '$handlerName'." );
00071                 return null;
00072             }
00073         }
00074 
00075         // Instantiate the handler.
00076         if ( $filename !== false )
00077         {
00078             // return new FileHandler based on INI setting.
00079             $handlerClass = $GLOBALS['eZClusterFileHandler_chosen_handler_class'];
00080             return new $handlerClass( $filename );
00081         }
00082         else
00083         {
00084             // return Filehandler from GLOBALS based on ini setting.
00085             if ( !isset( $GLOBALS['eZClusterFileHandler_chosen_handler'] ) )
00086             {
00087                 $handlerClass = $GLOBALS['eZClusterFileHandler_chosen_handler_class'];
00088                 $handler = new $handlerClass;
00089                 $GLOBALS['eZClusterFileHandler_chosen_handler'] = $handler;
00090             }
00091             else
00092                 $handler = $GLOBALS['eZClusterFileHandler_chosen_handler'];
00093 
00094             return $handler;
00095         }
00096     }
00097 
00098     /**
00099      * \public
00100      * \static
00101      * \return list of directories used to search cluster file handlers for.
00102      */
00103     static function searchPathArray()
00104     {
00105         if ( !isset( $GLOBALS['eZClusterFileHandler_search_path_array'] ) )
00106         {
00107             $fileINI = eZINI::instance( 'file.ini' );
00108             $searchPathArray = array( 'kernel/classes/clusterfilehandlers' );
00109             if ( $fileINI->hasVariable( 'ClusteringSettings', 'ExtensionDirectories' ) )
00110             {
00111                 $extensionDirectories = $fileINI->variable( 'ClusteringSettings', 'ExtensionDirectories' );
00112                 require_once( 'lib/ezutils/classes/ezextension.php' );
00113                 $baseDirectory = eZExtension::baseDirectory();
00114                 foreach ( $extensionDirectories as $extensionDirectory )
00115                 {
00116                     $customSearchPath = $baseDirectory . '/' . $extensionDirectory . '/clusterfilehandlers';
00117                     if ( file_exists( $customSearchPath ) )
00118                         $searchPathArray[] = $customSearchPath;
00119                 }
00120             }
00121 
00122             $GLOBALS['eZClusterFileHandler_search_path_array'] = $searchPathArray;
00123         }
00124 
00125         return $GLOBALS['eZClusterFileHandler_search_path_array'];
00126     }
00127 }
00128 
00129 ?>