update v1.0.7.9 R.C.
This is a Release Candidate. We are still testing.
This commit is contained in:
128
vendor/maximebf/debugbar/src/DebugBar/Storage/FileStorage.php
vendored
Normal file
128
vendor/maximebf/debugbar/src/DebugBar/Storage/FileStorage.php
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
<?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";
|
||||
}
|
||||
}
|
||||
111
vendor/maximebf/debugbar/src/DebugBar/Storage/MemcachedStorage.php
vendored
Normal file
111
vendor/maximebf/debugbar/src/DebugBar/Storage/MemcachedStorage.php
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Stores collected data into Memcache using the Memcached extension
|
||||
*/
|
||||
class MemcachedStorage implements StorageInterface
|
||||
{
|
||||
protected $memcached;
|
||||
|
||||
protected $keyNamespace;
|
||||
|
||||
/**
|
||||
* @param Memcached $memcached
|
||||
*/
|
||||
public function __construct(Memcached $memcached, $keyNamespace = 'phpdebugbar')
|
||||
{
|
||||
$this->memcached = $memcached;
|
||||
$this->keyNamespace = $keyNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save($id, $data)
|
||||
{
|
||||
$key = $this->createKey($id);
|
||||
$this->memcached->set($key, $data);
|
||||
if (!$this->memcached->append($this->keyNamespace, "|$key")) {
|
||||
$this->memcached->set($this->keyNamespace, $key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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();
|
||||
foreach (explode('|', $keys) as $key) {
|
||||
if ($data = $this->memcached->get($key)) {
|
||||
$meta = $data['__meta'];
|
||||
if ($this->filter($meta, $filters)) {
|
||||
$results[] = $meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
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()
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
137
vendor/maximebf/debugbar/src/DebugBar/Storage/PdoStorage.php
vendored
Normal file
137
vendor/maximebf/debugbar/src/DebugBar/Storage/PdoStorage.php
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
87
vendor/maximebf/debugbar/src/DebugBar/Storage/RedisStorage.php
vendored
Normal file
87
vendor/maximebf/debugbar/src/DebugBar/Storage/RedisStorage.php
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<?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 Predis\Client;
|
||||
|
||||
/**
|
||||
* 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(Client $redis, $hash = 'phpdebugbar')
|
||||
{
|
||||
$this->redis = $redis;
|
||||
$this->hash = $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save($id, $data)
|
||||
{
|
||||
$this->redis->hset($this->hash, $id, serialize($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return unserialize($this->redis->hget($this->hash, $id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find(array $filters = array(), $max = 20, $offset = 0)
|
||||
{
|
||||
$results = array();
|
||||
foreach ($this->redis->hgetall($this->hash) as $id => $data) {
|
||||
if ($data = unserialize($data)) {
|
||||
$meta = $data['__meta'];
|
||||
if ($this->filter($meta, $filters)) {
|
||||
$results[] = $meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
45
vendor/maximebf/debugbar/src/DebugBar/Storage/StorageInterface.php
vendored
Normal file
45
vendor/maximebf/debugbar/src/DebugBar/Storage/StorageInterface.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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();
|
||||
}
|
||||
16
vendor/maximebf/debugbar/src/DebugBar/Storage/pdo_storage_schema.sql
vendored
Normal file
16
vendor/maximebf/debugbar/src/DebugBar/Storage/pdo_storage_schema.sql
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
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