25 const DEFAULT_NODE_STYLE =
'height=0.1,width=1,shape=box,style=filled,color="#49B4CF",fillcolor="#49B4CF",fontcolor=white,fontsize=14,fontname="Helvetica-Bold"';
30 private $fileOk =
false;
31 private $nodeIndex = 0;
32 private $nodeIndexMap = [];
33 private $writtenNodes = [];
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;
56 if ($edgeStyle !=
'') {
57 $this->edgeStyle = $edgeStyle;
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)) {
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)) {
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++;
OutputStrategy defines the interface for classes that write an object's content to a destination (cal...
getDisplayValue()
Get the value of the object used for display.
writeObject(PersistentObject $obj)
getOID()
Get the object id of the PersistentObject.
__construct($file, $nodeStyle='', $edgeStyle='')
Constructor.
static getLogger($name)
Get the logger with the given name.
PersistentObject defines the interface of all persistent objects.
LogManager is used to retrieve Logger instances.
DotOutputStrategy outputs an object's content in a dot file.