updated-packages
This commit is contained in:
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Storage;
|
||||
|
||||
/**
|
||||
* Stores collected data into files
|
||||
*/
|
||||
class FileStorage implements StorageInterface
|
||||
{
|
||||
protected $dirname;
|
||||
|
||||
/**
|
||||
* @param string $dirname Directories where to store files
|
||||
*/
|
||||
public function __construct($dirname)
|
||||
{
|
||||
$this->dirname = rtrim($dirname, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save($id, $data)
|
||||
{
|
||||
if (!file_exists($this->dirname)) {
|
||||
mkdir($this->dirname, 0777, true);
|
||||
}
|
||||
file_put_contents($this->makeFilename($id), json_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return json_decode(file_get_contents($this->makeFilename($id)), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find(array $filters = array(), $max = 20, $offset = 0)
|
||||
{
|
||||
//Loop through all .json files and remember the modified time and id.
|
||||
$files = array();
|
||||
foreach (new \DirectoryIterator($this->dirname) as $file) {
|
||||
if ($file->getExtension() == 'json') {
|
||||
$files[] = array(
|
||||
'time' => $file->getMTime(),
|
||||
'id' => $file->getBasename('.json')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//Sort the files, newest first
|
||||
usort($files, function ($a, $b) {
|
||||
return $a['time'] < $b['time'];
|
||||
});
|
||||
|
||||
//Load the metadata and filter the results.
|
||||
$results = array();
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the metadata for matches.
|
||||
*
|
||||
* @param array $meta
|
||||
* @param array $filters
|
||||
* @return bool
|
||||
*/
|
||||
protected function filter($meta, $filters)
|
||||
{
|
||||
foreach ($filters as $key => $value) {
|
||||
if (!isset($meta[$key]) || fnmatch($value, $meta[$key]) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
foreach (new \DirectoryIterator($this->dirname) as $file) {
|
||||
if (substr($file->getFilename(), 0, 1) !== '.') {
|
||||
unlink($file->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return string
|
||||
*/
|
||||
public function makeFilename($id)
|
||||
{
|
||||
return $this->dirname . basename($id). ".json";
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Storage;
|
||||
|
||||
use Memcached;
|
||||
use ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Stores collected data into Memcache using the Memcached extension
|
||||
*/
|
||||
class MemcachedStorage implements StorageInterface
|
||||
{
|
||||
protected $memcached;
|
||||
|
||||
protected $keyNamespace;
|
||||
|
||||
protected $expiration;
|
||||
|
||||
protected $newGetMultiSignature;
|
||||
|
||||
/**
|
||||
* @param Memcached $memcached
|
||||
* @param string $keyNamespace Namespace for Memcached key names (to avoid conflict with other Memcached users).
|
||||
* @param int $expiration Expiration for Memcached entries (see Expiration Times in Memcached documentation).
|
||||
*/
|
||||
public function __construct(Memcached $memcached, $keyNamespace = 'phpdebugbar', $expiration = 0)
|
||||
{
|
||||
$this->memcached = $memcached;
|
||||
$this->keyNamespace = $keyNamespace;
|
||||
$this->expiration = $expiration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save($id, $data)
|
||||
{
|
||||
$key = $this->createKey($id);
|
||||
$this->memcached->set($key, $data, $this->expiration);
|
||||
if (!$this->memcached->append($this->keyNamespace, "|$key")) {
|
||||
$this->memcached->set($this->keyNamespace, $key, $this->expiration);
|
||||
} else if ($this->expiration) {
|
||||
// append doesn't support updating expiration, so do it here:
|
||||
$this->memcached->touch($this->keyNamespace, $this->expiration);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return $this->memcached->get($this->createKey($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find(array $filters = array(), $max = 20, $offset = 0)
|
||||
{
|
||||
if (!($keys = $this->memcached->get($this->keyNamespace))) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$results = array();
|
||||
$keys = array_reverse(explode('|', $keys)); // Reverse so newest comes first
|
||||
$keyPosition = 0; // Index in $keys to try to get next items from
|
||||
$remainingItems = $max + $offset; // Try to obtain this many remaining items
|
||||
// Loop until we've found $remainingItems matching items or no more items may exist.
|
||||
while ($remainingItems > 0 && $keyPosition < count($keys)) {
|
||||
// Consume some keys from $keys:
|
||||
$itemsToGet = array_slice($keys, $keyPosition, $remainingItems);
|
||||
$keyPosition += $remainingItems;
|
||||
// Try to get them, and filter them:
|
||||
$newItems = $this->memcachedGetMulti($itemsToGet, Memcached::GET_PRESERVE_ORDER);
|
||||
if ($newItems) {
|
||||
foreach ($newItems as $data) {
|
||||
$meta = $data['__meta'];
|
||||
if ($this->filter($meta, $filters)) {
|
||||
$remainingItems--;
|
||||
// Keep the result only if we've discarded $offset items first
|
||||
if ($offset <= 0) {
|
||||
$results[] = $meta;
|
||||
} else {
|
||||
$offset--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the metadata for matches.
|
||||
*
|
||||
* @param array $meta
|
||||
* @param array $filters
|
||||
* @return bool
|
||||
*/
|
||||
protected function filter($meta, $filters)
|
||||
{
|
||||
foreach ($filters as $key => $value) {
|
||||
if (!isset($meta[$key]) || fnmatch($value, $meta[$key]) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
if (!($keys = $this->memcached->get($this->keyNamespace))) {
|
||||
return;
|
||||
}
|
||||
$this->memcached->delete($this->keyNamespace);
|
||||
$this->memcached->deleteMulti(explode('|', $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return string
|
||||
*/
|
||||
protected function createKey($id)
|
||||
{
|
||||
return md5("{$this->keyNamespace}.$id");
|
||||
}
|
||||
|
||||
/**
|
||||
* The memcached getMulti function changed in version 3.0.0 to only have two parameters.
|
||||
*
|
||||
* @param array $keys
|
||||
* @param int $flags
|
||||
*/
|
||||
protected function memcachedGetMulti($keys, $flags)
|
||||
{
|
||||
if ($this->newGetMultiSignature === null) {
|
||||
$this->newGetMultiSignature = (new ReflectionMethod('Memcached', 'getMulti'))->getNumberOfParameters() === 2;
|
||||
}
|
||||
if ($this->newGetMultiSignature) {
|
||||
return $this->memcached->getMulti($keys, $flags);
|
||||
} else {
|
||||
$null = null;
|
||||
return $this->memcached->getMulti($keys, $null, $flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Storage;
|
||||
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* Stores collected data into a database using PDO
|
||||
*/
|
||||
class PdoStorage implements StorageInterface
|
||||
{
|
||||
protected $pdo;
|
||||
|
||||
protected $tableName;
|
||||
|
||||
protected $sqlQueries = array(
|
||||
'save' => "INSERT INTO %tablename% (id, data, meta_utime, meta_datetime, meta_uri, meta_ip, meta_method) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
'get' => "SELECT data FROM %tablename% WHERE id = ?",
|
||||
'find' => "SELECT data FROM %tablename% %where% ORDER BY meta_datetime DESC LIMIT %limit% OFFSET %offset%",
|
||||
'clear' => "DELETE FROM %tablename%"
|
||||
);
|
||||
|
||||
/**
|
||||
* @param \PDO $pdo The PDO instance
|
||||
* @param string $tableName
|
||||
* @param array $sqlQueries
|
||||
*/
|
||||
public function __construct(PDO $pdo, $tableName = 'phpdebugbar', array $sqlQueries = array())
|
||||
{
|
||||
$this->pdo = $pdo;
|
||||
$this->tableName = $tableName;
|
||||
$this->setSqlQueries($sqlQueries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sql queries to be used
|
||||
*
|
||||
* @param array $queries
|
||||
*/
|
||||
public function setSqlQueries(array $queries)
|
||||
{
|
||||
$this->sqlQueries = array_merge($this->sqlQueries, $queries);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save($id, $data)
|
||||
{
|
||||
$sql = $this->getSqlQuery('save');
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$meta = $data['__meta'];
|
||||
$stmt->execute(array($id, serialize($data), $meta['utime'], $meta['datetime'], $meta['uri'], $meta['ip'], $meta['method']));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$sql = $this->getSqlQuery('get');
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute(array($id));
|
||||
if (($data = $stmt->fetchColumn(0)) !== false) {
|
||||
return unserialize($data);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find(array $filters = array(), $max = 20, $offset = 0)
|
||||
{
|
||||
$where = array();
|
||||
$params = array();
|
||||
foreach ($filters as $key => $value) {
|
||||
$where[] = "meta_$key = ?";
|
||||
$params[] = $value;
|
||||
}
|
||||
if (count($where)) {
|
||||
$where = " WHERE " . implode(' AND ', $where);
|
||||
} else {
|
||||
$where = '';
|
||||
}
|
||||
|
||||
$sql = $this->getSqlQuery('find', array(
|
||||
'where' => $where,
|
||||
'offset' => $offset,
|
||||
'limit' => $max
|
||||
));
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
$results = array();
|
||||
foreach ($stmt->fetchAll() as $row) {
|
||||
$data = unserialize($row['data']);
|
||||
$results[] = $data['__meta'];
|
||||
unset($data);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->pdo->exec($this->getSqlQuery('clear'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a SQL Query for a task, with the variables replaced
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $vars
|
||||
* @return string
|
||||
*/
|
||||
protected function getSqlQuery($name, array $vars = array())
|
||||
{
|
||||
$sql = $this->sqlQueries[$name];
|
||||
$vars = array_merge(array('tablename' => $this->tableName), $vars);
|
||||
foreach ($vars as $k => $v) {
|
||||
$sql = str_replace("%$k%", $v, $sql);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Storage;
|
||||
|
||||
/**
|
||||
* Stores collected data into Redis
|
||||
*/
|
||||
class RedisStorage implements StorageInterface
|
||||
{
|
||||
protected $redis;
|
||||
|
||||
protected $hash;
|
||||
|
||||
/**
|
||||
* @param \Predis\Client $redis Redis Client
|
||||
* @param string $hash
|
||||
*/
|
||||
public function __construct($redis, $hash = 'phpdebugbar')
|
||||
{
|
||||
$this->redis = $redis;
|
||||
$this->hash = $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save($id, $data)
|
||||
{
|
||||
$this->redis->hset("$this->hash:meta", $id, serialize($data['__meta']));
|
||||
unset($data['__meta']);
|
||||
$this->redis->hset("$this->hash:data", $id, serialize($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return array_merge(unserialize($this->redis->hget("$this->hash:data", $id)),
|
||||
array('__meta' => unserialize($this->redis->hget("$this->hash:meta", $id))));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find(array $filters = array(), $max = 20, $offset = 0)
|
||||
{
|
||||
$results = array();
|
||||
$cursor = "0";
|
||||
do {
|
||||
list($cursor, $data) = $this->redis->hscan("$this->hash:meta", $cursor);
|
||||
|
||||
foreach ($data as $meta) {
|
||||
if ($meta = unserialize($meta)) {
|
||||
if ($this->filter($meta, $filters)) {
|
||||
$results[] = $meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while($cursor);
|
||||
|
||||
usort($results, function ($a, $b) {
|
||||
return $a['utime'] < $b['utime'];
|
||||
});
|
||||
|
||||
return array_slice($results, $offset, $max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the metadata for matches.
|
||||
*/
|
||||
protected function filter($meta, $filters)
|
||||
{
|
||||
foreach ($filters as $key => $value) {
|
||||
if (!isset($meta[$key]) || fnmatch($value, $meta[$key]) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->redis->del($this->hash);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Storage;
|
||||
|
||||
interface StorageInterface
|
||||
{
|
||||
/**
|
||||
* Saves collected data
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $data
|
||||
*/
|
||||
function save($id, $data);
|
||||
|
||||
/**
|
||||
* Returns collected data with the specified id
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
function get($id);
|
||||
|
||||
/**
|
||||
* Returns a metadata about collected data
|
||||
*
|
||||
* @param array $filters
|
||||
* @param integer $max
|
||||
* @param integer $offset
|
||||
* @return array
|
||||
*/
|
||||
function find(array $filters = array(), $max = 20, $offset = 0);
|
||||
|
||||
/**
|
||||
* Clears all the collected data
|
||||
*/
|
||||
function clear();
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
CREATE TABLE phpdebugbar (
|
||||
id TEXT PRIMARY KEY,
|
||||
data TEXT,
|
||||
meta_utime TEXT,
|
||||
meta_datetime TEXT,
|
||||
meta_uri TEXT,
|
||||
meta_ip TEXT,
|
||||
meta_method TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX idx_debugbar_id ON phpdebugbar (id);
|
||||
CREATE INDEX idx_debugbar_meta_utime ON phpdebugbar (meta_utime);
|
||||
CREATE INDEX idx_debugbar_meta_datetime ON phpdebugbar (meta_datetime);
|
||||
CREATE INDEX idx_debugbar_meta_uri ON phpdebugbar (meta_uri);
|
||||
CREATE INDEX idx_debugbar_meta_ip ON phpdebugbar (meta_ip);
|
||||
CREATE INDEX idx_debugbar_meta_method ON phpdebugbar (meta_method);
|
||||
Reference in New Issue
Block a user