UmlSequenceDiagramPrinterToHtml.class.php

Go to the documentation of this file.
00001 <?php
00013 class UmlSequenceDiagramPrinterToHtml implements UmlSequenceDiagramPrinterInterface
00014 {
00021     protected static $objInstance;
00022 
00029     protected $objUmlSequenceDiagram;
00030 
00036     protected $objConfiguration;
00037 
00044     public static function getInstance()
00045     {
00046         if( self::$objInstance == null )
00047         {
00048             self::$objInstance = new UmlSequenceDiagramPrinterToHtml();
00049         }
00050         return self::$objInstance;
00051     }
00052 
00053     public function __construct()
00054     {
00055         $objConfiguration = new UmlSequenceDiagramPrinterConfigurationToHtml();
00056         $this->setConfiguration( $objConfiguration );
00057     }
00064     public function setConfiguration( UmlSequenceDiagramPrinterConfigurationInterface $objConfiguration )
00065     {
00066         $this->objConfiguration = $objConfiguration;
00067         return $this;
00068     }
00069 
00075     public function getConfiguration()
00076     {
00077         return $this->objConfiguration;
00078     }
00079 
00087     public function perform( UmlSequenceDiagram $objUmlSequenceDiagram )
00088     {
00089         $this->objUmlSequenceDiagram = $objUmlSequenceDiagram;
00090         return $this->getPage();
00091     }
00092 
00096     public function getHeader()
00097     {
00098         header( "Content-type: text/html" );
00099     }
00100 
00101     public function getTemplate( $strTemplateFile , $arrReplace )
00102     {
00103         $strTemplateContent = file_get_contents( "template/" . $strTemplateFile , true );
00104         $strTemplateContent = str_replace(
00105             array_keys( $arrReplace ),
00106             array_values( $arrReplace ),
00107             $strTemplateContent
00108         );
00109         return $strTemplateContent;
00110     }
00111 
00112     public function getDiagram()
00113     {
00114         $arrReplace = array();
00115         $arrReplace[ '<codetodiagram:actors/>' ] = $this->getActors();
00116         $arrReplace[ '<codetodiagram:messages/>' ] = $this->getMessages();
00117         $arrReplace[ '<codetodiagram:embededscript/>' ] = $this->getEmbededScript();
00118 
00119         if( $this->getConfiguration()->getShowDetails() )
00120         {
00121             $arrReplace[ '<codetodiagram:details/>' ] = $this->getDetails();
00122         }
00123         else
00124         {
00125             $arrReplace[ '<codetodiagram:details/>' ] = '';
00126         }
00127         
00128         return $this->getTemplate( "diagram.html" , $arrReplace );
00129     }
00130 
00131     public function getEmbededScript()
00132     {
00133         if( $this->getConfiguration()->getEmbeded() )
00134         {
00135             $strStyle = $this->getStyle();
00136         }
00137         else
00138         {
00139             $strStyle = "";
00140         }
00141         $strStyle = str_replace( "\r", '', $strStyle );
00142         return implode( "'+\n'" , explode( "\n" , $strStyle ) );
00143     }
00144     
00150     public function getPage()
00151     {
00152         if( $this->getConfiguration()->getEmbeded() )
00153         {
00154             return $this->getDiagram();
00155         }
00156         else
00157         {
00158             $arrReplace = array();
00159             $arrReplace[ '<codetodiagram:diagram/>' ] = $this->getDiagram();
00160             $arrReplace[ 'codetodiagram:style' ] = $this->getStyle();
00161             return $this->getTemplate( "page.html" , $arrReplace );
00162         }
00163     }
00164 
00165     protected function getSequenceStyleFile()
00166     {
00167         return $this->getConfiguration()->getPublicFolderPath() . "css/sequenceStyle.css";
00168     }
00169 
00170     protected function getProportion()
00171     {
00172         return $this->getConfiguration()->getZoom() / 100 ;
00173     }
00179     protected function getStyle()
00180     {
00181         # get the public folder
00182         $strPublicPath = $this->getConfiguration()->getPublicFolderPath();
00183 
00184         # get the url of the static style file
00185         $strCssFile = "{$strPublicPath}css/sequenceStyle.css";
00186 
00187         # if is external access, all the style should be in line
00188         if( $this->getConfiguration()->getExternalAccess() )
00189         {
00190             $strStyleInLine = file_get_contents( $strCssFile  );
00191             $strSequenceStyleUrl = "";
00192         }
00193         else
00194         {
00195             $strStyleInLine = "";
00196             $strSequenceStyleUrl = $strCssFile;
00197         }
00198 
00199         # calc the number of actors and messages 
00200         $intQtdActors = sizeof( $this->objUmlSequenceDiagram->getActors() );
00201         if( $intQtdActors > 1 )
00202         {
00203             $intQtdMessageLine = $intQtdActors - 1;
00204         }
00205         else
00206         {
00207             $intQtdMessageLine = 1;
00208         }
00209 
00210         # calc the size of the header of each actor
00211         $intActorHeaderWidth =
00212         round(
00213             ( $this->getProportion()  * $this->getConfiguration()->getWidth() )
00214             /
00215             ( $intQtdActors )
00216         ) - 1;
00217 
00218         # calc the width of one slice of each actor
00219         $intSlice = $intActorHeaderWidth * 2;
00220 
00221         # calc the actor sizes
00222         $intActorBarWidth = floor( $intActorHeaderWidth * $this->getConfiguration()->getActorBarPercentWidth() / 100 );
00223         $intActorLogoWidth = floor( $intActorHeaderWidth * $this->getConfiguration()->getActorHeaderPercentWidth() / 100 );
00224         $intActorLogoBorder = floor( ( $intActorHeaderWidth - $intActorLogoWidth ) / 2 );
00225         $intActorHeaderHeight = floor( $intActorHeaderWidth * $this->getConfiguration()->getLineActorPercentHeight() / 100 );
00226         $intActorLogoHeight = floor( $intActorHeaderHeight * $this->getConfiguration()->getActorLogoPercentWidth() / 100 );
00227         $intActorMarginLogo = 1;
00228         $intActorLogoPercentHeight = floor( $this->getConfiguration()->getActorLogoPercentWidth() ) - $intActorMarginLogo;
00229         $intActorBoxPercentHeight = floor( 100 -  $this->getConfiguration()->getActorLogoPercentWidth() ) - $intActorMarginLogo;
00230 
00231         # calc the messages sizes
00232         $intMessageHeaderWidth = floor( $intSlice - $intActorHeaderWidth );
00233         $intMessageBarWidth = floor( ( $intSlice - $intActorBarWidth ) / 2 ) + 1 ;
00234         $intMessageBarHeight = floor( $intMessageBarWidth * $this->getConfiguration()->getLinePercentHeight() / 100 );
00235 
00236         # calc the font size
00237         $intFontWidth =
00238         floor(
00239                 ( $intMessageBarHeight * $this->getConfiguration()->getPercentFont() )
00240                 /
00241                 100        
00242         );
00243 
00244         # calc the line margin
00245         $intLineMargin = round( $intMessageBarWidth / 2);
00246 
00247         # put the data into the replace container
00248         $arrReplace = array();
00249         $arrReplace[ "codetodiagram_sequencestyleurl" ]         = $strSequenceStyleUrl;
00250         $arrReplace[ "codetodiagram:body_width" ]               = round( $this->getProportion() * $this->getConfiguration()->getWidth() ) . "px";
00251         $arrReplace[ "codetodiagram:body_font" ]                = round( $this->getProportion() * $intFontWidth ). "px";
00252         $arrReplace[ "codetodiagram:slice_width" ]              = $intSlice . "px";
00253         $arrReplace[ "codetodiagram:message_header_width" ]     = $intMessageHeaderWidth . "px";
00254         $arrReplace[ "codetodiagram:message_bar_width" ]        = $intMessageBarWidth. "px";
00255         $arrReplace[ "codetodiagram:message_bar_height" ]       = $intMessageBarHeight. "px";
00256         $arrReplace[ "codetodiagram:message_row_width" ]        = round( $intMessageBarWidth - 2 *  $intActorBarWidth ). "px";
00257         $arrReplace[ "codetodiagram:message_row_short_width" ]  = round( $intLineMargin - 2 *  $intActorBarWidth ). "px";
00258         $arrReplace[ "codetodiagram:actor_header_width" ]       = $intActorHeaderWidth . "px";
00259         $arrReplace[ "codetodiagram:actor_header_height" ]      = $intActorHeaderHeight . "px";
00260         $arrReplace[ "codetodiagram:actor_bar_width" ]          = $intActorBarWidth . "px";
00261         $arrReplace[ "codetodiagram:actor_logo_width" ]         = $intActorLogoWidth . "px";
00262         $arrReplace[ "codetodiagram:actor_logo_height" ]        = $intActorLogoHeight . "px";
00263         $arrReplace[ "codetodiagram:actor_logo_percent_height" ]= $intActorLogoPercentHeight . "%";
00264         $arrReplace[ "codetodiagram:actor_box_percent_height" ] = $intActorBoxPercentHeight . "%";
00265         $arrReplace[ "codetodiagram:actor_logo_border" ]        = $intActorLogoBorder . "px";
00266         $arrReplace[ "codetodiagram:line_height" ]              = $intMessageBarHeight . "px";
00267         $arrReplace[ "codetodiagram_styleinline" ]              = $strStyleInLine;
00268         $arrReplace[ "codetodiagram:line_margin" ]              = $intLineMargin . "px";
00269         $arrReplace[ "codetodiagram:public_path" ]              = $strPublicPath;
00270 
00271         # feed the style template with the received data
00272         return "*/" . $this->getTemplate( "style.css" , $arrReplace ) . "/*";
00273     }
00274 
00275     protected function makeBase64File( $strFile , $strMime )
00276     {
00277         $strContent = file_get_contents( $strFile );
00278         $strBase64  = base64_encode( $strContent );
00279         return ('data:' . $strMime . ';base64,' . $strBase64 );
00280 
00281     }
00282 
00283     protected function getActor( UmlSequenceDiagramActor $objActor )
00284     {
00285         $objStereotype = $objActor->getStereotype();
00286 
00287         if( $objStereotype->getDefault() )
00288         {
00289             $strImage = '<img alt="' . $objActor->getStereotype()->getName() . '" src="' . $this->getConfiguration()->getPublicFolderPath() . 'images/' . $objStereotype->getName() . '.gif"/>';
00290             //$strImage = '<img alt="' . $objActor->getStereotype()->getName() . '" src="' . $this->makeBase64File( $this->getConfiguration()->getPublicPath() . 'images/' . $objStereotype->getName() . '.gif' , "image/gif" ) . '"/>';
00291         }
00292         else
00293         {
00294             $strImage = '<img alt="' . $objActor->getStereotype()->getName() . '"  src="' . $objStereotype->getImage() . '"/>';
00295         }
00296 
00297         $arrReplace = array();
00298         $arrReplace[ "codetodiagram:actor_stereotype" ] = $objStereotype->getName();
00299         $arrReplace[ "codetodiagram:actor_image" ] = $strImage;
00300         $arrReplace[ "codetodiagram:actor_name" ] = $objActor->getName();
00301 
00302         return $this->getTemplate( "actor.html" , $arrReplace );
00303     }
00304 
00310     protected function getActors()
00311     {
00312         $arrActors = $this->objUmlSequenceDiagram->getActors();
00313         $strActorCollection = '';
00314 
00315         foreach( $arrActors as $objActor )
00316         {
00317             $strActorCollection .= $this->getActor( $objActor );
00318         }
00319 
00320         $arrReplace[ '<codetodiagram:actor_collection/>' ] = $strActorCollection;
00321 
00322         return $this->getTemplate( "actors.html" , $arrReplace );
00323     }
00324 
00331     protected function getMessage( UmlSequenceDiagramMessage $objMessage )
00332     {
00333         $strResult = '';
00334         $strNotesBefore = '';
00335         $strNotesAfter = '';
00336 
00337         $arrNotes = $objMessage->getNotesBefore();
00338         foreach( $arrNotes as $objNote )
00339         {
00340             $strNotesBefore .= $this->getNote( $objNote , false );
00341         }
00342         $arrNotes = $objMessage->getNotesAfter();
00343         foreach( $arrNotes as $objNote )
00344         {
00345             $strNotesAfter .= $this->getNote( $objNote , true );
00346         }
00347 
00348         if( $objMessage->isReverse() )
00349         {
00350             $intStart = $objMessage->getActorTo()->getPosition();
00351             $intEnd = $objMessage->getActorFrom()->getPosition();
00352         }
00353         else
00354         {
00355             $intEnd = $objMessage->getActorTo()->getPosition();
00356             $intStart = $objMessage->getActorFrom()->getPosition();
00357         }
00358 
00359         $arrActors = $objMessage->getUmlSequenceDiagram()->getActors();
00360         $intQtdActors = sizeof( $arrActors );
00361 
00362         $strReverse = $objMessage->isReverse() ? 'reverse' : 'regular';
00363         $strLarge = $objMessage->isLarge() ? 'large' : 'short';
00364         $strRecursive = $objMessage->isRecursive() ? 'recursive' : '';
00365 
00366         $arrReplace = array();
00367         $arrReplace[ "codetodiagram:reverse" ] = $strReverse;
00368         $arrReplace[ "codetodiagram:large" ] = $strLarge;
00369         $arrReplace[ "codetodiagram:recursive" ] = $strRecursive;
00370         $arrReplace[ "codetodiagram:message_type" ] = $objMessage->getType();
00371         $arrReplace[ "<codetodiagram:message_text/>" ] =  UmlSequenceDiagramPrinterToHtml::getMessageText( $objMessage );
00372         $arrReplace[ "codetodiagram:message_id" ] = $objMessage->getPosition();
00373         $arrReplace[ "<codetodiagram:message_position/>" ] = $objMessage->getPosition();
00374         $arrReplace[ "codetodiagram:actor_from" ] = "actor" . $intStart;
00375         $arrReplace[ "codetodiagram:message_dif" ] = "dif" . ( $intStart - $intEnd );
00376         $arrReplace[ "<codetodiagram:message_values/>" ] = $this->getValues( $objMessage );
00377 
00378         while( $objActorActual = array_shift( $arrActors ) )
00379         {
00380             $intNextPosition =  $objActorActual->getPosition() + 1;
00381             $strFinal = ( $objActorActual->getPosition() == $intQtdActors ) ? "final" : "regular";
00382 
00387             $arrReplace[ "codetodiagram:message_final" ] = $strFinal;
00388             $arrReplace[ "codetodiagram:actoractual_name" ] = $objActorActual->getName();
00389             $arrReplace[ "codetodiagram:message_dif" ] = $intNextPosition - $intEnd;;
00390             $arrReplace[ "codetodiagram:message_values" ] = "";
00391 
00392             if( $objActorActual->getPosition() < $intStart )
00393             {
00394                 $strResult .= $this->getTemplate( "line_before.html" , $arrReplace );
00395             }
00396             elseif( $objActorActual->getPosition() == $intStart )
00397             {
00398                 // start line //
00399                 $strResult .=  $this->getTemplate( "line_start.html" , $arrReplace );
00400             }
00401             elseif( ( $objActorActual->getPosition() > $intStart ) and ($intNextPosition  < $intEnd ) )
00402             {
00403                 // inside line //
00404                 $strResult .=  $this->getTemplate( "line_inside.html" , $arrReplace );
00405 
00406             }
00407             elseif( $intNextPosition == $intEnd )
00408             {
00409                 // last line //
00410                 $strResult .=  $this->getTemplate( "line_end.html" , $arrReplace );
00411             }
00412             elseif( $intNextPosition > $intEnd )
00413             {
00414                 // after line //
00415                 $strResult .=  $this->getTemplate( "line_after.html" , $arrReplace );
00416             }
00417             else
00418             {
00419                 $strMessage = '';
00420                 $strMessage .= ' Invalid Position ' . "\n" ;
00421                 $strMessage .= ' Actual Actor ' . $objActorActual->getPosition() ;
00422                 $strMessage .= ' Message Start ' . $intStart ;
00423                 $strMessage .= ' Message End' . $intEnd ;
00424                 throw new Exception( $strMessage );
00425             }
00426         }
00427 
00428         $arrReplace = array();
00429         $arrReplace[ '<codetodiagram:message_collection/>' ] = $strResult;
00430         $arrReplace[ '<codetodiagram:message_title/>' ] = $this->getMessageValues( $objMessage , false );
00431         $arrReplace[ 'codetodiagram:message_click' ] = "window.location = '#message_" . $objMessage->getPosition() . "'";
00432 
00433 
00434 
00435         $strMessages = $this->getTemplate( "messages.html" , $arrReplace );
00436         $strMessages = $strNotesBefore . $strMessages . $strNotesAfter;
00437         return $strMessages;
00438     }
00439 
00447     protected function getNote( UmlSequenceDiagramNote $objNote , $booAfter = true )
00448     {
00449         $arrActors = $objNote->getActor()->getUmlSequenceDiagram()->getActors();
00450         $intPosition = $objNote->getActor()->getPosition();
00451 
00452         $strResult = "";
00453 
00454         foreach( $arrActors as $objActor )
00455         {
00456             $arrReplace = array();
00457 
00458             $strFinal = ( $objActor->getPosition() == sizeof( $arrActors ) ) ? "final" : "regular";
00459 
00460             $arrReplace[ "codetodiagram:message_final" ] = $strFinal;
00461             $arrReplace[ "codetodiagram:actoractual_name" ] = $objActor->getName();
00462             $arrReplace[ "codetodiagram:message_dif" ] = 0;
00463             $arrReplace[ "codetodiagram:message_type" ] = "";
00464             $arrReplace[ "codetodiagram:reverse" ] = "";
00465             $arrReplace[ "codetodiagram:large" ] = "";
00466             $arrReplace[ "codetodiagram:recursive" ] = "";
00467             
00472             if( $objActor->getPosition() < $intPosition )
00473             {
00474                 $strResult .= $this->getTemplate( "line_before.html" , $arrReplace );
00475             }
00476             elseif( $objActor->getPosition() == $intPosition )
00477             {
00478                 $strContent = $objNote->getContent();
00479                 $intMaxSize = 30;
00480                 if( strlen( $strContent ) > $intMaxSize )
00481                 {
00482                     $strShortContent = substr( $strContent , 0 , $intMaxSize - strlen( "..." ) ) . "...";   
00483                 }
00484                 else
00485                 {
00486                         $strShortContent = $strContent;
00487                 }
00488                 $arrReplace[ "<codetodiagram:message_text/>" ] = $strShortContent;
00489                 $arrReplace[ "codetodiagram:message_values" ] = $strContent;
00490                 $strResult .=  $this->getTemplate( "line_note.html" , $arrReplace );
00491             }
00492             elseif( $objActor->getPosition()  > $intPosition )
00493             {
00494                 // after line //
00495                 $strResult .=  $this->getTemplate( "line_after.html" , $arrReplace );
00496             }
00497             else
00498             {
00499                 $strMessage = '';
00500                 $strMessage .= ' Invalid Position ' . "\n" ;
00501                 $strMessage .= ' Actual Actor ' . $objActorActual->getPosition() ;
00502                 $strMessage .= ' Message Start ' . $intStart ;
00503                 $strMessage .= ' Message End' . $intEnd ;
00504                 throw new Exception( $strMessage );
00505             }
00506         }
00507 
00508         $arrReplace = array();
00509         $arrReplace[ '<codetodiagram:message_collection/>' ] = $strResult;
00510         $arrReplace[ '<codetodiagram:message_title/>' ] = "";
00511         $arrReplace[ 'codetodiagram:message_click' ] = "";
00512 
00513         //return $strResult;
00514         $strReturn = $this->getTemplate( "messages.html" , $arrReplace );
00515 //        CorujaDebug::debug( $strReturn , 1 );
00516         return $strReturn;
00517     }
00518 
00525     protected function getMessages()
00526     {
00527         $arrMessages = $this->objUmlSequenceDiagram->getMessages();
00528         $strMessageCollection = '';
00529 
00530         foreach( $arrMessages as $objMessage )
00531         {
00532             $strMessageCollection .= $this->getMessage( $objMessage );
00533         }
00534 
00535         return $strMessageCollection;
00536     }
00537 
00538     public function getValue( UmlSequenceDiagramValue $objValue , UmlSequenceDiagramMessage $objMessage )
00539     {
00540         $strMark = ( $objMessage->getType() == 'return' ) ? '' : '$';
00541 
00542         if( is_object( $objValue->getValue()  ) )
00543         {
00544             $strType = 'object';
00545             $strClass = get_class( $objValue->getValue() );
00546         }
00547         else
00548         {
00549             $strType = gettype( $objValue->getValue() );
00550             $strClass = '';
00551         }
00552 
00553         $arrReplace[ '<codetodiagram:attribute_mark/>' ] = $strMark;
00554         $arrReplace[ '<codetodiagram:attribute_name/>' ] = $objValue->getName() ;
00555         $arrReplace[ '<codetodiagram:attribute_type/>' ] = $strType;
00556         $arrReplace[ '<codetodiagram:attribute_class/>' ] = $strClass;
00557         if( $objValue->getValue()  !== null )
00558         {
00559             $arrReplace[ '<codetodiagram:attribute_varexport/>' ] = $this->getVar( $objValue->getValue() );
00560         }
00561         else
00562         {
00563             $arrReplace[ '<codetodiagram:attribute_varexport/>' ] = "";
00564         }
00565 
00566         return $this->getTemplate( "value.html" , $arrReplace );
00567     }
00568 
00576     public function getValues( UmlSequenceDiagramMessage $objMessage )
00577     {
00578         $strValuesCollection = '';
00579 
00580         $arrValues = $objMessage->getValues();
00581         $strValueCollection = '';
00582         if( sizeof( $arrValues ) > 0 )
00583         {
00584             foreach( $arrValues as $objValue )
00585             {
00586                 $strValueCollection .= $this->getValue( $objValue , $objMessage );
00587             }
00588             $strValueCollection = "<ul>" . $strValueCollection . "</ul>";
00589         }
00590 
00591         $arrReplace = array();
00592         $arrReplace[ '<codetodiagram:value_collection/>' ] = $strValueCollection;
00593 
00594         return $this->getTemplate( "line_values.html" , $arrReplace );
00595     }
00596 
00597     public function getMessageValues( UmlSequenceDiagramMessage $objMessage , $booHtmlTags = false )
00598     {
00599         if( $booHtmlTags )
00600         {
00601             $strResult = '<li><div class="message" id="div_message_' . $objMessage->getPosition() . '">' . "\n";
00602         }
00603         else
00604         {
00605             $strResult = '';
00606         }
00607 
00608         $strText = html_entity_decode( $objMessage->getText() );
00609 
00610         switch( $strText )
00611         {
00612             case '<<create>>':
00613             {
00614                 if( $booHtmlTags )
00615                 {
00616                     $strText = '<span class="detail_actor from">' . $objMessage->getActorFrom()->getName() . '</span> create new ' . '<span class="detail_actor to">' . $objMessage->getActorTo()->getName() .  '</span>';
00617                 }
00618                 else
00619                 {
00620                     $strText = $objMessage->getActorFrom()->getName() . ' create new ' . $objMessage->getActorTo()->getName();
00621                 }
00622                 break;
00623             }
00624             case '<<destroy>>':
00625             {
00626                 if( $booHtmlTags )
00627                 {
00628                     $strText = '<span class="detail_actor from">' . $objMessage->getActorFrom()->getName() . '</span>' .  ' destroy ' . '<span class="detail_actor to">' . $objMessage->getActorTo()->getName() .  '</span>';
00629                 }
00630                 else
00631                 {
00632                     $strText = $objMessage->getActorFrom()->getName();
00633                 }
00634                 break;
00635             }
00636             default:
00637             {
00638                 if( $objMessage->getType() == 'call' )
00639                 {
00640                     if( $booHtmlTags )
00641                     {
00642                         $strText = '<span class="detail_actor from">' . $objMessage->getActorFrom()->getName() .  '</span>' .  ' ' . $objMessage->getType() . ' ' . '<span class="detail_actor to">' . $objMessage->getActorTo()->getName() .  '</span>' .  '-&gt;' . self::getMessageText( $objMessage );
00643                     }
00644                     else
00645                     {
00646                         $strText = $objMessage->getActorFrom()->getName() .  ' ' . $objMessage->getType() . ' ' . $objMessage->getActorTo()->getName() . '-&gt;' . $objMessage->getText();
00647                     }
00648                 }
00649                 else
00650                 {
00651                     if( $booHtmlTags )
00652                     {
00653                         $strText = '<span class="detail_actor from">' . $objMessage->getActorTo()->getName() .  '</span>' .  ' receive from ' . '<span class="detail_actor to">' . $objMessage->getActorFrom()->getName() .  '</span>' .  '-&gt;' . $objMessage->getText();
00654                     }
00655                     else
00656                     {
00657                         $strText = $objMessage->getActorTo()->getName() . ' receive from ' . $objMessage->getActorFrom()->getName() .  '-&gt;' . $objMessage->getText();
00658                     }
00659                 }
00660                 break;
00661             }
00662         }
00663 
00664         if( $booHtmlTags )
00665         {
00666             $strResult .= '<a name="message_' . $objMessage->getPosition() . '">' . $strText . '</a>' . "\n";
00667             $arrValues = $objMessage->getValues();
00668 
00669             $strResult .= '<div class="values" >' . "\n";
00670             foreach( $arrValues as $intValueId => $objValue )
00671             {
00672 
00673                 if( $objMessage->getType() != 'return' )
00674                 {
00675                     $strResult .= '<strong> $' . $objValue->getName() . '</strong>' .  "\n";
00676 //                  $strResult .= '<a class="noLink" name="message_' . $intMessageId . '_param_' . $intValueId . '" ><strong> $' . $objValue->getName() . '</strong> </a>' .  "\n";
00677                 }
00678                 else
00679                 {
00680                     $strResult .= '<strong> ' . $objValue->getName() . ' </strong>' . "\n";
00681                 }
00682                 $strResult .= '   <div>' .  self::getVar( $objValue->getValue() ). '</div>' . "\n";
00683             }
00684 
00685             $strResult .= '</div></div></li>' . "\n";
00686         }
00687         else
00688         {
00689             $strResult .= $strText;
00690         }
00691 
00692         return $strResult;
00693     }
00694 
00695     public function getDetails()
00696     {
00697         $strMessageValues = '';
00698         $arrMessages = $this->objUmlSequenceDiagram->getMessages();
00699         foreach( $arrMessages as $objMessage )
00700         {
00704             $strMessageValues .= $this->getMessageValues( $objMessage , true);
00705         }
00706 
00707         $arrReplace = array();
00708         $arrReplace[ '<codetodiagram:message_values/>' ] = $strMessageValues;
00709         return $this->getTemplate( "details.html" , $arrReplace );
00710     }
00711 
00712     private static function getVar( $mixVar )
00713     {
00714         if( $mixVar == null )
00715         {
00716             return "";
00717         }
00718         $strHtml = highlight_string( '<?php ' .
00719             self::removeRecursiveProblem(
00720                     $mixVar
00721             ),
00722             true
00723         );
00724         $strHtml = str_replace( '&lt;?php&nbsp;', '', $strHtml );
00725         $strHtml = str_replace( '<span style="color: #0000BB"></span>', '', $strHtml );
00726         return $strHtml;
00727 
00728     }
00736     private static function removeRecursiveProblem( $mixExpression )
00737     {
00738         $booActive = CodeInstrumentationReceiver::getInstance()->getConfiguration()->getActive();
00739         CodeInstrumentationReceiver::getInstance()->getConfiguration()->setActive( false );
00740 
00741         $mixExpression = serialize( $mixExpression );
00742         $arrExpression = explode( ";" , $mixExpression );
00743         foreach( $arrExpression as $intKey => $strExpression )
00744         {
00745             $arrElement = explode( ":" , $strExpression );
00746             if( $arrElement[0] == "r" )
00747             {
00748                 $arrElement[0] = "s";
00749                 $arrElement[2] = '"*recursive*"';
00750                 $arrElement[1] = strlen( $arrElement[2] ) - 2;
00751             }
00752             $arrExpression[ $intKey ] = implode( ":" , $arrElement );
00753         }
00754 
00755         $mixExpression = implode( ";" , $arrExpression );
00756         $mixExpression = unserialize( $mixExpression );
00757 
00758         $mixExpression = ( var_export( $mixExpression , true )  );
00759         $mixExpression = str_replace( '<span style="color: #0000BB"></span>' , '' , $mixExpression );
00760         $arrClasses = explode( "::" , $mixExpression );
00761 
00762         foreach( $arrClasses as $intKey => $strClass )
00763         {
00764             $arrClass = explode( " " , $strClass );
00765             $intLast =  sizeof( $arrClass ) - 1;
00766             $arrClass[ $intLast ] = ''. $arrClass[ $intLast ] . '';
00767             $strClass = implode( " " , $arrClass );
00768             $arrClasses[ $intKey ] = $strClass;
00769         }
00770 
00771         $mixExpression = implode( "::" , $arrClasses );
00772 
00773         CodeInstrumentationReceiver::getInstance()->getConfiguration()->setActive( $booActive );
00774         return $mixExpression;
00775     }
00776 
00777     private static function getMessageText( UmlSequenceDiagramMessage $objMessage )
00778     {
00779         $strText = $objMessage->getText();
00780         if( $objMessage->getType() != 'call' )
00781         {
00782             $strText = htmlentities( $strText );
00783         }
00784         else
00785         {
00786             $strClass = $objMessage->getActorTo()->getClassName();
00787             $strMethod = $objMessage->getMethod();
00788             if( class_exists( $strClass ) )
00789             {
00790                 $objReflectedClass = new CodeReflectionClass( $strClass );
00791                 if( method_exists( $strClass , $strMethod ) )
00792                 {
00793                     $objReflectedMethod = $objReflectedClass->getMethod( $strMethod );
00794                     $arrReflectedParameter = $objReflectedMethod->getParameters();
00795                 }
00796                 else
00797                 {
00798                     $arrReflectedParameter = array();
00799                 }
00800                 $arrSearch = array();
00801                 $arrReplace = array();
00802                 foreach( $arrReflectedParameter as $intPos => $objReflectedParameter )
00803                 {
00804                     $arrSearch[] = $objReflectedParameter->getCode();
00805                     $arrReplace[] = $objReflectedParameter->getCode();
00806     //                $arrReplace[] = '<a class="noLink" href="#message_' . $intMessageId . '_param_' . $intPos . '">' . $objReflectedParameter->getCode() . '</a>';
00807                 }
00808                 $strText = str_replace( $arrSearch , $arrReplace , htmlentities( $strText ) );
00809             }
00810         }
00811         $strText = str_replace( '<span style="color: #0000BB"></span>' , '' , $strText );
00812         return ( $strText );
00813     }
00814 }
00815 ?>

Generated on Sat Apr 7 14:19:10 2012 for CodeToDiagram by  doxygen 1.5.9