eZ Publish  [trunk]
ezpattributeoperatormanager.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing ezpAttributeOperatorManager class definition
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package kernel
00009  */
00010  
00011 class ezpAttributeOperatorManager
00012 {
00013     /**
00014      * @var ezpAttributeOperatorFormatterInterface Output formatter object container
00015      */
00016     protected static $formatter = null;
00017     protected static $format = null;
00018 
00019     /**
00020      * Searches for the output formatter handler class for a given format
00021      *
00022      * @static
00023      * @param string $format
00024      * @return ezpAttributeOperatorFormatterInterface
00025      */
00026     protected static function createFormatter( $format )
00027     {
00028         $formatterOptions = new ezpExtensionOptions();
00029         $formatterOptions->iniFile = 'template.ini';
00030         $formatterOptions->iniSection = 'AttributeOperator';
00031         $formatterOptions->iniVariable = 'OutputFormatter';
00032         $formatterOptions->handlerIndex = $format;
00033 
00034         $formatterInstance = eZExtension::getHandlerClass( $formatterOptions );
00035 
00036         if ( !( $formatterInstance instanceof ezpAttributeOperatorFormatterInterface ) )
00037             eZDebug::writeError( "Undefined output formatter for '{$format}'", __METHOD__ );
00038 
00039         return $formatterInstance;
00040     }
00041 
00042     /**
00043      * Checks is given format has registered handler class
00044      *
00045      * @static
00046      * @param string $format
00047      * @return bool
00048      */
00049     protected static function isRegisteredFormatter( $format )
00050     {
00051         return array_key_exists( $format, eZINI::instance( 'template.ini' )->variableArray( 'AttributeOperator', 'OutputFormatter' ) );
00052     }
00053 
00054     /**
00055      * Returns formatter object for a given format
00056      *
00057      * @static
00058      * @param string $format
00059      * @return ezpAttributeOperatorFormatterInterface|null
00060      */
00061     public static function getOutputFormatter( $format )
00062     {
00063         if ( !self::isRegisteredFormatter( $format ) )
00064         {
00065             $format = eZINI::instance( 'template.ini' )->variable( 'AttributeOperator', 'DefaultFormatter' );
00066         }
00067 
00068         if ( !( self::$formatter instanceof ezpAttributeOperatorFormatterInterface ) || $format != self::$format )
00069         {
00070             self::$formatter = self::createFormatter( $format );
00071             self::$format = $format;
00072         }
00073 
00074         return self::$formatter;
00075     }
00076 }