CodeToDiagram Class Reference

List of all members.

Public Member Functions

 __construct ()
 getConfiguration ()
 setPrinter (UmlSequenceDiagramPrinterInterface $objPrinter)
 getPrinter ()
 setPrinterConfiguration (UmlSequenceDiagramPrinterConfigurationInterface $objPrinterConfiguration)
 getPrinterConfiguration ()
 setOutputType ($strType)
 getOutputType ()
 setPrinterType ($strType)
 getPrinterType ()
 setExternalAcess ($booExternalAccess)
 getExternalAcess ()
 setStarted ($booStarted)
 getStarted ()
 setFileFrom ($strFileFrom)
 getFileFrom ()
 setFileName ($strFileName)
 getFileName ()
 setCallerPath ($strCallerPath)
 getCallerPath ()
 setPublicPath ($strPublicPath)
 getPublicPath ()
 start ()
 restart ()
 save ()
 __destruct ()
 addFile ($strFileFrom, $strFile)
 CodeToDiagramRequireOnce ($strFileFrom, $strFile)
 CodeToDiagramIncludeOnce ($strFileFrom, $strFile)
 CodeToDiagramRequire ($strFileFrom, $strFile)
 CodeToDiagramInclude ($strFileFrom, $strFile)
 CodeToDiagramExit ($strFileFrom= '', $strMessage= '')
 codeInstrumentationLine ($strLine, $strTextSearch)
 setCallerPathByFile ($strCallerFile)
 addNote ($strNoteContent, $booAfter=true)
 __call ($strMethod, $arrArguments)

Static Public Member Functions

static hasInstance ()
static getInstance ()
static init ($strFile)

Public Attributes

const RUN_IN_FILES = false
const REMOVE_FILES = true
const CODE_TO_DIAGRAM_CLASS_PREFIX = "CTD"
const OUTPUT_TYPE_STRING = "string"
const OUTPUT_TYPE_FILE = "file"
const OUTPUT_TYPE_SCREEN = "screen"
const PRINTER_TYPE_XML = "xml"
const PRINTER_TYPE_HTML = "html"
const MSG_NO_WRITE_PERMISSION = " The user of the system does not have permission to write the code to diagram files. Change the RUN_IN_FILES to false and save your files into a allowed folder."

Protected Member Functions

 loadDefaultsStereotypes ()
 fixFileName ($strFileFrom, $strFile)
 hasFile ($strFileFrom, $strFile)
 convertFileContent ($strContentFile, $strFile, $strFullFile)
 codeInstrumentationClass ($strTextSearch, array &$arrOldClasses, array &$arrNewClasses, array &$arrLines)
 preloadFile ($strFileName, $strContentFile)
 codeInstrumentationFile ($strFileName, $strContentFile)
 loadFile ($strFileFrom, $strFile)

Protected Attributes

 $arrFiles = array()
 $booStart = false
 $strFileFrom = null
 $strFileName = "diagram.html"
 $strOutputType = self::OUTPUT_TYPE_SCREEN
 $strPrinterType = self::PRINTER_TYPE_HTML
 $objPrinter
 $strCallerPath
 $strPublicPath
 $booExternalAccess = false

Static Protected Attributes

static $objInstance
static $arrDefaultStereotypes = array( 'user' , 'system' , 'user' , 'entity' , 'controller' , 'boundary' , 'database')

Private Member Functions

 checkPermissionToWrite ($strFileName)


Detailed Description

Code to diagram master class. Take to itself the service of include and require. Make code instrumentation of all the classes includes making this way possible to wacth some code execution.

Author:
Thiago Henrique Ramos da Mata <thiago.henrique.mata@gmail.com>

Definition at line 14 of file CodeToDiagram.class.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor of the CodetoDiagram

Create the child objects

Definition at line 173 of file CodeToDiagram.class.php.

References getPrinterType(), loadDefaultsStereotypes(), and setPrinterType().

00174     {
00175         $this->loadDefaultsStereotypes();
00176         $this->setPrinterType( $this->getPrinterType() );
00177     }

__destruct (  ) 

On destruct it will save the actual diagram any way

Definition at line 777 of file CodeToDiagram.class.php.

References save().

00777                                       {
00778 
00779                 $this->save();
00780         }


Member Function Documentation

__call ( strMethod,
arrArguments 
)

Definition at line 1182 of file CodeToDiagram.class.php.

01183         {
01184             throw new CodeToDiagramException( "unknow method " . $strMethod . " in " . get_class( $this ) );
01185         }

addFile ( strFileFrom,
strFile 
)

Add a file into the code instrumentation process

Parameters:
string $strFileFrom
string $strFile
Returns:
CodeToDiagram

Definition at line 822 of file CodeToDiagram.class.php.

References $strFile, $strFileFrom, and fixFileName().

Referenced by loadFile().

00823         {
00824                 $strFile = $this->fixFileName( $strFileFrom, $strFile );
00825 
00826                 $this->arrFiles[] = $strFile;
00827 
00828                 return $this;
00829         }

addNote ( strNoteContent,
booAfter = true 
)

Add a note into the diagram

Parameters:
string $strNoteContent
boolean $booAfter
Returns:
UmlSequenceDiagramNote

Definition at line 1163 of file CodeToDiagram.class.php.

References getInstance().

01164         {
01165             $objNote = new UmlSequenceDiagramNote();
01166             $objNote->setContent( $strNoteContent );
01167             $objMessage = CodeInstrumentationReceiver::getInstance()->getActualMessage();
01168             $objActor =  CodeInstrumentationReceiver::getInstance()->getActualActor();
01169             $objNote->setActor( $objActor );
01170             
01171             if( $booAfter )
01172             {
01173                 $objMessage->addNoteAfter($objNote);
01174             }
01175             else
01176             {
01177                 $objMessage->addNoteBefore( $objNote );
01178             }
01179             return $objNote;
01180         }

checkPermissionToWrite ( strFileName  )  [private]

Check if the user has permission to write into the file folder.

Exceptions:
CodeToDiagramException 
Parameters:
string $strFileName
Returns:
boolean

Todo:
deal with write permission into dirs..

Definition at line 655 of file CodeToDiagram.class.php.

References $strFileName, CorujaFileManipulation::getPathOfFile(), and getPublicPath().

Referenced by codeInstrumentationFile(), preloadFile(), and save().

00656     {
00657         $strPath = CorujaFileManipulation::getPathOfFile( $strFileName );
00658 
00659         if( $strPath == "" )
00660         {
00661             $strPath = $this->getPublicPath();
00662         }
00663 
00664         if( file_exists( $strFileName ) )
00665         {
00666             if( !is_writable( $strFileName ) )
00667             {
00668                 throw new CodeToDiagramException( 1 .  self::MSG_NO_WRITE_PERMISSION );
00669             }
00670             return TRUE;
00671         }
00672 
00673         if( is_dir( $strPath ) )
00674         {
00678             return true;
00679         }
00680 
00681         if( !mkdir( $strPath , 0777, TRUE ) )
00682         {
00683                 throw new CodeToDiagramException(3 . self::MSG_NO_WRITE_PERMISSION );
00684         }
00685         return TRUE;
00686     }

codeInstrumentationClass ( strTextSearch,
array &$  arrOldClasses,
array &$  arrNewClasses,
array &$  arrLines 
) [protected]

Implements a code instrumentation into a class

Parameters:
string $strTextSearch
array $arrOldClasses
array $arrNewClasses
array $arrLines

Definition at line 1002 of file CodeToDiagram.class.php.

References codeInstrumentationLine().

Referenced by codeInstrumentationFile().

01003         {
01004                 foreach( $arrLines as $intLine => $strLine )
01005                 {
01006                         $arrResult = $this->codeInstrumentationLine( $strLine , $strTextSearch  );
01007 
01008                         if( sizeof( $arrResult ) !== 0 )
01009                         {
01010                                 $arrOldClasses[] = $arrResult[ "class_old" ];
01011                                 $arrNewClasses[] = $arrResult[ "class_new" ];
01012                                 $arrLines[ $intLine ] = $arrResult[ "line" ];
01013                         }
01014                 }
01015         }

codeInstrumentationFile ( strFileName,
strContentFile 
) [protected]

Implement a code instrumentation into a file

Parameters:
string $strFile
string $strContentFile

Fixme:
the real codeinstrumentation of interfaces fails by mysterious reasons

Definition at line 1051 of file CodeToDiagram.class.php.

References $oReflectionCode, $strFileName, $strNewCode, checkPermissionToWrite(), codeInstrumentationClass(), and preloadFile().

Referenced by loadFile().

01052         {
01053                 $arrLines = explode( "\n"  , $strContentFile );
01054                 $arrOldClasses  = array();
01055                 $arrNewClasses  = array();
01056                 $arrOldInterface = array();
01057                 $arrNewInterface = array();
01058 
01059                 $this->codeInstrumentationClass( "class " , $arrOldClasses , $arrNewClasses, $arrLines );
01060                 $this->codeInstrumentationClass( "interface " , $arrOldInterface , $arrNewInterface, $arrLines );
01061 
01062                 $strContentFile = implode( "\n" , $arrLines );
01063 
01064                 $this->preloadFile( $strFileName , $strContentFile );
01065 
01066                 foreach( $arrNewClasses as $intKey => $strNewClassName )
01067                 {
01068                         $oReflectionCode = new CodeInstrumentationClass( $strNewClassName , $strContentFile );
01069                         $oReflectionCode->setClassName( $arrOldClasses[ $intKey ] );
01070                         $strNewCode = $oReflectionCode->getCode();
01071                         if( self::RUN_IN_FILES )
01072                         {
01073                                 $strFileName = trim( $strNewClassName ) . "(1).phps";
01074                 $this->checkPermissionToWrite( $strFileName );
01075                 file_put_contents( $strFileName , '<?' . 'php ' .  $strNewCode );
01076                                 require_once( $strFileName );
01077                                 if( self::REMOVE_FILES )
01078                                 {
01079                                         unlink( $strFileName );
01080                                 }
01081                         }
01082                         else
01083                         {
01084                                 eval( $strNewCode );
01085                         }
01086                 }
01087                 foreach( $arrNewInterface as $intKey => $strNewInterfaceName )
01088                 {
01089                         $strOldInterface = $arrOldInterface[ $intKey ];
01091                         $strNewCode = "interface $strOldInterface {} ";
01092                         if( self::RUN_IN_FILES )
01093                         {
01094                                 $strFileName = trim( $strNewInterfaceName ) . "(1).phps";
01095                 $this->checkPermissionToWrite( $strFileName );
01096                                 file_put_contents( $strFileName , '<?' . 'php ' .  $strNewCode );
01097                                 require_once( $strFileName );
01098                                 if( self::REMOVE_FILES )
01099                                 {
01100                                         unlink( $strFileName );
01101                                 }
01102                         }
01103                         else
01104                         {
01105                                 eval( $strNewCode );
01106                         }
01107                 }
01108         }

codeInstrumentationLine ( strLine,
strTextSearch 
)

Implement the code instrumentation into a code line

Parameters:
string $strLine
string $strTextSearch
Returns:
array

Definition at line 968 of file CodeToDiagram.class.php.

Referenced by codeInstrumentationClass().

00969         {
00970                 $arrResult = array();
00971 
00972                 if(  substr( strtolower( trim( $strLine ) ) , 0 , strlen( $strTextSearch ) ) == $strTextSearch )
00973                 {
00974                         $strLine = trim( $strLine );
00975                         $strBefore = substr( $strLine , 0 , strlen( $strTextSearch ) );
00976                         $strAfter = substr( $strLine , strlen( $strTextSearch ) );
00977                         $arrWords = explode( " " , $strAfter );
00978 
00979                         $strOldClassName = $arrWords[0];
00980                         $strNewClassName = self::CODE_TO_DIAGRAM_CLASS_PREFIX . $strOldClassName;
00981 
00982                         $arrWords[0] = $strNewClassName;
00983                         $strAfter = implode( " " , $arrWords );
00984                         $strLine = $strBefore . $strAfter;
00985 
00986                         $arrResult[ "line" ] = $strLine;
00987                         $arrResult[ "class_old" ] = $strOldClassName;
00988                         $arrResult[ "class_new" ] = $strNewClassName;
00989 
00990                 }
00991                 return $arrResult;
00992         }

CodeToDiagramExit ( strFileFrom = '',
strMessage = '' 
)

Method what will be called in replace of the original exit function

Parameters:
string $strFileFrom
string $strMessage
Returns:
CodeToDiagram

Definition at line 915 of file CodeToDiagram.class.php.

References print.

00916         {
00917                 print "Exit called into $strFileFrom ($strMessage ) ";
00918         }

CodeToDiagramInclude ( strFileFrom,
strFile 
)

Method what will be called in replace of the original include function

Parameters:
string $strFileFrom
string $strFile
Returns:
CodeToDiagram

Definition at line 901 of file CodeToDiagram.class.php.

References $strFile, $strFileFrom, and loadFile().

00902         {
00903                 $this->loadFile( $strFileFrom , $strFile );
00904                 return $this;
00905         }

CodeToDiagramIncludeOnce ( strFileFrom,
strFile 
)

Method what will be called in replace of the original include_once function

Parameters:
string $strFileFrom
string $strFile
Returns:
CodeToDiagram

Definition at line 870 of file CodeToDiagram.class.php.

References $strFile, $strFileFrom, and hasFile().

00871         {
00872                 if( !$this->hasFile( $strFileFrom , $strFile ) )
00873                 {
00874                         $this->CodeToDiagramIncludeOnce( $strFileFrom , $strFile );
00875                 }
00876                 return $this;
00877         }

CodeToDiagramRequire ( strFileFrom,
strFile 
)

Method what will be called in replace of the original require function

Parameters:
string $strFileFrom
string $strFile
Returns:
CodeToDiagram

Definition at line 887 of file CodeToDiagram.class.php.

References $strFile, $strFileFrom, and loadFile().

Referenced by CodeToDiagramRequireOnce().

00888         {
00889                 $this->loadFile( $strFileFrom , $strFile );
00890                 return $this;
00891         }

CodeToDiagramRequireOnce ( strFileFrom,
strFile 
)

Method what will be called in replace of the original require_once function

Parameters:
string $strFileFrom
string $strFile
Returns:
CodeToDiagram

Definition at line 851 of file CodeToDiagram.class.php.

References $strFile, $strFileFrom, CodeToDiagramRequire(), and hasFile().

Referenced by start().

00852         {               
00853                 $arrCodeToDiagramBackTrace = debug_backtrace();
00854 
00855                 if( !$this->hasFile( $strFileFrom , $strFile ) )
00856                 {
00857                         $this->CodeToDiagramRequire( $strFileFrom, $strFile );
00858                 }
00859                 return $this;
00860         }

convertFileContent ( strContentFile,
strFile,
strFullFile 
) [protected]

Replace the php function with the CodeToDiagram function

Parameters:
string $strContentFile
string $strFile
string $strFullFile
Returns:
string

Definition at line 928 of file CodeToDiagram.class.php.

References $strFile, getCallerPath(), getInstance(), and getStarted().

Referenced by loadFile().

00929         {
00930                 if( self::getInstance()->getStarted() == false )
00931                 {
00932                         self::getInstance()->setStarted( true );
00933                         $strContentFile = preg_replace('/require_once/', '//require_once', $strContentFile, 1);
00934                 }
00935 
00936                 $strContentFile = str_replace(
00937                         Array(
00938                                 'require_once(' ,
00939                                 'require(' ,
00940                                 'include(' ,
00941                                 'include_once(',
00942                                 'exit()',
00943                                 'exit(',
00944                                 '__FILE__',
00945                         ),
00946                         Array(
00947                                 'CodeToDiagram::getInstance()->CodeToDiagramRequireOnce("'. $strFile . '",' ,
00948                                 'CodeToDiagram::getInstance()->CodeToDiagramRequire("'. $strFile . '",' ,
00949                                 'CodeToDiagram::getInstance()->CodeToDiagramInclude("'. $strFile . '",' ,
00950                                 'CodeToDiagram::getInstance()->CodeToDiagramIncludeOnce("'. $strFile . '",',
00951                                 'CodeToDiagram::getInstance()->CodeToDiagramExit("'. $strFile . '")',
00952                                 'CodeToDiagram::getInstance()->CodeToDiagramExit("'. $strFile . '",',
00953                                 '"' . $this->getCallerPath() . $strFullFile . '"',
00954                         ),
00955                         $strContentFile
00956                 );
00957 
00958                 return $strContentFile;
00959         }

fixFileName ( strFileFrom,
strFile 
) [protected]

Make the link reference possible

Parameters:
string $strFileFrom
string $strFile
Returns:
string

Definition at line 805 of file CodeToDiagram.class.php.

References $strFile, and $strFileFrom.

Referenced by addFile(), and loadFile().

00806         {
00807                 $strFileFrom = str_replace( '/', '\\', $strFileFrom );
00808                 $strFile = str_replace( '/', '\\', $strFile );
00809                 $strFilePath = substr( $strFileFrom ,  0 , -(strlen(basename($strFileFrom ) ) ) );
00810                 $strFile = $strFilePath . $strFile;
00811 
00812                 return $strFile;
00813         }

getCallerPath (  ) 

Get the caller path

Returns:
string

Definition at line 583 of file CodeToDiagram.class.php.

Referenced by convertFileContent(), and save().

00584         {
00585                 return $this->strCallerPath;
00586         }

getConfiguration (  ) 

Get if the configuration of the factory

See also:
CodeInstrumentationReceiver::getConfiguration()
Returns:
CodeInstrumentationReceiverConfiguration

Definition at line 199 of file CodeToDiagram.class.php.

References getInstance().

00200         {
00201                 return CodeInstrumentationReceiver::getInstance()->getConfiguration();
00202         }

getExternalAcess (  ) 

Get if the acess it is as a external call

See also:
CodeToDiagram::setExternalAcess( boolean )

CodeToDiagram->boolExternalAccess

Returns:
boolean

Definition at line 419 of file CodeToDiagram.class.php.

Referenced by save().

00420         {
00421                 return $this->booExternalAccess;
00422         }

getFileFrom (  ) 

Get the file what the execution start from.

Example:
 \1 
returns
 true 
.... $this->setFileFrom( __FILE__ )->getFileFrom() == __FILE__
Returns:
string

Definition at line 531 of file CodeToDiagram.class.php.

Referenced by start().

00532         {
00533                 return $this->strFileFrom;
00534         }

getFileName (  ) 

Get the file name of the actual file in code instrumentation

Example:
 \1 
returns
 true 
.... $this->setFileName( "index.php" )->getFileName() == "index.php"
Returns:
string

Definition at line 561 of file CodeToDiagram.class.php.

Referenced by save().

00562         {
00563                 return $this->strFileName;
00564         }

static getInstance (  )  [static]

Get a singleton instance of the class

Example:
 \1 
returns
 true 
.... get_class( self::getInstance() ) == "CodeToDiagram"
Returns:
CodeToDiagram

Definition at line 454 of file CodeToDiagram.class.php.

Referenced by History::__construct(), addNote(), convertFileContent(), getConfiguration(), init(), restart(), save(), and start().

00455         {
00456                 if( self::$objInstance === null )
00457                 {
00458                         self::$objInstance = new CodeToDiagram();
00459                 }
00460                 return self::$objInstance;
00461         }

getOutputType (  ) 

Get the output type of the diagram

Example:
 \1 
returns
 true 
.... $this->setOutputType( CodeToDiagram::OUTPUT_TYPE_SCREEN )->getOutputType() == CodeToDiagram::OUTPUT_TYPE_SCREEN
Example:
 \1 
returns
 true 
.... $this->setOutputType( CodeToDiagram::OUTPUT_TYPE_FILE )->getOutputType() == CodeToDiagram::OUTPUT_TYPE_FILE
Example:
 \1 
returns
 true 
.... $this->setOutputType( CodeToDiagram::OUTPUT_TYPE_STRING )->getOutputType() == CodeToDiagram::OUTPUT_TYPE_STRING
Example:
 \1 
returns
 true 
.... $this->setOutputType( "something" ) throws CodeToDiagramException
Returns:
string

Definition at line 322 of file CodeToDiagram.class.php.

Referenced by save().

00323         {
00324                 return $this->strOutputType;
00325         }

getPrinter (  ) 

Get the printer of the code to diagram

Returns:
UmlSequenceDiagramPrinterInterface

Definition at line 221 of file CodeToDiagram.class.php.

Referenced by getPrinterConfiguration(), and setPrinterConfiguration().

00222     {
00223         return $this->objPrinter;
00224     }

getPrinterConfiguration (  ) 

Get the printer configuration

Returns:
UmlSequenceDiagramPrinterConfigurationInterface

Definition at line 248 of file CodeToDiagram.class.php.

References getPrinter().

Referenced by setPrinterConfiguration().

00249     {
00250         return $this->getPrinter()->getConfiguration();
00251     }

getPrinterType (  ) 

Get the printer type of the diagram

Example:
returns
 true 
Example:
returns
 true 
Example:
 <code>
          $this->setPrinterType( "something" ) throws CodeToDiagramException
 </code> 
returns
 true 
Returns:
string

Definition at line 393 of file CodeToDiagram.class.php.

Referenced by __construct(), and save().

00394         {
00395                 return $this->strPrinterType;
00396         }

getPublicPath (  ) 

Get the public path

Returns:
string

Definition at line 605 of file CodeToDiagram.class.php.

Referenced by checkPermissionToWrite(), and save().

00606         {
00607                 return $this->strPublicPath;    
00608         }

getStarted (  ) 

Get if the diagram creation has started

Example:
 \1 
returns
 true 
.... $this->setStarted( true )->getStarted() == true
Example:
 \1 
returns
 true 
.... $this->setStarted( false )->getStarted() == false
Assert:
() == false
Returns:
boolean

Definition at line 498 of file CodeToDiagram.class.php.

Referenced by convertFileContent(), init(), save(), and start().

00499         {
00500                 return $this->booStart;
00501         }

hasFile ( strFileFrom,
strFile 
) [protected]

Check if the file already was loaded

Parameters:
string $strFileFrom
string $strFile
Returns:
boolean

Definition at line 838 of file CodeToDiagram.class.php.

References $strFile.

Referenced by CodeToDiagramIncludeOnce(), and CodeToDiagramRequireOnce().

00839         {
00840                 return in_array( $strFile ,  $this->arrFiles );
00841         }

static hasInstance (  )  [static]

Returns if the element has a instance

Example:
 \1 
returns
 true 
.... self::hasInstance() == false;
Example:
 \1 
returns
 true 
.... self::getInstance(); self::hasInstance() == true
Returns:
boolean

Definition at line 439 of file CodeToDiagram.class.php.

00440         {
00441                 return ( self::$objInstance !== null );
00442         }

static init ( strFile  )  [static]

Init the code to diagram

Parameters:
string $strFile
Returns:
CodeToDiagram

Definition at line 788 of file CodeToDiagram.class.php.

References $strFile, getInstance(), and getStarted().

00789         {
00790                 if( self::getInstance()->getStarted() == false )
00791                 {
00792                         self::getInstance()->setFileFrom( $strFile );
00793                 }
00794                 return self::getInstance();
00795         }

loadDefaultsStereotypes (  )  [protected]

Load the default stereotype list

Definition at line 182 of file CodeToDiagram.class.php.

References UmlSequenceDiagramStereotype::addStereotype().

Referenced by __construct().

00183     {
00184         foreach( self::$arrDefaultStereotypes as $strDefaultStereotype )
00185         {
00186             $objStereotype = new UmlSequenceDiagramStereotype();
00187             $objStereotype->setName( $strDefaultStereotype  )->setDefault( true );
00188             UmlSequenceDiagramStereotype::addStereotype( $objStereotype );
00189         }
00190 
00191     }

loadFile ( strFileFrom,
strFile 
) [protected]

Load some file implement the code instrumentation

Parameters:
string $strFileFrom
string $strFile
Returns:
CodeToDiagram

Definition at line 1117 of file CodeToDiagram.class.php.

References $strFile, $strFileFrom, addFile(), codeInstrumentationFile(), convertFileContent(), fixFileName(), and CorujaFileManipulation::isRelativePath().

Referenced by CodeToDiagramInclude(), and CodeToDiagramRequire().

01118         {
01119                 if( basename( $strFile ) == 'CodeToDiagram.class.php' )
01120                 {
01121                         return $this;
01122                 }
01123                 $this->addFile( $strFileFrom, $strFile );
01124 
01125                 if( CorujaFileManipulation::isRelativePath( $strFile ) )
01126                 {
01127                         $strFullFile = $this->fixFileName( $strFileFrom, $strFile );
01128                 }
01129                 else
01130                 {
01131                         $strFullFile = $strFile;
01132                 }
01133 
01134                 if( ! file_exists( $strFullFile ) )
01135                 {
01136                         throw new CodeToDiagramException( "Unable to find file: " . $strFullFile );
01137                 }
01138 
01139                 $strContentFile = file_get_contents( $strFullFile );
01140                 $strContentFile = $this->convertFileContent( $strContentFile , $strFile , $strFullFile );
01141                 $this->codeInstrumentationFile( $strFile, $strContentFile );
01142                 
01143                 return $this;
01144         }

preloadFile ( strFileName,
strContentFile 
) [protected]

Pre load the file into is's context

Parameters:
string $strFileName
string $strContentFile
Returns:
CodeToDiagram

Definition at line 1024 of file CodeToDiagram.class.php.

References $strFileName, checkPermissionToWrite(), and print.

Referenced by codeInstrumentationFile().

01025         {
01026                 if( self::RUN_IN_FILES )
01027                 {
01028                         $strFileName = $strFileName . "(0).phps";
01029             print $strFileName;
01030             $this->checkPermissionToWrite( $strFileName );
01031                         file_put_contents( $strFileName , $strContentFile );
01032                         require_once( $strFileName );
01033                         if( self::REMOVE_FILES )
01034                         {
01035                                 unlink( $strFileName );
01036                         }
01037                 }
01038                 else
01039                 {
01040                         eval( '?' . '>' . $strContentFile );
01041                 }
01042                 return $this;
01043         }

restart (  ) 

Restart the informations inside the code instrumentation receiver

Assert:
()
Returns:
CodeToDiagram

Definition at line 642 of file CodeToDiagram.class.php.

References getInstance().

00643         {
00644                 CodeInstrumentationReceiver::getInstance()->restart();
00645                 return $this;
00646         }

save (  ) 

Save the actual information from the code instrumentation into the selected output.

Example:
 \1 
returns
 true 
.... CodeToDiagram::getInstance()->restart(); // output will be a file // CodeToDiagram::getInstance()->setOutputType( 'file' ); // name of the new file // CodeToDiagram::getInstance()->setFileName( 'myFile.html' ); # this code will be saved { $objWolf = new Wolf(); $objWolf->say( "i will be back " . date( "h:i:s") ); CodeToDiagram::getInstance()->save(); # } into the new file
Returns:
string

Definition at line 708 of file CodeToDiagram.class.php.

References $objPrinter, $strContent, checkPermissionToWrite(), getCallerPath(), getExternalAcess(), getFileName(), getInstance(), getOutputType(), getPrinterType(), getPublicPath(), getStarted(), and print.

Referenced by __destruct().

00709         {
00710                 $strReturn = "";
00711                 $strDiagram = "";
00712                 
00713                 if( $this->getStarted() )
00714                 {
00715             $strContent = ob_get_contents();
00716             ob_end_clean();
00717                         $objUmlSequenceDiagram = CodeInstrumentationReceiver::getInstance()->getUmlSequenceDiagram();
00718             $objUmlSequenceDiagram->setOutput( $strContent );
00719 
00720                         switch( $this->getPrinterType() )
00721                         {
00722                                 case self::PRINTER_TYPE_HTML:
00723                                 {
00724                                         $objPrinter = UmlSequenceDiagramPrinterToHtml::getInstance();
00725                     UmlSequenceDiagramPrinterToHtml::getInstance()->getConfiguration()->setPublicPath( $this->getPublicPath() );
00726                                         UmlSequenceDiagramPrinterToHtml::getInstance()->getConfiguration()->setCallerPath( $this->getCallerPath() );
00727                                         UmlSequenceDiagramPrinterToHtml::getInstance()->getConfiguration()->setExternalAccess( $this->getExternalAcess() );
00728                                         $strDiagram = UmlSequenceDiagramPrinterToHtml::getInstance()->perform( $objUmlSequenceDiagram );
00729                                         break;
00730                                 }
00731                                 case self::PRINTER_TYPE_XML:
00732                                 {
00733                                         $objPrinter = UmlSequenceDiagramPrinterToXml::getInstance();
00734                                         $strDiagram = UmlSequenceDiagramPrinterToXml::getInstance()->perform( $objUmlSequenceDiagram );
00735                                         break;
00736                                 }
00737                                 default:
00738                                 {
00739                                         throw new CodeToDiagramException( "Invalid printer type ({$this->getPrinterType()})" );
00740                                         break;
00741                                 }
00742                         }
00743                         switch( $this->getOutputType() )
00744                         {
00745                                 case self::OUTPUT_TYPE_SCREEN:
00746                                 {
00747                                         $objPrinter->getHeader();
00748                                         print $strDiagram;
00749                                         break;
00750                                 }
00751                                 case self::OUTPUT_TYPE_STRING:
00752                                 {
00753                                         $strReturn = $strDiagram;
00754                                         break;
00755                                 }
00756                                 case self::OUTPUT_TYPE_FILE:
00757                                 {
00758                     $this->checkPermissionToWrite( $this->getFileName() );
00759                                         file_put_contents( $this->getFileName() , $strDiagram );
00760                                         $strReturn = $strDiagram;
00761                                         break;
00762                                 }
00763                                 default:
00764                                 {
00765                                         throw new CodeToDiagramException( "Invalid output type ({$this->getOutputType()})" );
00766                                         break;
00767                                 }
00768                         }
00769                         CodeInstrumentationReceiver::getInstance()->restart();
00770                 }
00771                 return $strReturn;
00772         }

setCallerPath ( strCallerPath  ) 

Set the caller path

Parameters:
string $strCallerPath
Returns:
CodeToDiagram me

Definition at line 572 of file CodeToDiagram.class.php.

References $strCallerPath.

Referenced by setCallerPathByFile().

00573         {
00574                 $this->strCallerPath = $strCallerPath;
00575                 return $this;
00576         }

setCallerPathByFile ( strCallerFile  ) 

Set the caller path receiving the caller file

Parameters:
string $strCallerFile

Definition at line 1151 of file CodeToDiagram.class.php.

References CorujaFileManipulation::getPathOfFile(), and setCallerPath().

01152         {
01153                 $this->setCallerPath( CorujaFileManipulation::getPathOfFile( $strCallerFile ) );
01154         }

setExternalAcess ( booExternalAccess  ) 

Set if the acess it is as a external call

See also:
CodeToDiagram::getExternalAcess()

CodeToDiagram->boolExternalAccess

Parameters:
boolean $booExternalAccess
Returns:
CodeToDiagram me

Definition at line 406 of file CodeToDiagram.class.php.

References $booExternalAccess.

00407         {
00408                 $this->booExternalAccess = (boolean)$booExternalAccess;
00409                 return $this;
00410         }

setFileFrom ( strFileFrom  ) 

Set the file what the execution start from. This should be edit with very care

Example:
 \1 
returns
 true 
.... $this->setFileFrom( __FILE__ )->getFileFrom() == __FILE__
Assert:
( __FILE__ );
Parameters:
string $strFileFrom
Returns:
CodeToDiagram

Definition at line 515 of file CodeToDiagram.class.php.

References $strFileFrom.

00516         {
00517                 $this->strFileFrom = $strFileFrom;
00518                 return $this;
00519         }

setFileName ( strFileName  ) 

Set the actual file in code instrumentation

Example:
 \1 
returns
 true 
.... $this->setFileName( "index.php" )->getFileName() == "index.php"
Parameters:
string $strFileName
Returns:
CodeToDiagram

Definition at line 546 of file CodeToDiagram.class.php.

References $strFileName.

00547         {
00548                 $this->strFileName = $strFileName;
00549                 return $this;
00550         }

setOutputType ( strType  ) 

Set the output type of the diagram.;

The output type it is how the class should deal with the result of the printer

Example:
 \1 
returns
 true 
.... $this->setOutputType( CodeToDiagram::OUTPUT_TYPE_SCREEN )->getOutputType() == CodeToDiagram::OUTPUT_TYPE_SCREEN
Example:
 \1 
returns
 true 
.... $this->setOutputType( CodeToDiagram::OUTPUT_TYPE_FILE )->getOutputType() == CodeToDiagram::OUTPUT_TYPE_FILE
Example:
 \1 
returns
 true 
.... $this->setOutputType( CodeToDiagram::OUTPUT_TYPE_STRING )->getOutputType() == CodeToDiagram::OUTPUT_TYPE_STRING
Example:
 \1 
returns
 true 
.... $this->setOutputType( "something" ) throws CodeToDiagramException
Assert:
( CodeToDiagram::OUTPUT_TYPE_SCREEN )
Assert:
( CodeToDiagram::OUTPUT_TYPE_FILE )
Assert:
( CodeToDiagram::OUTPUT_TYPE_STRING )
Assert:
( "somethingElse" ) throws CodeToDiagramException
Parameters:
string $strType

Definition at line 280 of file CodeToDiagram.class.php.

References OUTPUT_TYPE_FILE, OUTPUT_TYPE_SCREEN, and OUTPUT_TYPE_STRING.

00281         {
00282                 switch( $strType )
00283                 {
00284                         case CodeToDiagram::OUTPUT_TYPE_SCREEN:
00285                         case CodeToDiagram::OUTPUT_TYPE_STRING:
00286                         case CodeToDiagram::OUTPUT_TYPE_FILE :
00287                         {
00288                                 $this->strOutputType = $strType;
00289                                 break;
00290                         }
00291                         default:
00292                         {
00293                                 throw new CodeToDiagramException( "Invalid output type. ('" . $strType . "')" );
00294                                 break;
00295                         }
00296                 }
00297                 return $this;
00298         }

setPrinter ( UmlSequenceDiagramPrinterInterface objPrinter  ) 

Set the printer of the code to diagram

Parameters:
UmlSequenceDiagramPrinterInterface $objPrinter
Returns:
CodeToDiagram me

Definition at line 210 of file CodeToDiagram.class.php.

Referenced by setPrinterType().

00211     {
00212         $this->objPrinter = $objPrinter;
00213         return $this;
00214     }

setPrinterConfiguration ( UmlSequenceDiagramPrinterConfigurationInterface objPrinterConfiguration  ) 

Set the printer configuration

Parameters:
UmlSequenceDiagramPrinterConfigurationInterface $objPrinterConfiguration
Returns:
CodeToDiagram me
Exceptions:
CodeToDiagramException 

Definition at line 233 of file CodeToDiagram.class.php.

References getPrinter(), and getPrinterConfiguration().

00234     {
00235         if( get_class( $objPrinterConfiguration ) != get_class( $this->getPrinterConfiguration() ) )
00236         {
00237             throw new CodeToDiagramException( "Invalid Printer Configuration" );
00238         }
00239         $this->getPrinter()->setConfiguration( $objPrinterConfiguration );
00240         return $this;
00241     }

setPrinterType ( strType  ) 

Set the printer type of the diagram.

Set the printer what will deal with the UmlSequenceDiagram Object

Example:
returns
 true 
Example:
returns
 true 
Example:
 <code>
          $this->setPrinterType( "something" ) throws CodeToDiagramException
 </code> 
returns
 true 
Assert:
( CodeToDiagram::PRINTER_TYPE_HTML )
Assert:
( CodeToDiagram::PRINTER_TYPE_XML )
Assert:
( "somethingElse" ) throws CodeToDiagramException
Parameters:
string $strType

Definition at line 350 of file CodeToDiagram.class.php.

References UmlSequenceDiagramPrinterToXml::getInstance(), UmlSequenceDiagramPrinterToHtml::getInstance(), PRINTER_TYPE_HTML, PRINTER_TYPE_XML, and setPrinter().

Referenced by __construct().

00351         {
00352                 switch( $strType )
00353                 {
00354                         case CodeToDiagram::PRINTER_TYPE_HTML:
00355             {
00356                 $this->setPrinter( UmlSequenceDiagramPrinterToHtml::getInstance() );
00357                                 $this->strPrinterType = $strType;
00358                                 break;
00359             }
00360                         case CodeToDiagram::PRINTER_TYPE_XML:
00361                         {
00362                 $this->setPrinter( UmlSequenceDiagramPrinterToXml::getInstance() );
00363                                 $this->strPrinterType = $strType;
00364                                 break;
00365                         }
00366                         default:
00367                         {
00368                                 throw new CodeToDiagramException( "Invalid printer type. ('" . $strType . "')" );
00369                                 break;
00370                         }
00371                 }
00372                 return $this;
00373         }

setPublicPath ( strPublicPath  ) 

Set the public path

Parameters:
string $strPublicPath
Returns:
CodeToDiagram me

Definition at line 594 of file CodeToDiagram.class.php.

References $strPublicPath.

00595         {
00596                 $this->strPublicPath = $strPublicPath;
00597                 return $this;
00598         }

setStarted ( booStarted  ) 

Set if the diagram creation has started

Example:
 \1 
returns
 true 
.... $this->setStarted( true )->getStarted() == true
Example:
 \1 
returns
 true 
.... $this->setStarted( false )->getStarted() == false
Assert:
( true )
Assert:
( false )
Parameters:
bool $booStarted
Returns:
CodeToDiagram

Definition at line 479 of file CodeToDiagram.class.php.

00480         {
00481                 $this->booStart = $booStarted;
00482                 return $this;
00483         }

start (  ) 

Start the log of the execution and restart if already have

Assert:
()
Returns:
CodeToDiagram

Definition at line 617 of file CodeToDiagram.class.php.

References CodeToDiagramRequireOnce(), getFileFrom(), getInstance(), and getStarted().

00618         {
00619                 ob_start();
00620                 if( $this->getStarted() )
00621                 {
00622                         return $this;
00623                 }
00624                 else
00625                 {
00626                         CodeInstrumentationReceiver::getInstance()->restart();
00627                         $this->CodeToDiagramRequireOnce($this->getFileFrom() , $this->getFileFrom() );
00628                         exit();
00629 
00630                         // just to safety //
00631                         return $this;
00632                 }
00633         }


Member Data Documentation

$arrDefaultStereotypes = array( 'user' , 'system' , 'user' , 'entity' , 'controller' , 'boundary' , 'database') [static, protected]

array with the name of the default stereotypes

string[]

Definition at line 165 of file CodeToDiagram.class.php.

$arrFiles = array() [protected]

Array of files already load

string[]

Definition at line 21 of file CodeToDiagram.class.php.

$booExternalAccess = false [protected]

Controls if the access it is been maded by a external link call

boolean

Default: false

Definition at line 87 of file CodeToDiagram.class.php.

Referenced by setExternalAcess().

$booStart = false [protected]

Flag of control if is the first load

boolean

Definition at line 28 of file CodeToDiagram.class.php.

$objInstance [static, protected]

Singleton of this class

CodeToDiagram

Definition at line 93 of file CodeToDiagram.class.php.

$objPrinter [protected]

Printer of the diagram

UmlSequenceDiagramPrinterInterface

Definition at line 65 of file CodeToDiagram.class.php.

Referenced by save().

$strCallerPath [protected]

Caller Path of the execution

string

Definition at line 72 of file CodeToDiagram.class.php.

Referenced by setCallerPath().

$strFileFrom = null [protected]

$strFileName = "diagram.html" [protected]

File of actual load

string

Definition at line 42 of file CodeToDiagram.class.php.

Referenced by checkPermissionToWrite(), codeInstrumentationFile(), preloadFile(), and setFileName().

$strOutputType = self::OUTPUT_TYPE_SCREEN [protected]

Diagram output type

Default: CodeToDiagram::::OUTPUT_TYPE_SCREEN
string

Definition at line 50 of file CodeToDiagram.class.php.

$strPrinterType = self::PRINTER_TYPE_HTML [protected]

Diagram printer type

Default: CodeToDiagram::::PRINTER_TYPE_HTML
string

Definition at line 58 of file CodeToDiagram.class.php.

$strPublicPath [protected]

Public Path of the project

string

Definition at line 79 of file CodeToDiagram.class.php.

Referenced by setPublicPath().

Prefix of the code instrumentation classes of the code to diagram

Definition at line 117 of file CodeToDiagram.class.php.

const MSG_NO_WRITE_PERMISSION = " The user of the system does not have permission to write the code to diagram files. Change the RUN_IN_FILES to false and save your files into a allowed folder."

Definition at line 158 of file CodeToDiagram.class.php.

const OUTPUT_TYPE_FILE = "file"

The CodeToDiagram don't print anything into screen and save into a file the string generetad by the printer

Ouputput type file

Definition at line 134 of file CodeToDiagram.class.php.

Referenced by setOutputType().

const OUTPUT_TYPE_SCREEN = "screen"

The CodeToDiagram print into screen the string generetad by the printer, returning it too

Definition at line 140 of file CodeToDiagram.class.php.

Referenced by setOutputType().

const OUTPUT_TYPE_STRING = "string"

The CodeToDiagram don't print anything into screen and returns the string generetad by the printer

Ouputput type string

Definition at line 125 of file CodeToDiagram.class.php.

Referenced by setOutputType().

const PRINTER_TYPE_HTML = "html"

Printer type html.

Convert the UmlSequenceDiagram into a html file

Definition at line 156 of file CodeToDiagram.class.php.

Referenced by setPrinterType().

const PRINTER_TYPE_XML = "xml"

Printer type xml.

Convert the UmlSequenceDiagram into a xml file

Definition at line 148 of file CodeToDiagram.class.php.

Referenced by setPrinterType().

const REMOVE_FILES = true

If the execution happen into files the new file will be destroy just after be executed. This will prevent the existence of garbage files.

boolean

Definition at line 111 of file CodeToDiagram.class.php.

const RUN_IN_FILES = false

Should the code instrumentation run in files If not will run into a eval function

boolean

Definition at line 101 of file CodeToDiagram.class.php.


The documentation for this class was generated from the following file:

Generated on Thu Feb 3 03:55:03 2011 for CodeToDiagram by  doxygen 1.5.9