/** * Set key pattern * * @param null|string $keyPattern * @throws Exception\InvalidArgumentException * @return AdapterOptions */ public function setKeyPattern($keyPattern) { $keyPattern = (string) $keyPattern; if ($this->keyPattern !== $keyPattern) { // validate pattern if ($keyPattern !== '') { ErrorHandler::start(E_WARNING); $result = preg_match($keyPattern, ''); $error = ErrorHandler::stop(); if ($result === false) { throw new Exception\InvalidArgumentException(sprintf('Invalid pattern "%s"%s', $keyPattern, $error ? ': ' . $error->getMessage() : ''), 0, $error); } } $this->keyPattern = $keyPattern; } return $this; }
/** * Unlink a file * * @param string $file * @return void * @throws Exception\RuntimeException */ protected function unlink($file) { ErrorHandler::start(); $res = unlink($file); $err = ErrorHandler::stop(); // only throw exception if file still exists after deleting if (!$res && file_exists($file)) { throw new Exception\RuntimeException("Error unlinking file '{$file}'; file still exists", 0, $err); } }