| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 3 class AkReflectionDocBlock 4 { 5 6 var $_structure = array(); 7 var $changed = false; 8 var $original=''; 9 function AkReflectionDocBlock($string) 10 { 11 $this->original = $string; 12 $this->_structure = $this->_parseDocBlock($string); 13 } 14 15 function getComment() 16 { 17 return isset($this->_structure['comment'])?$this->_structure['comment']:false; 18 } 19 function getParams() 20 { 21 return isset($this->_structure['tags']['params'])?$this->_structure['tags']['params']:false; 22 } 23 function toString() 24 { 25 $string = '/**'; 26 isset($this->_structure['comment'])?$string.="\n * ".$this->_structure['comment']."\n *":null; 27 $tags = $this->_structure['tags']; 28 $params = isset($tags['params'])?$tags['params']:array(); 29 unset($tags['_unmatched_']); 30 unset($tags['params']); 31 if (count($tags)>0) { 32 foreach ($tags as $key=>$value) { 33 $string .= "\n * @$key $value"; 34 } 35 } 36 if (count($params)>0) { 37 foreach ($params as $key=>$value) { 38 $string .= "\n * @param \$$key $value"; 39 } 40 } 41 $string.="\n */"; 42 return $string; 43 } 44 45 function setTag($tag, $value) { 46 $this->_structure['tags'][$tag] = $value; 47 $this->changed = true; 48 } 49 50 function getTag($tag) 51 { 52 return isset($this->_structure['tags'][$tag])?$this->_structure['tags'][$tag]:false; 53 } 54 function _parseDocBlock($string) 55 { 56 preg_match_all('/\/\*\*\n(\s*\*([^\n]+?\n)+)+.*?\*\//',$string,$matches); 57 $docBlockStructure = array('comment'=>null); 58 if (isset($matches[1][0])) { 59 $docPart = $matches[1][0]; 60 $docPart = preg_replace('/\s*\*\s*/',"\n",$docPart); 61 $docPart = trim($docPart); 62 $commentLines = array(); 63 $tags = array('_unmatched_'=>array()); 64 $docLines = split("\n",$docPart); 65 $inComment = true; 66 $tempTag=array(); 67 foreach ($docLines as $line) { 68 if (preg_match('/^@([a-zA-Z0-9_]+)\s+(.+)$/',$line, $matches)) { 69 if (!empty($tempTag)) { 70 $this->_parseTag(&$tags, $tempTag); 71 } 72 $inComment = false; 73 $tempTag = array($matches[1],$matches[2]); 74 } else if ($inComment) { 75 $commentLines[] = $line; 76 } else { 77 $tempTag[1].="\n".$line; 78 } 79 } 80 if (!empty($tempTag)) { 81 $this->_parseTag(&$tags, $tempTag); 82 } 83 $docBlockStructure['comment'] = trim(implode("\n",$commentLines)); 84 $docBlockStructure['tags'] = $tags; 85 } 86 return $docBlockStructure; 87 } 88 89 function _parseTag(&$tags, $tempTag) 90 { 91 switch($tempTag[0]) { 92 case 'param': 93 if (preg_match('/\$([a-zA-Z0-9_]+)\s*(.*?)/s',$tempTag[1],$pmatches)) { 94 95 if (!isset($tags['params'])) { 96 $tags['params'] = array(); 97 } else if (!is_array($tags['params'])) { 98 $currentValue = $tags['params']; 99 $tags['params'] = array($currentValue); 100 } 101 $tags['params'][$pmatches[1]] = trim($pmatches[2]); 102 } else { 103 104 $tags['_unmatched_'][] = array($tempTag[0],$tempTag[1]); 105 } 106 break; 107 default: 108 if(!empty($tags[$tempTag[0]])) { 109 if(!is_array($tags[$tempTag[0]])) { 110 111 $currentValue = $tags[$tempTag[0]]; 112 $tags[$tempTag[0]] = array($currentValue); 113 } 114 $tags[$tempTag[0]][]=trim($tempTag[1]); 115 } else { 116 $tags[$tempTag[0]]=trim($tempTag[1]); 117 } 118 119 } 120 } 121 } 122 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |