MemcacheStatsEvent.php in Memcache API and Integration 8.2
Namespace
Drupal\memcache_admin\EventFile
memcache_admin/src/Event/MemcacheStatsEvent.phpView source
<?php
namespace Drupal\memcache_admin\Event;
use Drupal\memcache\DrupalMemcacheInterface;
use Symfony\Component\EventDispatcher\Event;
/**
* Memcache Stats Event
*
* The memcache stats event stores all the attributes generated by the different
* types of memcache servers. Currently memcache_admin supports memcache and
* mcrouter.
*/
class MemcacheStatsEvent extends Event {
/**
* Event used to build the memcache stats array.
*
* When the stats array is created, this event allows modules to inject extra
* data to be contained within the array.
*/
const BUILD_MEMCACHE_STATS = 'memcache_build_memcache_stats';
/**
* Event used to report out the memcache stats array.
*
* When the stats array is created, this event allows modules to inject extra
* data to be contained within the array.
*/
const REPORT_MEMCACHE_STATS = 'memcache_report_memcache_stats';
/**
* The Stats Array for which to create attributes.
*
* @var array
*/
protected $rawStats;
/**
* The Stats Array for which to create attributes.
*
* @var array
*/
protected $formattedStats = [];
/**
* The Stats Array for which to create attributes.
*
* @var array
*/
protected $totals;
/**
* The Stats Array for which to create attributes.
*
* @var array
*/
protected $report;
/**
* The Stats Array for which to create attributes.
*
* @var array
*/
protected $servers;
/**
* Cache Bin To Retrieve
* @var string $bin
*/
protected $bin;
protected $memcache;
/**
* MemcacheStatsEvent constructor.
*
* @param array $raw_stats
* The Stats Data.
* @param string $bin
* The cache bin.
*
*/
public function __construct(DrupalMemcacheInterface $memcache, string $bin = 'default') {
$this->memcache = $memcache;
$this->rawStats = $memcache
->stats($bin, 'default', TRUE);
$this->formattedStats = [];
$this->bin = $bin;
}
/**
* Get the Stats Array being created.
*
* @return array
* The Stats Object.
*/
public function getRawStats() {
return $this->rawStats;
}
/**
* Gets the stats formatted from a MemcacheStatsInterface.
* @param $server_type
*
* @return array|mixed
*/
public function getFormattedStats($server_type) {
if (isset($this->formattedStats[$server_type])) {
return $this->formattedStats[$server_type];
}
return [];
}
/**
* Returns the memcache connection.
*/
public function getMemcache() {
return $this->memcache;
}
/**
* Returns the cache bin from this event.
*/
public function getCacheBin() {
return $this->bin;
}
/**
* Sets the formatted stats array with relevant data.
*
* @param string $format
* @param string $bin
* @param string $server
* @param \Drupal\memcache_admin\Stats\MemcacheStatsInterface $data
*/
public function updateFormattedStats($format, $bin, $server, $data) {
$this->formattedStats[$format][$bin][$server] = $data;
}
/**
* Update the total column when multiple memcache servers exist.
* @param $total
*/
public function updateTotals($total) {
$this->totals = $total;
}
/**
* Return the total values from all memcache servers.
* @return array
*/
public function getTotals() {
return $this->totals;
}
/**
* Add a new server to the servers array.
* @param string $server
*/
public function updateServers($server) {
$this->servers[] = $server;
}
/**
* Retrieve all servers from the servers array.
*
* @return array
*/
public function getServers() {
return $this->servers;
}
/**
* Update the full report from the event.
* @param $report
*/
public function updateReport($report) {
$this->report = $report;
}
/**
* Returns the stats report.
* @return array
*/
public function getReport() {
return $this->report;
}
}
Classes
Name | Description |
---|---|
MemcacheStatsEvent | Memcache Stats Event |