abstract class AcquiaPurgeStateStorageBase in Acquia Purge 7
Base layer for state storage backends.
Hierarchy
- class \AcquiaPurgeStateStorageBase implements AcquiaPurgeStateStorageInterface
Expanded class hierarchy of AcquiaPurgeStateStorageBase
File
- lib/
state/ AcquiaPurgeStateStorageBase.php, line 11 - Contains AcquiaPurgeStateStorageBase.
View source
abstract class AcquiaPurgeStateStorageBase implements AcquiaPurgeStateStorageInterface {
/**
* Indicates if ::commit() has been registered to be called at shutdown.
*
* @var bool
*/
protected $commit = FALSE;
/**
* Item instances.
*
* @var AcquiaPurgeStateItemInterface[]
*/
protected $items = array();
/**
* The payload buffer which gets synchronized with memcached.
*
* @var mixed[]
*/
protected $buffer = array();
/**
* Propagate AcquiaPurgeStateItem objects from the given buffer data.
*
* @param mixed $buffer
* Raw buffer payload to initialize state data from.
*
* @return int
* The number of items it was able to load from the buffer.
*/
public function __construct($buffer) {
$loaded_items = 0;
_acquia_purge_load('_acquia_purge_state_item_interface');
$class = _acquia_purge_load('_acquia_purge_state_item');
if (is_array($buffer) && count($buffer)) {
foreach ($buffer as $key => $value) {
if (!is_string($key)) {
continue;
}
$this->buffer[$key] = $value;
$this->items[$key] = new $class($this, $key, $value);
$loaded_items++;
}
}
return $loaded_items;
}
/**
* {@inheritdoc}
*/
public function set(AcquiaPurgeStateItemInterface $item) {
if (!$this->commit) {
$this->commit = TRUE;
drupal_register_shutdown_function(array(
$this,
'commit',
));
}
$this->items[$item
->getKey()] = $item;
$this->buffer[$item
->getKey()] = $item
->get();
}
/**
* {@inheritdoc}
*/
public function get($key, $default = NULL) {
if (!isset($this->items[$key])) {
_acquia_purge_load('_acquia_purge_state_item_interface');
$class = _acquia_purge_load('_acquia_purge_state_item');
$this->items[$key] = new $class($this, $key, $default);
}
return $this->items[$key];
}
/**
* {@inheritdoc}
*/
public function getCounter($key) {
_acquia_purge_load('_acquia_purge_state_counter_interface');
$class = _acquia_purge_load('_acquia_purge_state_counter');
if (isset($this->items[$key])) {
if (!$this->items[$key] instanceof AcquiaPurgeStateCounterInterface) {
$this->items[$key] = new $class($this, $key, $this->items[$key]
->get());
}
}
else {
$this->items[$key] = new $class($this, $key, 0);
}
return $this->items[$key];
}
/**
* {@inheritdoc}
*/
public function wipe() {
$this->items = array();
$this->buffer = array();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AcquiaPurgeStateStorageBase:: |
protected | property | The payload buffer which gets synchronized with memcached. | |
AcquiaPurgeStateStorageBase:: |
protected | property | Indicates if ::commit() has been registered to be called at shutdown. | |
AcquiaPurgeStateStorageBase:: |
protected | property | Item instances. | |
AcquiaPurgeStateStorageBase:: |
public | function |
Retrieve the object named $key. Overrides AcquiaPurgeStateStorageInterface:: |
|
AcquiaPurgeStateStorageBase:: |
public | function |
Retrieve a counter object named $key. Overrides AcquiaPurgeStateStorageInterface:: |
|
AcquiaPurgeStateStorageBase:: |
public | function |
Store the state item in state item storage. Overrides AcquiaPurgeStateStorageInterface:: |
|
AcquiaPurgeStateStorageBase:: |
public | function |
Wipe all state data. Overrides AcquiaPurgeStateStorageInterface:: |
2 |
AcquiaPurgeStateStorageBase:: |
public | function | Propagate AcquiaPurgeStateItem objects from the given buffer data. | 2 |
AcquiaPurgeStateStorageInterface:: |
public | function | Commit the state data to its persistent storage location. | 2 |