-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from Firesphere/hans/header-collector
Add a Header collector
- Loading branch information
Showing
7 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,2 @@ | ||
.php_cs.cache | ||
.idea |
This file contains 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 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 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 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 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,76 @@ | ||
<?php | ||
|
||
namespace LeKoala\DebugBar\Collector; | ||
|
||
use DebugBar\DataCollector\AssetProvider; | ||
use DebugBar\DataCollector\DataCollector; | ||
use DebugBar\DataCollector\Renderable; | ||
use SilverStripe\Control\Controller; | ||
|
||
class HeaderCollector extends DataCollector implements Renderable, AssetProvider | ||
{ | ||
/** | ||
* @var \SilverStripe\Control\Controller; | ||
*/ | ||
protected $controller; | ||
|
||
/** | ||
* HeaderCollector constructor. | ||
* @param Controller $controller | ||
*/ | ||
public function __construct($controller) | ||
{ | ||
$this->controller = $controller; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getWidgets() | ||
{ | ||
return [ | ||
'Headers' => [ | ||
'icon' => 'gear', | ||
'widget' => 'PhpDebugBar.Widgets.VariableListWidget', | ||
'map' => 'Headers.list', | ||
'default' => '{}' | ||
], | ||
'Headers:badge' => [ | ||
'map' => 'Headers.count', | ||
'default' => 0 | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function collect() | ||
{ | ||
|
||
$result = $this->controller->getResponse()->getHeaders(); | ||
|
||
foreach ($result as $key => &$value) { | ||
$value = trim(implode(PHP_EOL, explode('; ', $value))); | ||
$value = implode(PHP_EOL . ' - ', explode(' ', $value)); | ||
} | ||
|
||
return [ | ||
'count' => count($result), | ||
'list' => $result | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return 'Headers'; | ||
} | ||
|
||
public function getAssets() | ||
{ | ||
return []; | ||
} | ||
} |
This file contains 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