CodeInstrumentationReceiver Class Reference

Inheritance diagram for CodeInstrumentationReceiver:

UmlSequenceDiagramFactoryInterface

List of all members.

Public Member Functions

 setConfiguration (CodeInstrumentationReceiverConfiguration $objConfiguration)
 getConfiguration ()
 __construct ()
 renameMethod ($strMethod, $strClass)
 onEnterMethod ($uid, $strClassDefinition, $strMethod, $arrArguments)
 onLeaveMethod ($uid, $strClassDefinition, $strMethod, $mixReturn)
 getUmlSequenceDiagram ()
 setUmlSequenceDiagram (UmlSequenceDiagram $objUmlSequence)
 restart ()
 perform ()
 getActualActor ()
 getActualMessage ()

Static Public Member Functions

static getInstance ()

Protected Member Functions

 shouldBeLog ($strClass, $strMethod)

Protected Attributes

 $arrStack = array()
 $arrActors = array()
 $arrClasses = array()
 $arrMessages = array()
 $objUmlSequence = null
 $objConfiguration
 $objActualMessage
 $objActualActor

Static Protected Attributes

static $objCodeInstrumentationReceiver


Detailed Description

Class create to make possible the creation of code instrumentation of executions.

It receive the messages of enter methods and leave methods, into what object, of what class and, based into this informations, create a UmlSequenceDiagram object.

The uml sequence diagram object created, can be used for many ways, since create a xml, create a diagram file, etc. as the printers avaliable of it.

Todo:
make filter methods to reduce the diagram of big executions
See also:
CodeInstrumentationMethod

CodeInstrumentationClass

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

Definition at line 22 of file CodeInstrumentationReceiver.class.php.


Constructor & Destructor Documentation

__construct (  ) 

prepare the code instrumentation receiver to start to receive the informations about the execution.

Execution Plan:
  1. create the internal objects
  2. create the uml sequence diagram object
  3. create the user actor
Returns:
null

Definition at line 113 of file CodeInstrumentationReceiver.class.php.

References $objConfiguration, and setConfiguration().

Referenced by restart().

00114     {
00115         // set the configuration file //
00116         $objConfiguration = new CodeInstrumentationReceiverConfiguration();
00117         $this->setConfiguration( $objConfiguration );
00118 
00119         // create the uml sequence diagram object //
00120         $this->objUmlSequence = new UmlSequenceDiagram();
00121 
00122         // create the user actor //     
00123         $objActorFrom = new UmlSequenceDiagramActor();
00124         $objActorFrom->setType( 'user' );
00125         $objActorFrom->setName( "user" );
00126         $objActorFrom->setId( sizeof( $this->arrActors ) + 1 );
00127         $this->arrActors[] = $objActorFrom;
00128         $this->arrStack[] = $objActorFrom;
00129         $this->objUmlSequence->addActor($objActorFrom);
00130     }


Member Function Documentation

getActualActor (  ) 

Get the actual actor

Returns:
UmlSequenceDiagramActor

Definition at line 524 of file CodeInstrumentationReceiver.class.php.

00525     {
00526         return $this->objActualActor;
00527     }

getActualMessage (  ) 

Get the actual message

Returns:
UmlSequenceDiagramMessage

Definition at line 534 of file CodeInstrumentationReceiver.class.php.

00535     {
00536         return ( $this->objActualMessage );
00537     }

getConfiguration (  ) 

Get the code instrumentation receiver configuration

Returns:
CodeInstrumentationReceiverConfiguration

Definition at line 94 of file CodeInstrumentationReceiver.class.php.

Referenced by onEnterMethod(), onLeaveMethod(), and shouldBeLog().

00095     {
00096         return $this->objConfiguration;
00097     }

static getInstance (  )  [static]

Get the code instrumentation receiver singleton

Returns:
CodeInstrumentationReceiver

Implements UmlSequenceDiagramFactoryInterface.

Definition at line 138 of file CodeInstrumentationReceiver.class.php.

00139     {
00140         if( self::$objCodeInstrumentationReceiver ==  null )
00141         {
00142             self::$objCodeInstrumentationReceiver = new CodeInstrumentationReceiver();
00143         }
00144         return self::$objCodeInstrumentationReceiver;
00145     }

getUmlSequenceDiagram (  ) 

Return the uml sequence diagram Object what the Code Instrumentation Receiver feeds

See also:
CodeInstrumentationReceiver->objUmlSequence

CodeInstrumentationReceiver::setUmlSequenceDiagram( UmlSequenceDiagram )

Returns:
UmlSequenceDiagram

Implements UmlSequenceDiagramFactoryInterface.

Definition at line 458 of file CodeInstrumentationReceiver.class.php.

Referenced by perform().

00459     {
00460         return $this->objUmlSequence;
00461     }

onEnterMethod ( uid,
strClassDefinition,
strMethod,
arrArguments 
)

Receive a message of enter into some method and append it as a uml sequence diagram message into the uml sequence diagram object, creating if necessary the uml sequence diagram actor

Execution Plan:
  1. get the name of method as the diagram standart
  2. get the namespace name
  3. get the actor what the message is bring from
  4. get the actor what the message is bring to
    1. create the actor to if he not exists
  5. create the message
    1. set the message attributes
    2. set the message values
  6. append the message
Parameters:
string $uid
string $strClassDefinition
string $strMethod
Array $arrArguments
Returns:
CodeInstrumentationReceiver me

Definition at line 254 of file CodeInstrumentationReceiver.class.php.

References CorujaClassManipulation::getClassNameFromClassDefinition(), getConfiguration(), CorujaClassManipulation::getNamespaceFromClassDefinition(), renameMethod(), and shouldBeLog().

00255     {
00256         // get the name of method as the diagram standart //
00257         $strClass               = CorujaClassManipulation::getClassNameFromClassDefinition( $strClassDefinition );
00258         $arrMethod      = explode( "::" , $strMethod );
00259         $strRealMethod  = array_pop( $arrMethod );
00260         $strMethod      = $this->renameMethod( $strRealMethod , $strClass);
00261 
00262         // get the namespace name //
00263         $strNamespace   = CorujaClassManipulation::getNamespaceFromClassDefinition( $strClassDefinition );
00264 
00265         if( ! array_key_exists( $strClass, $this->arrClasses ) )
00266         {
00267             $this->arrClasses[ $strClass ] = 0;
00268         }
00269         
00270          // apply receiver configurations
00271         if( $this->getConfiguration()->getMergeSameClassObjects() )
00272         {
00273             $uid = $strClass;
00274         }        
00275 
00276         if( ! $this->shouldBeLog( $strClass , $strRealMethod ) )
00277         {
00278                 return $this;
00279         }
00280         
00281         // get the actor what the message is bring from  //
00282         $objActorFrom = current( $this->arrStack );
00283         //$objActorFrom = $this->arrStack[0];
00284         if( $objActorFrom  === false )
00285         {
00286             return $this;
00287         }
00288 
00289         // get the actor what the message is bring to //
00290         if( ! array_key_exists( $uid , $this->arrActors ) )
00291         {
00292                 // create the actor to if he not exists //
00293             $this->arrClasses[ $strClass ]++;
00294             $objActorTo = new UmlSequenceDiagramActor();
00295             $objActorTo->setStereotype( $this->getConfiguration()->getMatchGroupStereotypes()->match( $strClass ) );
00296             $objActorTo->setClassName( $strClass );
00297 
00298             // object counter by class only make sence when has more the one
00299             // object of the same class
00300             if( $this->getConfiguration()->getMergeSameClassObjects() )
00301             {
00302                     $objActorTo->setName( $strClass );
00303             }
00304             else
00305             {
00306                     $objActorTo->setName( $strClass . '(' . $this->arrClasses[ $strClass ] . ')');
00307             }
00308             
00309             $objActorTo->setId(sizeof( $this->arrActors ) + 1  );
00310             $this->arrActors[ $uid ] = $objActorTo;
00311             $this->objUmlSequence->addActor($objActorTo);
00312         }
00313         else
00314         {
00315             $objActorTo = $this->arrActors[ $uid ];
00316         }
00317         
00318         if( !$this->getConfiguration()->getIgnoreRecursiveCalls() || ( $objActorFrom != $objActorTo ) )
00319         {
00320             // create the message //
00321             $objMessage = new UmlSequenceDiagramMessage();
00322 
00323             // set the message attributes //
00324             $objMessage->setMethod( $strRealMethod );
00325             $objMessage->setText( $strMethod );
00326             $objMessage->setActorFrom( $objActorFrom );
00327             $objMessage->setActorTo( $objActorTo );
00328             $objMessage->setType( 'call' );
00329 
00330             $objReflectedClass = new CodeReflectionClass( $strClass );
00331             $objReflectedMethod = $objReflectedClass->getMethod( $strRealMethod );
00332             $arrReflectedParameter = $objReflectedMethod->getParameters();
00333 
00334             // set the message values //
00335             foreach( $arrArguments as $intPos => $mixValue )
00336             {
00337                 $objValue = new UmlSequenceDiagramValue();
00338                 $objReflectedParameter = $arrReflectedParameter[ $intPos ];
00339                 $strName = $objReflectedParameter->getName();
00340                 $objValue->setName( $strName );
00341                 $objValue->setValue( $mixValue );
00342                 $objMessage->addValue( $objValue );
00343             }
00344             $objMessage->setTimeStart( microtime( true ) );
00345 
00346             // append the message  //
00347             $this->objUmlSequence->addMessage( $objMessage );
00348             $this->objActualMessage = $objMessage;
00349             $this->arrMessages[]        = $objMessage;
00350         }
00351         
00352         array_unshift( $this->arrStack , $objActorTo );
00353 
00354         $this->objActualActor = $objActorFrom;
00355         return $this;
00356     }

onLeaveMethod ( uid,
strClassDefinition,
strMethod,
mixReturn 
)

Receive the message of leave some method and append it message into the uml sequence diagram object

Execution Plan:
  1. get the name of method as the diagram standart
  2. get the namespace name
  3. get the actor what the message is bring from
  4. get the actor what the message is bring to
  5. create the message
    1. set the message attributes
    2. set the message values
  6. append the message
Parameters:
integer $uid
string $strClassDefinition
string $strMethod
$mixReturn 
Returns:
CodeInstrumentationReceiver me

Definition at line 384 of file CodeInstrumentationReceiver.class.php.

References CorujaClassManipulation::getClassNameFromClassDefinition(), getConfiguration(), CorujaClassManipulation::getNamespaceFromClassDefinition(), renameMethod(), and shouldBeLog().

00385     {
00386         // get the name of method as the diagram standart //
00387         $strClass               = CorujaClassManipulation::getClassNameFromClassDefinition( $strClassDefinition );
00388         $arrMethod      = explode( "::" , $strMethod );
00389         $strRealMethod  = array_pop( $arrMethod );
00390         $strMethod      = $this->renameMethod( $strRealMethod , $strClass );
00391 
00392         // get the namespace name //
00393         $strNamespace   = CorujaClassManipulation::getNamespaceFromClassDefinition( $strClassDefinition );
00394 
00395             if( ! $this->shouldBeLog( $strClass , $strRealMethod ) )
00396         {
00397                 return $this;
00398         }
00399                 
00400         // get the actor what the message is bring from //
00401         reset( $this->arrStack );
00402         $objActorFrom = array_shift( $this->arrStack );
00403         
00404         // get the actor what the message is bring to //
00405         //$objActorTo = $this->arrStack[0];
00406         $objActorTo = current( $this->arrStack );
00407 
00408         $boolCreateMessage = true;
00409 
00410         if( $mixReturn == null and $this->getConfiguration()->getIgnoreNullReturns() )
00411         {
00412             $boolCreateMessage = false;
00413         }
00414 
00415         if( ( $objActorFrom == $objActorTo ) and $this->getConfiguration()->getIgnoreRecursiveCalls() )
00416         {
00417             $boolCreateMessage = false;
00418         }
00419 
00420         if( $boolCreateMessage )
00421         {
00422                 // create the message //
00423             $objMessage = new UmlSequenceDiagramMessage();
00424             
00425             // set the message attributes //
00426             $objMessage->setMethod( $strRealMethod );
00427             $objMessage->setText( $strMethod );
00428             $objMessage->setActorFrom( $objActorFrom );
00429             $objMessage->setActorTo( $objActorTo );
00430             $objMessage->setType( 'return' );
00431 
00432             // set the message values //
00433             if( $mixReturn !== null )
00434             {
00435                 $objValue = new UmlSequenceDiagramValue();
00436                 $objValue->setName( "return" );
00437                 $objValue->setValue( $mixReturn );
00438                 $objMessage->addValue( $objValue );
00439             }
00440 
00441             // append the message  //
00442             $this->objUmlSequence->addMessage( $objMessage );
00443             $objMessage->setTimeEnd( microtime( true ) );
00444             $this->objActualMessage = $objMessage;
00445         }
00446         $this->objActualActor = $objActorTo;
00447         
00448         return $this;
00449     }

perform (  ) 

Return the UmlSequenceDiagram created by this factory

Returns:
UmlSequenceDiagram

Implements UmlSequenceDiagramFactoryInterface.

Definition at line 513 of file CodeInstrumentationReceiver.class.php.

References getUmlSequenceDiagram().

00514     {
00515         return $this->getUmlSequenceDiagram();
00516     }

renameMethod ( strMethod,
strClass 
)

Rename the method to which they are in accordance with the standarts of the diagram

Execution Plan:
  1. if __construct replace by >>create<<
  2. if __destruct replace by >>destroy<<
  3. other cases should append the "()"
Parameters:
string $strMethod old method name
Returns:
string new method name

Definition at line 162 of file CodeInstrumentationReceiver.class.php.

Referenced by onEnterMethod(), and onLeaveMethod().

00163     {
00164         switch( $strMethod )
00165         {
00166                 // 1. if __construct replace by <<create>> //
00167             case "__construct":
00168             {
00169                 $strMethod = ( "<<create>>" );
00170                 break;
00171             }
00172             // 2. if __destruct replace by <<destroy>> //
00173             case "__destruct":
00174             {
00175                 $strMethod = ( "<<destroy>>" );
00176                 break;
00177             }
00178             // 3. other cases should append the "()" //
00179             default:
00180             {
00181                 $objReflectedClass = new CodeReflectionClass( $strClass );
00182                 $objReflectedMethod = $objReflectedClass->getMethod( $strMethod );
00183                 $arrReflectedParameter = $objReflectedMethod->getParameters();
00184                 $arrParams = array();
00185                 foreach( $arrReflectedParameter as $objReflectedParameter )
00186                 {
00187                     $arrParams[] = $objReflectedParameter->getCode();
00188                 }
00189                 $strMethod .= "( " . implode( " , " , $arrParams ) . " )";
00190                 break;
00191             }
00192         }
00193         return $strMethod;
00194     }

restart (  ) 

Clean the attributes of the uml sequence diagram existing

  1. clean actors
  2. clean classes
  3. clean messages
  4. clean stack
  5. clean object uml sequence diagram
  6. restart the receiver

Returns:
CodeInstrumentationReceiver

Definition at line 491 of file CodeInstrumentationReceiver.class.php.

References __construct().

00492     {
00493         // clean actors //
00494         $this->arrActors = array();
00495         // clean classes //
00496         $this->arrClasses = array();
00497         // clean messages //
00498         $this->arrMessages = array();
00499         // clean stack //
00500         $this->arrStack = array();
00501         // clean object uml sequence diagram //
00502         $this->objUmlSequence->restart();
00503         // restart the receiver //
00504         $this->__construct();
00505         return $this;
00506     }

setConfiguration ( CodeInstrumentationReceiverConfiguration objConfiguration  ) 

Set the code instrumentation receiver configuration

Parameters:
CodeInstrumentationReceiverConfiguration $objConfiguration
Returns:
CodeInstrumentationReceiver

Definition at line 83 of file CodeInstrumentationReceiver.class.php.

Referenced by __construct().

00084     {
00085         $this->objConfiguration = $objConfiguration;
00086         return $this;
00087     }

setUmlSequenceDiagram ( UmlSequenceDiagram objUmlSequence  ) 

Set the uml sequence diagram Object what the Code Instrumentation Receiver feeds

Parameters:
UmlSequenceDiagram 
See also:
CodeInstrumentationReceiver->objUmlSequence

CodeInstrumentationReceiver::getUmlSequenceDiagram()

Returns:
CodeInstrumentationReceiver me

Implements UmlSequenceDiagramFactoryInterface.

Definition at line 471 of file CodeInstrumentationReceiver.class.php.

00472     {
00473         $this->objUmlSequence = $objUmlSequence;
00474         return $this;
00475     }

shouldBeLog ( strClass,
strMethod 
) [protected]

Check if the method should be loged into the uml sequence diagram

Parameters:
String $strClass
String $strMethod
Returns:
boolean

Definition at line 203 of file CodeInstrumentationReceiver.class.php.

References getConfiguration().

Referenced by onEnterMethod(), and onLeaveMethod().

00204     {
00205         if( ! $this->getConfiguration()->getActive() )
00206         {
00207             return false;
00208         }
00209         
00210         if( $this->getConfiguration()->getGatekeeperClasses()->match( $strClass ) == false )
00211         {
00212             return false;
00213         }
00214 
00215         // returns of it is a ignored method
00216         if( $this->getConfiguration()->getGatekeeperMethods()->match( $strMethod ) == false )
00217         {
00218             return false;
00219         }
00220         
00221         return true;
00222     }


Member Data Documentation

$arrActors = array() [protected]

array with all the actors existents into the execution

UmlSequenceActor[]

Definition at line 43 of file CodeInstrumentationReceiver.class.php.

$arrClasses = array() [protected]

Array with the name of all the classes existents into the execution

String[]

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

$arrMessages = array() [protected]

Array with all the messages received into the execution

UmlSequenceMessage[]

Definition at line 57 of file CodeInstrumentationReceiver.class.php.

$arrStack = array() [protected]

stack of actors into the execution pile

UmlSequenceActor[]

Definition at line 36 of file CodeInstrumentationReceiver.class.php.

$objActualActor [protected]

Definition at line 75 of file CodeInstrumentationReceiver.class.php.

$objActualMessage [protected]

Definition at line 73 of file CodeInstrumentationReceiver.class.php.

$objCodeInstrumentationReceiver [static, protected]

$objConfiguration [protected]

Configuration of this printer

CodeInstrumentationReceiverConfiguration

Definition at line 71 of file CodeInstrumentationReceiver.class.php.

Referenced by __construct().

$objUmlSequence = null [protected]

Object of the uml sequence diagram what will be feed into the execution

UmlSequenceDiagram

Definition at line 64 of file CodeInstrumentationReceiver.class.php.


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

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