-
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.
- Loading branch information
Showing
7 changed files
with
111 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
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 LeKoala\DebugBar\DebugBar; | ||
use SilverStripe\Control\Director; | ||
use DebugBar\DataCollector\Renderable; | ||
use LeKoala\DebugBar\Proxy\CacheProxy; | ||
use DebugBar\DataCollector\AssetProvider; | ||
use DebugBar\DataCollector\DataCollector; | ||
|
||
/** | ||
* Collects data about the cache | ||
*/ | ||
class CacheCollector extends DataCollector implements Renderable, AssetProvider | ||
{ | ||
public function getName() | ||
{ | ||
return 'cache'; | ||
} | ||
|
||
public function getAssets() | ||
{ | ||
// This depends on ConfigCollector assets | ||
return [ | ||
'base_path' => '/' . DebugBar::moduleResource('javascript')->getRelativePath(), | ||
'base_url' => Director::makeRelative(DebugBar::moduleResource('javascript')->getURL()), | ||
'css' => 'config/widget.css', | ||
'js' => 'config/widget.js' | ||
]; | ||
} | ||
|
||
public function collect() | ||
{ | ||
$result = CacheProxy::getData(); | ||
|
||
|
||
$keys = []; | ||
foreach ($result as $k => $v) { | ||
$val = $v['value']; | ||
if (!is_string($val)) { | ||
$val = json_encode($val); | ||
} | ||
if (strlen($val) > 150) { | ||
$val = substr($val, 0, 150) . "..."; | ||
} | ||
if (!empty($v['ttl'])) { | ||
$val .= " - TTL: " . $v['ttl']; | ||
} | ||
$keys[$k] = $val; | ||
} | ||
|
||
return [ | ||
'count' => count($result), | ||
'keys' => $keys | ||
]; | ||
} | ||
|
||
public function getWidgets() | ||
{ | ||
$widgets = [ | ||
'Cache' => [ | ||
'icon' => 'puzzle-piece', | ||
'widget' => 'PhpDebugBar.Widgets.VariableListWidget', | ||
'map' => 'cache.keys', | ||
'default' => '{}' | ||
] | ||
]; | ||
$widgets['Cache:badge'] = [ | ||
'map' => 'cache.count', | ||
'default' => 0 | ||
]; | ||
|
||
return $widgets; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace LeKoala\DebugBar\Proxy; | ||
|
||
use Symfony\Component\Cache\Psr16Cache; | ||
|
||
class CacheProxy extends Psr16Cache | ||
{ | ||
protected static $data = []; | ||
|
||
public function set($key, $value, $ttl = null): bool | ||
{ | ||
self::$data[$key] = [ | ||
"value" => $value, | ||
"ttl" => $ttl | ||
]; | ||
return parent::set($key, $value, $ttl); | ||
} | ||
|
||
public static function getData(): array | ||
{ | ||
return self::$data; | ||
} | ||
} |