-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.0] Improve DebugBar: view history, allow debug POST and non HTML requests, replace json storage to own #22327
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
40d993f
Custom storage
Fedik fba8387
Debug OpenHandler
Fedik d7f5977
Debug stackData, allow debug POST and non HTML requests
Fedik 4f8a47f
Debug ajax request, Check for request forgeries
Fedik ad06e1b
phpcs
Fedik 7bfc904
phpcs
Fedik 0e51812
phpcs
Fedik 6fda29a
remove unused, array syntax
Fedik 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Plugin | ||
| * @subpackage System.Debug | ||
| * | ||
| * @copyright Copyright (C) 2017 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Plugin\System\Debug\Storage; | ||
|
|
||
| use Joomla\Filesystem\Folder; | ||
|
|
||
| /** | ||
| * Stores collected data into files | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class FileStorage extends \DebugBar\Storage\FileStorage | ||
| { | ||
| /** | ||
| * Saves collected data | ||
| * | ||
| * @param string $id The log id | ||
| * @param string $data The log data | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function save($id, $data) | ||
| { | ||
| if (!file_exists($this->dirname)) | ||
| { | ||
| Folder::create($this->dirname); | ||
| } | ||
|
|
||
| $dataStr = '<?php die(); ?>#(^-^)#' . json_encode($data); | ||
|
|
||
| file_put_contents($this->makeFilename($id), $dataStr); | ||
| } | ||
|
|
||
| /** | ||
| * Returns collected data with the specified id | ||
| * | ||
| * @param string $id The log id | ||
| * | ||
| * @return array | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function get($id) | ||
| { | ||
| $dataStr = file_get_contents($this->makeFilename($id)); | ||
| $dataStr = str_replace('<?php die(); ?>#(^-^)#', '', $dataStr); | ||
|
|
||
| return json_decode($dataStr, true) ?: array(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a metadata about collected data | ||
| * | ||
| * @param array $filters Filtering options | ||
| * @param integer $max The limit, items per page | ||
| * @param integer $offset The offset | ||
| * | ||
| * @return array | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function find(array $filters = [], $max = 20, $offset = 0) | ||
| { | ||
| // Loop through all .php files and remember the modified time and id. | ||
| $files = []; | ||
| foreach (new \DirectoryIterator($this->dirname) as $file) | ||
| { | ||
| if ($file->getExtension() == 'php') | ||
| { | ||
| $files[] = array( | ||
| 'time' => $file->getMTime(), | ||
| 'id' => $file->getBasename('.php') | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Sort the files, newest first | ||
| usort( | ||
| $files, | ||
| function ($a, $b) { | ||
| return $a['time'] < $b['time']; | ||
| } | ||
| ); | ||
|
|
||
| // Load the metadata and filter the results. | ||
| $results = []; | ||
| $i = 0; | ||
| foreach ($files as $file) | ||
| { | ||
| // When filter is empty, skip loading the offset | ||
| if ($i++ < $offset && empty($filters)) | ||
| { | ||
| $results[] = null; | ||
| continue; | ||
| } | ||
|
|
||
| $data = $this->get($file['id']); | ||
| $meta = $data['__meta']; | ||
| unset($data); | ||
|
|
||
| if ($this->filter($meta, $filters)) | ||
| { | ||
| $results[] = $meta; | ||
| } | ||
|
|
||
| if (count($results) >= ($max + $offset)) | ||
| { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return array_slice($results, $offset, $max); | ||
| } | ||
|
|
||
| /** | ||
| * Get a full path to the file | ||
| * | ||
| * @param string $id The log id | ||
| * | ||
| * @return string | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function makeFilename($id) | ||
| { | ||
| return $this->dirname . basename($id) . '.php'; | ||
| } | ||
| } | ||
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
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.
Change to
[]