protected function processRequestOperations($action, array $arguments)
{
// Get the current active host.
$host = $this->getActiveHost(true);
$result = null;
$error = null;
$anchor = '';
// Try to execute the operation ...
try {
if (isset($arguments['set']) === true && ($arguments['set'] = strip_tags($arguments['set']))) {
// Check required minimum input
if (isset($arguments['value']) !== true) {
throw new \Exception(sprintf('Cannot set key "%s" without value!', $arguments['set']));
}
$value = $this->castAsPhpType($arguments['value']);
if (true !== ($result = $this->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)->set($arguments['set'], $value))) {
$error = $this->errorContext(self::ERROR_CREATE, array($arguments['set'], $arguments['value']));
} else {
$anchor = '#' . $arguments['set'];
}
} elseif (isset($arguments['replace']) === true && ($arguments['replace'] = strip_tags($arguments['replace']))) {
// Check required minimum input
if (isset($arguments['value']) !== true) {
throw new \Exception(sprintf('Cannot set key "%s" without value!', $arguments['set']));
}
$value = $this->castAsPhpType($arguments['value']);
if (true !== ($result = $this->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)->replace($arguments['replace'], $value))) {
$error = $this->errorContext(self::ERROR_UPDATE, array($arguments['replace']));
} else {
$anchor = '#' . $arguments['replace'];
}
} elseif (isset($arguments['append']) === true && ($arguments['append'] = strip_tags($arguments['append']))) {
if (true !== ($result = $this->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)->append($arguments['append'], $arguments['value']))) {
$error = $this->errorContext(self::ERROR_APPEND, array($arguments['append']));
} else {
$anchor = '#' . $arguments['append'];
}
} elseif (isset($arguments['prepend']) === true && ($arguments['prepend'] = strip_tags($arguments['prepend']))) {
if (true !== ($result = $this->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)->prepend($arguments['prepend'], $arguments['value']))) {
$error = $this->errorContext(self::ERROR_PREPEND, array($arguments['prepend']));
} else {
$anchor = '#' . $arguments['prepend'];
}
} elseif (isset($arguments['increment']) === true && ($arguments['increment'] = strip_tags($arguments['increment']))) {
$value = $this->castAsPhpType($arguments['value']);
if (true !== is_float($result = $this->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)->incr($arguments['increment'], $value))) {
$error = $this->errorContext(self::ERROR_INCREMENT, array($arguments['increment']));
} else {
$anchor = '#' . $arguments['increment'];
$result = true;
}
} elseif (isset($arguments['decrement']) === true && ($arguments['decrement'] = strip_tags($arguments['decrement']))) {
$value = $this->castAsPhpType($arguments['value']);
if (true !== is_float($result = $this->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)->decr($arguments['decrement'], $value))) {
$error = $this->errorContext(self::ERROR_DECREMENT, array($arguments['decrement']));
} else {
$anchor = '#' . $arguments['decrement'];
$result = true;
}
} elseif (isset($arguments['delete']) === true && ($arguments['delete'] = strip_tags($arguments['delete']))) {
if (true !== ($result = $this->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)->delete($arguments['delete']))) {
$error = $this->errorContext(self::ERROR_DELETE, array($arguments['delete']));
}
} elseif (isset($arguments['flush']) === true && ($arguments['flush'] = strip_tags($arguments['flush']))) {
if (true !== ($result = $this->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)->flush())) {
$error = $this->errorContext(self::ERROR_FLUSH);
}
}
} catch (\Clickalicious\Memcached\Exception $e) {
$error = $this->errorContext(self::ERROR_GENERIC, array(var_export($e, true)));
}
//
if ($error !== null) {
$this->setError(vsprintf($this->getErrorMessageByNumber($error['number']), $error['context']));
}
// Result = true = some operation done and redirect required!
if ($result === true) {
// So redirect to clean state self action
$this->redirect($this->getUrl(array('action' => $action, 'host' => $this->getActiveHost()), '', $anchor));
}
}