for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of Transfer.
*
* For the full copyright and license information, please view the LICENSE file located
* in the root directory.
*/
namespace Transfer\Storage;
use Transfer\Storage\Exception\ObjectNotFoundException;
/**
* In-memory storage.
class InMemoryStorage extends AbstractStorage
{
* @var array
private $data = array();
* {@inheritdoc}
public function add($object, $id = null)
if ($id === null) {
$id = $this->hashingStrategy->hash($object);
}
$this->data[$id] = $object;
return true;
public function contains($object)
return $this->containsId($this->hashingStrategy->hash($object));
public function containsId($id)
return array_key_exists($id, $this->data);
public function findById($id)
if (!$this->containsId($id)) {
throw new ObjectNotFoundException($id);
return $this->data[$id];
public function remove($object)
return $this->removeById($this->hashingStrategy->hash($object));
public function removeById($id)
unset($this->data[$id]);
public function all()
return $this->data;