|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZDiff class. 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 lib 00009 */ 00010 00011 /*! 00012 \class eZDiff ezdiff.php 00013 \ingroup eZDiff 00014 \brief eZDiff provides an access point the diff system 00015 00016 The eZDiff class is responsible for accessing and loading the correct 00017 diff engine when a datatype makes a call to eZDiff library. 00018 */ 00019 class eZDiff 00020 { 00021 /*! 00022 Instantiates the eZDiff object 00023 \param $diffEngineType The type of diff engine to initialize at start 00024 */ 00025 function eZDiff( $diffEngineType = false ) 00026 { 00027 if ( $diffEngineType ) 00028 { 00029 $this->DiffEngine = $diffEngineType; 00030 eZDebug::writeNotice( "Diff engine type: " . $diffEngineType, 'eZDiff' ); 00031 } 00032 } 00033 00034 /*! 00035 \public 00036 Set the diff engine to be used for diffing. 00037 \param $diffEngineType The type of diff engine to intitialize 00038 */ 00039 function setDiffEngineType( $diffEngineType ) 00040 { 00041 if ( isset( $diffEngineType ) ) 00042 { 00043 $this->DiffEngine = $diffEngineType; 00044 eZDebug::writeNotice( "Changing diff engine to type: " . $diffEngineType, 'eZDiff' ); 00045 } 00046 } 00047 00048 /*! 00049 \public 00050 \return The diff engine type used in this instance. 00051 */ 00052 function getDiffEngineType() 00053 { 00054 return $this->DiffEngine; 00055 } 00056 00057 /*! 00058 \public 00059 \return Internal id of engine type given in \a $typeString 00060 */ 00061 function engineType( $typeString ) 00062 { 00063 switch ( $typeString ) 00064 { 00065 case 'text': 00066 { 00067 return $this->DIFF_TYPE['text']; 00068 }break; 00069 00070 case 'xml': 00071 { 00072 return $this->DIFF_TYPE['xml']; 00073 }break; 00074 00075 case 'container': 00076 { 00077 return $this->DIFF_TYPE['container']; 00078 }break; 00079 } 00080 } 00081 00082 /*! 00083 \public 00084 Returns diff engine of \a $type 00085 */ 00086 function initDiffEngine() 00087 { 00088 if ( !$diffEngine = $this->DiffEngineInstance ) 00089 { 00090 switch( $this->DiffEngine ) 00091 { 00092 case '0': //Text 00093 { 00094 $this->DiffEngineInstance = new eZDiffTextEngine(); 00095 }break; 00096 00097 case '1': //XML 00098 { 00099 $this->DiffEngineInstance = new eZDiffXMLTextEngine(); 00100 }break; 00101 00102 case '2': //ObjectContainer 00103 { 00104 $this->DiffEngineInstance = new eZDiffContainerObjectEngine(); 00105 } 00106 } 00107 } 00108 } 00109 00110 /*! 00111 \public 00112 Perform a diff operation on the provided set of data. A valid 00113 diff engine have to be specified, before this can be run. 00114 00115 \return An eZDiffContent object with the detected changes 00116 */ 00117 function &diff( $fromData, $toData) 00118 { 00119 if ( !$this->DiffEngineInstance ) 00120 return null; 00121 00122 $differ =& $this->DiffEngineInstance; 00123 $diffObject = $differ->createDifferenceObject( $fromData, $toData ); 00124 return $diffObject; 00125 } 00126 00127 ///\privatesection 00128 /// Variable holding the diff engine type 00129 public $DiffEngine; 00130 00131 /// The instance of the diff engine class 00132 public $DiffEngineInstance; 00133 00134 /// The allowed input on which to diff 00135 public $DIFF_TYPE = array( 'text' => 0, 00136 'xml' => 1, 00137 'container' => 2 ); 00138 } 00139 00140 ?>