-
Notifications
You must be signed in to change notification settings - Fork 570
POC Dump panel. #1038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
POC Dump panel. #1038
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* @link https://cakephp.org CakePHP(tm) Project | ||
* @since DebugKit 5.1 | ||
* @license https://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace DebugKit; | ||
|
||
use Cake\Core\Configure; | ||
|
||
/** | ||
* Contains methods for dumping well formatted SQL queries. | ||
*/ | ||
class DebugStatements | ||
{ | ||
/** | ||
* @var array<string> | ||
*/ | ||
protected static $statements = []; | ||
Check failure on line 28 in src/DebugStatements.php
|
||
|
||
/** | ||
* @return array<string> | ||
*/ | ||
public static function all(): array | ||
{ | ||
return static::$statements; | ||
} | ||
|
||
/** | ||
* Template used for HTML output. | ||
* | ||
* @var string | ||
*/ | ||
private static string $templateHtml = <<<HTML | ||
<div class="cake-debug-output"> | ||
%s | ||
<pre class="cake-debug"> | ||
%s | ||
</pre> | ||
</div> | ||
HTML; | ||
|
||
/** | ||
* Template used for CLI and text output. | ||
* | ||
* @var string | ||
*/ | ||
private static string $templateText = <<<TEXT | ||
%s | ||
########## DEBUG ########## | ||
%s | ||
########################### | ||
|
||
TEXT; | ||
|
||
/** | ||
* Prints out the SQL statements generated by a Query object. | ||
* | ||
* This function returns the same variable that was passed. | ||
* Only runs if debug mode is enabled. | ||
* | ||
* @param mixed $var | ||
* @param bool|null $showHtml | ||
* @param array $location | ||
* @return string Empty string. | ||
*/ | ||
public static function add(mixed $var, ?bool $showHtml = null, array $location = []): string | ||
{ | ||
if (!Configure::read('debug')) { | ||
return ''; | ||
} | ||
|
||
static::$statements[] = [ | ||
'var' => $var, | ||
'showHtml' => $showHtml, | ||
'location' => $location, | ||
]; | ||
|
||
return ''; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* @link https://cakephp.org CakePHP(tm) Project | ||
* @license https://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace DebugKit\Panel; | ||
|
||
use DebugKit\DebugPanel; | ||
use DebugKit\DebugStatements; | ||
|
||
/** | ||
* A panel for displaying dumped statements. | ||
*/ | ||
class DumpPanel extends DebugPanel | ||
{ | ||
/** | ||
* Get the data for this panel | ||
* | ||
* @return array | ||
*/ | ||
public function data(): array | ||
{ | ||
return [ | ||
'statements' => DebugStatements::all(), | ||
]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* Debug Panel Element | ||
* | ||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* @link https://cakephp.org CakePHP(tm) Project | ||
* @since DebugKit 5.1 | ||
* @license https://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
|
||
/** | ||
* @var \DebugKit\View\AjaxView $this | ||
* @var array $statements | ||
*/ | ||
|
||
?> | ||
<div class="c-dump-panel"> | ||
<?php | ||
foreach ($statements as $statement) { | ||
echo '<pre class="cake-debug-string">' . h($statement['var']) . '</pre>'; | ||
if (!empty($statement['location'])) { | ||
echo '<small>' . h($statement['location']['file']) . ':' . h($statement['location']['line']) . '</small>'; | ||
} | ||
} | ||
|
||
?> | ||
<h4></h4> | ||
|
||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to handle more complex values as well? If we're only going to support simple values, one could use logging instead.