Guest User

Untitled

a guest
Dec 2nd, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. /**
  2.  * Ensure a value or object will remain globally unique
  3.  * @param  string  $key   The value or object name
  4.  * @param  Closure        The closure that defines the object
  5.  * @return mixed
  6.  */
  7. public function singleton($key, $value)
  8. {
  9.     $this->set($key, function ($c) use ($value) {
  10.         static $object;
  11.        
  12.         if (null === $object) {
  13.             $object = $value($c);
  14.         }
  15.  
  16.         return $object;
  17.     });
  18. }
Advertisement
Add Comment
Please, Sign In to add comment