Ground Sunlight

Windowsで作る - PHPプログラミングの開発環境

ユーザ用ツール

サイト用ツール


basic-library:php-debugbar:1.16

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
basic-library:php-debugbar:1.16 [2020/03/19 16:01]
tanaka [テスト]
basic-library:php-debugbar:1.16 [2020/04/18 10:54] (現在)
y2sunlight [デバッグ出力 - php-debugbar]
行 1: 行 1:
 ====== デバッグ出力 - php-debugbar ====== ====== デバッグ出力 - php-debugbar ======
-Version 1.16+Version 1.16 ([[https://github.com/maximebf/php-debugbar/blob/master/LICENSE|MIT License]])
  
  --- //[[http://www.y2sunlight.com|y2sunlight]] 2020-03-18//  --- //[[http://www.y2sunlight.com|y2sunlight]] 2020-03-18//
行 7: 行 7:
  
 関連記事 関連記事
-  * [[basic-library:project|プロジェクトの作成 - apricot]]+  * [[basic-library:project|プロジェクトの作成 - Apricot (α版)]]
   * [[basic-library:phpdotenv:4.1|環境変数 - phpdotenv]]   * [[basic-library:phpdotenv:4.1|環境変数 - phpdotenv]]
   * [[basic-library:monolog:2.0|ログ出力 - monolog]]   * [[basic-library:monolog:2.0|ログ出力 - monolog]]
   * [[basic-library:idiorm:1.5|ORマッパー - Idiorm]]   * [[basic-library:idiorm:1.5|ORマッパー - Idiorm]]
   * [[basic-library:bladeone:3.37|テンプレートエンジン - BladeOne]]   * [[basic-library:bladeone:3.37|テンプレートエンジン - BladeOne]]
-  * [[basic-library:fast-route:1.3|リクエストルーター - fast-route]] +  * [[basic-library:fast-route:1.3|リクエストルーター - FastRoute]] 
-  * [[basic-library:whoops:2.7|エラーハンドラー - whoops]]+  * [[basic-library:league-container:3.3|DIコンテナー League/Container]] 
 +  * [[basic-library:valitron:1.4|バリデーター - Valitron]] 
 +  * [[basic-library:whoops:2.7|エラーハンドラー - Whoops]]
   * デバッグ出力 - php-debugbar   * デバッグ出力 - php-debugbar
  
-サイト +リンク 
-  * https://github.com/maximebf/php-debugbar --- php-debugbarの本家 (MIT License) +  * https://github.com/maximebf/php-debugbar --- PHP Debug Barの本家 
-  * http://phpdebugbar.com/ --- ここに説明を書く+  * http://phpdebugbar.com/docs/ --- PHP Debug Barの本家のドキュメント(英語)
  
 +テストプログラムの所在
 +<code>
 +{Project Folder}\test\
 +</code>
 +
 +----
 +
 +
 +===== php-debugbarについて =====
 +
 +エラーログと共にデバッグログ(デバッグライト)はプログラム開発では無くてはならない存在です。[[https://www.php.net/manual/ja/function.var-dump.php|var_dump()]] は変数の中身を簡単に表示してくれる Cool な関数ですが、WEBプログラムでは適当な表示先が無いのでログファイルに書かなくてはなりません。そんな時に役立つのが php-debugbar です。
 +
 +php-debugbarは、ブラウザにデバッグバーを表示し、PHPでデバッグ出力した情報を画面に綺麗に整形して表示してくれます。Whoops と同様に本当に pretty cool な存在です。whoops と php-debugbar はPHPデバッグ環境の最強バディと言ってもいいでしょう。
 +
 +DebugBarには、ブリッジコレクターと呼ばれる他のパッケージとの統合方法が提供されており、ORMの[[https://www.doctrine-project.org/|Doctrine]]や[[http://propelorm.org/|Propel]]、ログ出力の[[https://github.com/Seldaek/monolog|Monolog]]、メール送信の[[https://swiftmailer.symfony.com/|Swift Mailer]]などがその例です。また、Laravel、Zend Framework、PhalconなどのPHPフレームワークとも統合されています。DebugBarもまた、PHPのデバッグツールとしての選定に関しては異論の余地がありません。
 ===== インストール ===== ===== インストール =====
  
 <code> <code>
-D:\>cd usr\workspace3\y2sunlight\apple +composer require maximebf/debugbar
-D:\usr\workspace3\y2sunlight\apple>composer require maximebf/debugbar +
 </code> </code>
  
行 44: 行 59:
 Generating autoload files Generating autoload files
 1 package you are using is looking for funding. 1 package you are using is looking for funding.
-Use the composer fund command to find out more!+Use the `composer fundcommand to find out more!
 </code> </code>
  
 +>Note:
 +>Eclipse起動中にパッケージを取得した場合は、プロジェクト・エクスプローラー内の[プロジェクト(apricote)]を右クリックして[リフレッシュ]を選択して下さい。また、新しく取得したパッケージのインテリセンスが有効にならない場合は、プロジェクトのビルトまたはクリーン&ビルドを行ってビルドリストの更新を行って下さい。
 +
 +パッケージの取得が終わると ''composer.json'' の ''require'' に以下が追加されます。
 +
 +<code javascript composer.json>
 +{
 +    "require": {
 +        "maximebf/debugbar": "^1.16"
 +    }
 +}
 +</code>
 +
 +\\
 ===== テスト ===== ===== テスト =====
 +
 +パッケージのテストフォルダ(''test\'')に、テスト用のコード(''php-debugbar.php'')を作成し実行します。この例では、''DEBUG_MODE'' が ''true'' の場合のみ ''Debug Bar'' が有効になります。詳細はコード内のコメントを参照して下さい。
  
 <code php /test/php-debugbar.php> <code php /test/php-debugbar.php>
行 55: 行 86:
 use DebugBar\StandardDebugBar; use DebugBar\StandardDebugBar;
  
 +// デバッグモード有効
 const DEBUG_MODE = true; const DEBUG_MODE = true;
  
 +// 標準のデバッグレンダラー(StandardDebugBar)の作成
 +// (DebugBar/Resourcesフォルダーは通常、publicフォルダにコピーして使用する方が良い)
 $debugbar = new StandardDebugBar(); $debugbar = new StandardDebugBar();
 $base_url = '../vendor/maximebf/debugbar/src/DebugBar/Resources'; $base_url = '../vendor/maximebf/debugbar/src/DebugBar/Resources';
 $debugbarRenderer = $debugbar->getJavascriptRenderer($base_url); $debugbarRenderer = $debugbar->getJavascriptRenderer($base_url);
  
 +// デバッグライトはメッセージコレクターに出力する
 +// 使い方はvar_dump($var)と同じ
 $arr = ['0'=>'apple','1'=>'banana','2'=>'chery',]; $arr = ['0'=>'apple','1'=>'banana','2'=>'chery',];
 $debugbar['messages']->debug($arr); $debugbar['messages']->debug($arr);
  
 +// PSR-3 logger互換のログ出力
 $debugbar['messages']->info("info"); $debugbar['messages']->info("info");
 +$debugbar['messages']->notice("notice");
 $debugbar['messages']->warning('warning'); $debugbar['messages']->warning('warning');
 $debugbar['messages']->error('error'); $debugbar['messages']->error('error');
行 70: 行 108:
 <html> <html>
     <head>     <head>
 +        <!-- デバッグモードの場合はJSライブラリを読み込む -->
         <?php if(DEBUG_MODE) echo $debugbarRenderer->renderHead() ?>         <?php if(DEBUG_MODE) echo $debugbarRenderer->renderHead() ?>
     </head>     </head>
     <body>     <body>
         ...         ...
 +        <!-- デバッグモードの場合は、デバッグバーを表示する -->
         <?php if(DEBUG_MODE) echo $debugbarRenderer->render() ?>         <?php if(DEBUG_MODE) echo $debugbarRenderer->render() ?>
     </body>     </body>
 </html> </html>
 </code> </code>
 +
 +=== 実行結果 ===
 +
 +[{{basic-library:php-debugbar:debug-bar01.png?nolink}}]
 +
 +■ 標準のデバッグレンダラーでは以下の表示ができます
 +  * php ---PHP バージョン番号
 +  * memory --- メモリ使用量
 +  * [[http://phpdebugbar.com/docs/base-collectors.html#timedata|time]] --- 総実行時間(または任意の測定結果)
 +  * [[http://phpdebugbar.com/docs/base-collectors.html#messages|messages]] --- デバッグ出力(debug/info/notice/warning/errorメソッドで出力した値)
 +  * [[http://phpdebugbar.com/docs/base-collectors.html#requestdata|request]] --- PHPのスーパーグローバル変数($_GET/$_POST/$_COOKIE/$_SERVER)
 +  * [[http://phpdebugbar.com/docs/base-collectors.html#exceptions|exceptions]] --- 例外表示
 +
 +■ デバッグ出力の種類毎にフィルタリングできます。 \\
 +■ メッセージをクリックすると変数の展開できます。
 +
 +
  
basic-library/php-debugbar/1.16.1584601304.txt.gz · 最終更新: 2020/03/19 16:01 by tanaka