Guest User

Untitled

a guest
Jul 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.37 KB | None | 0 0
  1. <?php
  2.  
  3. someFactory(InstanceManager $im, $name, $isShared = false)
  4. {
  5.     // calculate the service
  6.     // ...
  7.     // and do this:
  8.     if ($isShared) {
  9.         $im->set($name, $result);
  10.     }
  11.  
  12.     // or:
  13.     if ($isShared) {
  14.         $this->service = $result;
  15.     }
  16.  
  17.     // and on subsequent calls, return it early:
  18.     if ($this->service) {
  19.         return $this->service;
  20.     }
  21. }
Add Comment
Please, Sign In to add comment