ホームページ >php教程 >php手册 >コンパクトなPHPドキュメント生成クラス

コンパクトなPHPドキュメント生成クラス

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBオリジナル
2016-06-21 09:15:471029ブラウズ

プロジェクトの開発中に、他の人が php ドキュメントの管理が不足していることに気付きました。しかし、そのドキュメントには多くの機能がありませんでした

/**
* クラス名: doc
* 説明: ドキュメント生成クラス
* その他: ソースディレクトリを設定した後、生成されるディレクトリを絶対パスで指定することができます。 モード
* 1 は調整可能です。通常のタイプ、つまりスラッシュ ** で始まり * スラッシュで終わる
* 2 は、スラッシュ * で始まり * スラッシュで終わるものはすべて、ドキュメントの一部になります
。*/
class doc
{
var $docdirname;
var $docdir;

/**
* 関数名: doc()
* 関数関数: 構築
* 入力パラメータ: なし
* 関数戻り値: 戻り値の説明
* その他の命令: 2004-10-13
*/
function doc()
{
$this->docdirname = "doc/";
}

/**
* 関数名: createDoc($root,$newdir,$mode="1",$filter=null)
* 関数: ドキュメントの作成
* 入力パラメータ: $root ----------- - -- ソースディレクトリ
$newdir ----------- ターゲットディレクトリ
$mode ------------- モード、1 は通常、2 は拡張
$filter - - ---------- フィルターディレクトリ
* 関数の戻り値: 戻り値の説明
* その他の説明: 2004-10-13
*/
function createDoc($root,$ newdir,$mode="1",$filter=null)
{
$getarr = $this->loopDir($root,$filter);
$i = 0;
$this->createFrame($newdir );
foreach($getarr as $key=>$val)
{
if($this->getPhpFiles($val))
{
$content = $this ->getContent($val);
$content = $this->getDoc($content,$mode);
$filepath = $this->setFilepath($val,$root,$newdir);
$ filedir = $this->getFileDir($ filepath);
$this->mkdirs($filedir);
$this->setDoc($filepath,$content);
$data[$i]['url '] = "$filepath";
$ data[$i]['name'] = "$val";
$i++;
}
}
if(!empty($data))
{
$this- >createMenu($newdir,$data) ;
$this->redirect($this->docdir);
}
}

/**
* 関数名: redirect($path)
* 関数関数: redirect
* 入力パラメータ: $path ---------------- リダイレクトパス
* 関数の戻り値: 戻り値の説明
*その他の指示: 2004-10-13
*/
function redirect($path)
{
echo "ドキュメントは正常に生成されました。ここをクリックして表示します";
}

/**
* 関数名:loopDir($root,$filter=null)
* 関数: ディレクトリのトラバース
* 入力パラメータ: $root ------------------- ソースディレクトリ
$filter ----------------- Filter
* 関数の戻り値: array
* その他の命令: 2004-10-13
*/
functionloopDir($root,$filter=null)
{
static $getarr=array();
$d = dir($root);
while (false !== ($entry = $d->read( )))
{
if ($entry = = "." || $entry == "..")
{
continue;
}
if($this->filter($entry,$filter))
{
if(is_dir($root.$entry))
{
$this->loopDir($d->gt;path.$entry."/");
}
else
{
$getarr[] = $d->path.$entry
}
}
}
$d->close();
Return $getarr;
}

/**
* 関数名: getPhpFiles($path)
* 関数関数: PHP ドキュメントの抽出
* 入力パラメータ: $path ---------------- ドキュメントパス
* 関数の戻り値: bool
*その他の指示: 2004-10-13
*/
function getPhpFiles($path )
{
$type = preg_replace('/ .*.(.*[^.].*)/i','\1',$path);
$type = strto lower($type);
if( $type=="php")
{
Return true;
}
else
{
Return false;
}
}

/**
* 関数名: getContent($path)
* 関数機能: ファイルの内容を読み取る
* 入力パラメータ: $path ------------------- ファイルパス
* 関数の戻り値値: 文字列
* その他の指示: 2004-10-13
*/
function getContent($path)
{
$fp = ファイル($パス);
$content = implode('',$fp);
Return $content;
}

/**
* 関数名: getDoc($content,$mode="1")
* 関数機能: php ファイル内のコメントを取得します
* 入力パラメータ: $content ------------ ドキュメントのコンテンツ
$mode --------------- モード、1は通常、2は拡張
* 関数の戻り値: string
* その他の命令: 2004-10-13
*/
function getDoc($content,$mode="1")
{
switch($mode )
{
case '1':
$pattern = '//(*)[rn].**//isU';
ブレーク;
case '2':
$pattern = '//*.** //isU';
break;
}

preg_match_all($pattern,$content,$carr);
$getarr = array();
foreach($carr[0] as $key=>$val)
{
$getarr[] = トリム($val);
}
$str = implode("

",$getarr);
$str = preg_replace('/[r]/i' ,'
',$str);
$style = $this->getStyle();
$str = $this->getTable($str);
$str = $style.$str;
Return $str;
}

/**
* 関数名: etFilepath($filepath,$oldroot,$newroot)
* 関数: 生成されたファイルへのパスを設定します
* 入力パラメータ: $filepath -------------- ソースファイルパス
$oldroot -------------- ソース ディレクトリ パス
$newroot -------------- ターゲット ディレクトリ パス
* 関数の戻り値: 文字列
*その他の説明: 2004-10-13
*/
function setFilepath($filepath,$oldroot,$newroot)
{
$oldroot = str_replace('/',"\/",$oldroot) ;
$pattern = "/".$oldroot."(.*)/iU";
$filepath = preg_replace($pattern,'\1',$filepath);
$newpath = $newroot.$this-> ;docdirname.$filepath;//echo "$newpath
";
$newpath = preg_replace('/(.*.)(.*[^.].*)/i','\1htm',$ newpath);
Return $newpath;
}

/**
* 関数名: getFileDir($path)
* 関数関数: ドキュメントディレクトリを取得
* 入力パラメータ: $path ------------- ドキュメントパス
* 関数戻り値: string
*その他の説明: 2004-10-13
*/
function getFileDir($path)
{
$getpath = preg_replace('/(.*)(/.*[^.]. *)/i','\1',$path);
Return $getpath;
}

/**
* 関数名: setDoc
* 関数の機能: 指定されたディレクトリにコメントを書き込み、ページを生成します
* 入力パラメータ: $filepath --------------- ディレクトリパス
$content -- - ------------- 記述内容
* 関数の戻り値: 戻り値の説明
* その他の説明: 説明
*/
function setDoc($filepath,$content)
{
$fp = fopen( $filepath,"w+");
flock($fp,LOCK_EX);
fwrite($fp,$content);
flock($fp, LOCK_UN);
}

/**
* 関数名: mkdirs($path)
* 関数関数: ディレクトリの作成
* 入力パラメータ: $path ------------------- パス
* 関数の戻り値:なし
*その他の説明: 2004-10-13
*/
関数mkdirs($path)
{
$adir =explode('/',$path);
$dirlist = '';
$rootdir = $adir[0];
array_shift ($adir);
foreach($adir as $key=>$val)
{
if($val!='.'&&$val!='..')
{
$dirlist .= "/".$val;
$dirpath = $ rootdir.$dirlist;
if(!file_exists($dirpath)&&!is_file($dirpath))
{
mkdir($dirpath);
chmod($dirpath,0777);
}
}
}
}

/**
* 関数名: filter($item,$arr=null)
* 関数: filter
* 入力パラメータ: $item -------------- Content
$arr ---- - ---------- Filter item
* 関数の戻り値: bool
* その他の命令: 2004-10-13
*/
関数 filter($item,$arr=null)
{
$item = strto lower($item);
$filter =explode(',',$arr);
if($ arr==null||!in_array($item,$filter))
{
Return true;
}
else
{
Return false;
}
}

/**
* 関数名: createFrame($root)
* 関数関数: フレームページ生成
* 入力パラメータ: $root --------------- ホームページ格納ディレクトリ
* 関数戻り値: str
* その他の指示: 2004-10-13
*/
function createFrame($root)
{
$str = '



無标题文档






<body><br> </body>< ;/noframes><br/> </html>';<br/> $this->docdir = $root."index.htm";<br/> $this->setDoc($this->docdir,$str);<br/> } <br/><br/> /**<br/> * 関数名: createMenu($root,$data)<br/> * 関数: メニューの生成<br/> * 入力パラメーター: $root ------------------- ページをディレクトリ<br/> $data ------------------ Content<br/> * 関数の戻り値: string<br/> * その他の命令: 2004-10-13<br/>*/<br/> function createMenu($root,$data)<br/> {<br/> $path = $root."menu.htm";<br/> $str = $this->getStyle();<br/> $ str.= "<table>";<br> foreach($data as $key=>$val)<br> {<br> $str.= "<tr><td><a href='".$val ['url']."' target='mainFrame'>".$val['name']."</a></td></tr>";<br> }<br> $str.= "</table>";<br> $this->setDoc($path,$str);<br> }<br><br> /**<br> * 関数名: getStyle()<br> * 関数 function: style<br> * 入力パラメータ: none<br> * 関数の戻り値: string<br> * その他の命令: 2004-10-13<br>*/<br> function getStyle()<br> {<br> $str = '<br> < style><br> table {<br> font-family: "Courier New","宋体";<br> border-collapse: Collapse;<br> word-break:break-all;<br> }<br> td {<br> font-family: "Courier New", "宋体";<br> font-size: 12px;<br> line-height: 22px;<br> }<br> </style>';<br> Return $str;<br> }<br><br> /**<br> * 関数名: getTable($content)<br> * 関数関数: コンテンツをテーブルに入れる<br> * 入力パラメータ: $content ------------ コンテンツ<br> * 関数の戻り値: string<br> * その他指示: 2004-10-13<br>*/<br> function getTable($ content)<br> {<br> $str = "<table width="100%" border="1" bordercolor="#dbdbdb" cellpadding="5" cellpadding="0"><br> <tr><br> <td bgcolor="#f5f5f5">".$content."</td><br> </tr><br> </table>";<br> Return $str;<br> }<br>}<br><br>// <br>$d を使用= 新しいドキュメント;<br>$filter = "adodb,smarty,cvs,templates,templates_c";<br>$d->createDoc("e:/www/kpub20/class/","e:/www/test/aaa/ ",1,$filter);<br>?><br><br> </p> <center> </center> <p style="width:100%;text-align:center;margin:10px 0"> <br> <br> </p> <p style="width:100%;text-align:center;margin:10px 0"> </p> <p class="clear"></p></div><div class="nphpQianMsg"><div class="clear"></div></div><div class="nphpQianSheng"><span>声明:</span><div>この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。</div></div></div><div class="nphpSytBox"><span>前の記事:<a class="dBlack" title="PHP の最適化に関する HOWTO" href="https://m.php.cn/ja/faq/241665.html">PHP の最適化に関する HOWTO</a></span><span>次の記事:<a class="dBlack" title="PHP の最適化に関する HOWTO" href="https://m.php.cn/ja/faq/241675.html">PHP の最適化に関する HOWTO</a></span></div><div class="nphpSytBox2"><div class="nphpZbktTitle"><h2>関連記事</h2><em><a href="https://m.php.cn/ja/article.html" class="bBlack"><i>続きを見る</i><b></b></a></em><div class="clear"></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="fluid" data-ad-layout-key="-6t+ed+2i-1n-4w" data-ad-client="ca-pub-5902227090019525" data-ad-slot="8966999616"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><ul class="nphpXgwzList"><li><b></b><a href="https://m.php.cn/ja/faq/92233.html" title="Windows7系统下Netbeans+PHPUnit搭建PHP单元测试开发环境及PHPUn" class="aBlack">Windows7系统下Netbeans+PHPUnit搭建PHP单元测试开发环境及PHPUn</a><div class="clear"></div></li><li><b></b><a href="https://m.php.cn/ja/faq/97151.html" title="程序猿ProMonkey V2.03" class="aBlack">程序猿ProMonkey V2.03</a><div class="clear"></div></li><li><b></b><a href="https://m.php.cn/ja/faq/94770.html" title="PHP Navigator" class="aBlack">PHP Navigator</a><div class="clear"></div></li><li><b></b><a href="https://m.php.cn/ja/faq/90182.html" title="php返回数组中指定的一列(php5.5.0默认函数array_column()在php" class="aBlack">php返回数组中指定的一列(php5.5.0默认函数array_column()在php</a><div class="clear"></div></li><li><b></b><a href="https://m.php.cn/ja/faq/208396.html" title="htmlentitiesとhtmlspecialcharsの違いの詳しい説明" class="aBlack">htmlentitiesとhtmlspecialcharsの違いの詳しい説明</a><div class="clear"></div></li></ul></div></div><ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5902227090019525" data-ad-slot="5027754603"></ins><script> (adsbygoogle = window.adsbygoogle || []).push({}); </script><footer><div class="footer"><div class="footertop"><img src="/static/imghwm/logo.png" alt=""><p>福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!</p></div><div class="footermid"><a href="https://m.php.cn/ja/about/us.html">私たちについて</a><a href="https://m.php.cn/ja/about/disclaimer.html">免責事項</a><a href="https://m.php.cn/ja/update/article_0_1.html">Sitemap</a></div><div class="footerbottom"><p> © php.cn All rights reserved </p></div></div></footer><script>isLogin = 0;</script><script type="text/javascript" src="/static/layui/layui.js"></script><script type="text/javascript" src="/static/js/global.js?4.9.47"></script></div><script src="https://vdse.bdstatic.com//search-video.v1.min.js"></script><link rel='stylesheet' id='_main-css' href='/static/css/viewer.min.css' type='text/css' media='all'/><script type='text/javascript' src='/static/js/viewer.min.js?1'></script><script type='text/javascript' src='/static/js/jquery-viewer.min.js'></script><script>jQuery.fn.wait = function (func, times, interval) { var _times = times || -1, //100次 _interval = interval || 20, //20毫秒每次 _self = this, _selector = this.selector, //选择器 _iIntervalID; //定时器id if( this.length ){ //如果已经获取到了,就直接执行函数 func && func.call(this); } else { _iIntervalID = setInterval(function() { if(!_times) { //是0就退出 clearInterval(_iIntervalID); } _times <= 0 || _times--; //如果是正数就 -- _self = $(_selector); //再次选择 if( _self.length ) { //判断是否取到 func && func.call(_self); clearInterval(_iIntervalID); } }, _interval); } return this; } $("table.syntaxhighlighter").wait(function() { $('table.syntaxhighlighter').append("<p class='cnblogs_code_footer'><span class='cnblogs_code_footer_icon'></span></p>"); }); $(document).on("click", ".cnblogs_code_footer",function(){ $(this).parents('table.syntaxhighlighter').css('display','inline-table');$(this).hide(); }); $('.nphpQianCont').viewer({navbar:true,title:false,toolbar:false,movable:false,viewed:function(){$('img').click(function(){$('.viewer-close').trigger('click');});}}); </script></body><!-- Matomo --><script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="https://tongji.php.cn/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '9']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script><!-- End Matomo Code --></html>