25 private $DEFAULT_NODE_STYLE =
'height=0.1,width=1,shape=box,style=filled,color="#49B4CF",fillcolor="#49B4CF",fontcolor=white,fontsize=14,fontname="Helvetica-Bold"';
26 private $DEFAULT_EDGE_STYLE =
'color="#49B4CF"';
30 private $_fileOk =
false;
31 private $_nodeIndex = 0;
32 private $_nodeIndexMap = array();
33 private $_writtenNodes = array();
35 private $_nodeStyle =
'';
36 private $_edgeStyle =
'';
38 private static $_logger = null;
46 public function __construct($file, $nodeStyle=
'', $edgeStyle=
'') {
48 $this->_fileOk =
false;
50 if ($nodeStyle !=
'') {
51 $this->_nodeStyle = $nodeStyle;
54 $this->_nodeStyle = $this->DEFAULT_NODE_STYLE;
56 if ($edgeStyle !=
'') {
57 $this->_edgeStyle = $edgeStyle;
60 $this->_edgeStyle = $this->DEFAULT_EDGE_STYLE;
62 if (self::$_logger == null) {
72 if (file_exists($this->_file)) {
73 $this->_fp = fopen($this->_file,
"r");
75 self::$_logger->warn(
"Can't write to file ".$this->_file.
". Another user holds the lock. Try again later.");
83 $this->_fp = fopen($this->_file,
"w");
85 if (flock ($this->_fp, LOCK_EX)) {
86 $this->_fileOk =
true;
87 fputs($this->_fp,
"digraph G {\n\n");
88 fputs($this->_fp,
" node [".$this->_nodeStyle.
"]\n");
89 fputs($this->_fp,
" edge [".$this->_edgeStyle.
"]\n\n");
100 fputs($this->_fp,
"\n}\n");
101 flock ($this->_fp, LOCK_UN);
110 if ($this->isWritten($obj)) {
113 if ($this->_fileOk) {
114 fputs($this->_fp,
' n'.$this->getIndex($obj).
' [label="'.$obj->
getDisplayValue().
'"]'.
"\n");
115 $children = $obj->getChildren(
false);
116 for($i=0; $i<sizeOf($children); $i++) {
117 fputs($this->_fp,
' n'.$this->getIndex($obj).
' -> n'.$this->getIndex($children[$i]).
"\n");
119 fputs($this->_fp,
"\n");
121 $oidStr = $obj->
getOID()->__toString();
122 $this->_writtenNodes[$oidStr] =
true;
130 private function isWritten($node) {
131 $oidStr = $node->getOID()->__toString();
132 return (isset($this->_writtenNodes[$oidStr]));
140 private function getIndex($node) {
141 $oidStr = $node->getOID()->__toString();
142 if (!isset($this->_nodeIndexMap[$oidStr])) {
143 $this->_nodeIndexMap[$oidStr] = $this->getNextIndex();
145 return $this->_nodeIndexMap[$oidStr];
152 private function getNextIndex() {
153 return $this->_nodeIndex++;
getOID()
Get the object id of the PersistentObject.
DotOutputStrategy outputs an object's content in a dot file.
__construct($file, $nodeStyle='', $edgeStyle='')
Constructor.
getDisplayValue()
Get the value of the object used for display.
OutputStrategy defines the interface for classes that write an object's content to a destination (cal...
static getLogger($name)
Get the logger with the given name.
writeObject(PersistentObject $obj)
PersistentObject defines the interface of all persistent objects.