Slim-Flash
Slim-Flash copied to clipboard
Problems with ArrayAccess storage
When using an ArrayAccess storage (I'm using adbario/slim-secure-session-middleware) the addMessage fails to write the message to the storage. The problem is that with ArrayAccess double indexing cannot be used:
$this->storage[$this->storageKey][$key] = array();
has no effect. Instead the following should be used:
$temp = $this->storage[$this->storageKey];
$temp[$key] = array();
$this->storage[$this->storageKey] =$temp;
I made a small modification to addMessage which seems to work:
public function addMessage($key, $message)
{
// Workaround for ArrayAccess storage
$temp = $this->storage[$this->storageKey];
// Create Array for this key
if (!isset($temp[$key])) {
$temp[$key] = [];
}
// Push onto the array
$temp[$key][] = $message;
$this->storage[$this->storageKey] = $temp;
}
If you have control of the ArrayAccess implementation, you can add a & to the offsetGet implementation to solve this.
public function &offsetGet($offset)
{