original_string: public function createService($name, ArrayObject $config = NULL, $merge_into_config = FALSE) {
          if($merge_into_config) {
              $service_config = $this->config->offsetExists($name) ? $this->config->offsetGet($name) : new ArrayObject;
  
              if(is_array($service_config)) {
                  $service_config = ArrayObject::fromArray($service_config);
              }
  
              if($config) {
                  $service_config->merge($config);
              }
          }
          else {
              $service_config = $config ?: new ArrayObject;
          }
  
          if(!$this->hasService($name)) {
              throw new Exception("Service '$name' does not exist.");
          }
  
          $service = $this->services[$name];
  
          if(array_key_exists("classname", $service)) {
              $reflection = new ReflectionClass($service["classname"]);
  
              $params = new ArrayObject($service["params"]);
              $params->merge($service_config);
  
              if($reflection->implementsInterface("Loops\ServiceInterface")) {
                  return call_user_func_array([$service["classname"], "getService" ], [ $params, $this ]);
              }
              else {
                  $params->offsetSet("loops", $this);
                  return Misc::reflectionInstance($service["classname"], $params);
              }
          }
  
          if(array_key_exists("callback", $service)) {
              $params = new ArrayObject($service["params"]);
              $params->merge($service_config);
              return call_user_func_array($service["callback"], $params->toArray());
          }
  
          if(array_key_exists("object", $service)) {
              return $service["object"];
          }
      }
code: public function createService($name, ArrayObject $config = NULL, $merge_into_config = FALSE) {
          if($merge_into_config) {
              $service_config = $this->config->offsetExists($name) ? $this->config->offsetGet($name) : new ArrayObject;
  
              if(is_array($service_config)) {
                  $service_config = ArrayObject::fromArray($service_config);
              }
  
              if($config) {
                  $service_config->merge($config);
              }
          }
          else {
              $service_config = $config ?: new ArrayObject;
          }
  
          if(!$this->hasService($name)) {
              throw new Exception("Service '$name' does not exist.");
          }
  
          $service = $this->services[$name];
  
          if(array_key_exists("classname", $service)) {
              $reflection = new ReflectionClass($service["classname"]);
  
              $params = new ArrayObject($service["params"]);
              $params->merge($service_config);
  
              if($reflection->implementsInterface("Loops\ServiceInterface")) {
                  return call_user_func_array([$service["classname"], "getService" ], [ $params, $this ]);
              }
              else {
                  $params->offsetSet("loops", $this);
                  return Misc::reflectionInstance($service["classname"], $params);
              }
          }
  
          if(array_key_exists("callback", $service)) {
              $params = new ArrayObject($service["params"]);
              $params->merge($service_config);
              return call_user_func_array($service["callback"], $params->toArray());
          }
  
          if(array_key_exists("object", $service)) {
              return $service["object"];
          }
      }
code_tokens: public function createService ( $ name , ArrayObject $ config = NULL , $ merge_into_config = FALSE ) { if ( $ merge_into_config ) { $ service_config = $ this -> config -> offsetExists ( $ name ) ? $ this -> config -> offsetGet ( $ name ) : new ArrayObject ; if ( is_array ( $ service_config ) ) { $ service_config = ArrayObject :: fromArray ( $ service_config ) ; } if ( $ config ) { $ service_config -> merge ( $ config ) ; } } else { $ service_config = $ config ? : new ArrayObject ; } if ( ! $ this -> hasService ( $ name ) ) { throw new Exception ( "Service '$name' does not exist." ) ; } $ service = $ this -> services [ $ name ] ; if ( array_key_exists ( "classname" , $ service ) ) { $ reflection = new ReflectionClass ( $ service [ "classname" ] ) ; $ params = new ArrayObject ( $ service [ "params" ] ) ; $ params -> merge ( $ service_config ) ; if ( $ reflection -> implementsInterface ( "Loops\ServiceInterface" ) ) { return call_user_func_array ( [ $ service [ "classname" ] , "getService" ] , [ $ params , $ this ] ) ; } else { $ params -> offsetSet ( "loops" , $ this ) ; return Misc :: reflectionInstance ( $ service [ "classname" ] , $ params ) ; } } if ( array_key_exists ( "callback" , $ service ) ) { $ params = new ArrayObject ( $ service [ "params" ] ) ; $ params -> merge ( $ service_config ) ; return call_user_func_array ( $ service [ "callback" ] , $ params -> toArray ( ) ) ; } if ( array_key_exists ( "object" , $ service ) ) { return $ service [ "object" ] ; } }
docstring: Creates a new instance of a service
  
  @param $name The service name
  @param array $config
  @return Loops\Service\ServiceInterface The new service
docstring_tokens: Creates a new instance of a service