for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Albert221\Blog\Repository\Database;
use Albert221\Blog\Entity\Setting;
use Albert221\Blog\Repository\SettingRepositoryInterface;
use Doctrine\ORM\EntityRepository;
use InvalidArgumentException;
class SettingRepository extends EntityRepository implements SettingRepositoryInterface
{
/**
* @var array Settings
*/
protected $settings;
public function offsetExists($offset)
if (is_null($this->settings)) {
$this->loadSettings();
}
return isset($this->settings[$offset]);
public function offsetGet($offset)
if (!$this->offsetExists($offset)) {
throw new InvalidArgumentException(sprintf('Setting \'%\' cannot be found.', $offset));
return $this->settings[$offset];
public function offsetSet($offset, $value)
// Do nothing
public function offsetUnset($offset)
protected function loadSettings()
$settings = [];
array_walk($this->findAll(), function (Setting $setting) use (&$settings) {
$this->findAll()
array_walk()
$array
$settings[$setting->getName()] = $setting;
});
$this->settings = $settings;