/** * Returns all sessions which are tagged by the specified tag. * * @param string $tag A valid Cache Frontend tag * @return array A collection of Session objects or an empty array if tag did not match * @api */ public function getSessionsByTag($tag) { $taggedSessions = []; foreach ($this->metaDataCache->getByTag(Session::TAG_PREFIX . $tag) as $sessionIdentifier => $sessionInfo) { $session = new Session($sessionIdentifier, $sessionInfo['storageIdentifier'], $sessionInfo['lastActivityTimestamp'], $sessionInfo['tags']); $taggedSessions[] = $session; } return $taggedSessions; }
/** * @test * @requires extension igbinary */ public function getByTagUsesIgBinaryIfAvailable() { $tag = 'sometag'; $identifiers = ['one', 'two']; $entries = ['one' => 'one value', 'two' => 'two value']; $backend = $this->prepareDefaultBackend(); $backend->expects($this->once())->method('findIdentifiersByTag')->with($this->equalTo($tag))->will($this->returnValue($identifiers)); $backend->expects($this->exactly(2))->method('get')->will($this->onConsecutiveCalls(igbinary_serialize('one value'), igbinary_serialize('two value'))); $cache = new VariableFrontend('VariableFrontend', $backend); $cache->initializeObject(); $this->assertEquals($entries, $cache->getByTag($tag), 'Did not receive the expected entries'); }