HosipLan

Untitled

Oct 31st, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. /**
  2.      * @param object $service
  3.      * @param array $options
  4.      * @param array $defaults
  5.      */
  6.     public static function setServiceOptions($service, $options, array $defaults = NULL, array $ignore = NULL)
  7.     {
  8.         $options = Nette\Utils\Arrays::mergeTree((array)$options, $defaults);
  9.  
  10.         // set options
  11.         foreach ($options as $name => $val) {
  12.             $method = 'set' . strtoupper($name[0]) . substr($name, 1);
  13.             if (!method_exists($service, $method) && !in_array($ignore[$name])) {
  14.                 $e = new MemberAccessException("Call to undefined method " . get_class($service) . "::$method().");
  15.                 throw new Nette\InvalidArgumentException("Unknown option $name", NULL, $e);
  16.             }
  17.  
  18.             $service->$method = $val;
  19.         }
  20.     }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment