<?php
public function singleton($key, $value)
{
$this->set($key, function ($c) use ($value) {
static $object;
if (null === $object) {
$object = $value($c);
}
return $object;
});
}
PD9waHAKCnB1YmxpYyBmdW5jdGlvbiBzaW5nbGV0b24oJGtleSwgJHZhbHVlKQogICAgewogICAgICAgICR0aGlzLT5zZXQoJGtleSwgZnVuY3Rpb24gKCRjKSB1c2UgKCR2YWx1ZSkgewogICAgICAgICAgICBzdGF0aWMgJG9iamVjdDsKCiAgICAgICAgICAgIGlmIChudWxsID09PSAkb2JqZWN0KSB7CiAgICAgICAgICAgICAgICAkb2JqZWN0ID0gJHZhbHVlKCRjKTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgcmV0dXJuICRvYmplY3Q7CiAgICAgICAgfSk7CiAgICB9