How To Use
You can use Code to Diagram in two ways:
Locally
Diagram displayed in the browser
Into the bootstrap file insert these commands:
<?php
// code to diagram { //
require_once( '../../public/codetodiagram.php' );
CodeToDiagram::getInstance()->start();
// } end code to diagram //
(...)
your code here
(...)
?>
Remember that the "../../public/codetodiagram.php" must be the valid relative path to acess your file.
With just this command you will see the diagram when you run your code.
Diagram saved to file
If you want to save the diagram result into a separated file, you can config the class CodeToDiagram like this:
<?php
// code to diagram { //
require_once( '../../public/codetodiagram.php' );
CodeToDiagram::getInstance()->setOutputType( 'file' ); // can be "file" or "screen"
CodeToDiagram::getInstance()->setFileName( 'myfile.html' ); // se the filename of diagram
CodeToDiagram::getInstance()->start();
// } end code to diagram //
(...)
your code here
(...)
?>
You can also generate a diagram of just part of a code execution
Diagram of part of an execution
<?php
// code to diagram include { //
require_once( '../../public/codetodiagram.php' );
CodeToDiagram::getInstance()->start();
// } end of the code to diagram include //
// start of regular page { //
require_once( 'Wolf.class.php' );
require_once( 'Pig.class.php' );
require_once( 'House.class.php' );
require_once( 'History.class.php' );
// start the first diagram { //
CodeToDiagram::getInstance()->restart(); // clear the diagram history //
CodeToDiagram::getInstance()->setOutputType( 'file' );
CodeToDiagram::getInstance()->setFileName( 'diagram1.html' );
$objPig = new LitllePig();
$objPig->say( "Hello there!!" );
CodeToDiagram::getInstance()->save();
// } end of the first diagram //
// start of no diagram code { //
$objPig->say( "This will be a secret" );
// } end of no diagram code //
// start of second diagram { //
CodeToDiagram::getInstance()->restart(); // clear the diagram history //
CodeToDiagram::getInstance()->setOutputType( 'file' );
CodeToDiagram::getInstance()->setFileName( 'diagram2.html' );
$objPig = new LittlePig();
$objPig->say( "This will be saved" );
CodeToDiagram::getInstance()->save();
// } end of second diagram //
// } end of regular page //
?>
Remotely
Still in development.
Should work just like the local acess, without the no need to download the code:
<?php
// code to diagram { //
require_once( 'http://code.assembla.com/codetodiagram/subversion/node/blob/_start.php' );
CodeToDiagram::getInstance()->start();
// } end code to diagram //
// regular page { //
require_once( 'Wolf.class.php' );
require_once( 'Pig.class.php' );
require_once( 'House.class.php' );
require_once( 'History.class.php' );
new History();
// } end regular page //
?>
Results
The diagram generated will be a html with javascript what describe the execution. Some style changes are under development and some new informations as show the code line of the message should be add soon.
To see some example this example page will create this diagram.
