/**
  * Calls the method of this call definition on the passed Service object
  *
  * @param mixed $service
  *
  * @throws InvalidServiceException if the service passed is invalid
  * @throws InvalidServiceCallConfigException if the requested method does not exist
  */
 public function __invoke($service)
 {
     if (!is_object($service)) {
         throw InvalidServiceException::build([], ['service' => $service]);
     }
     $callable = [$service, $this->getMethod()];
     if (!is_callable($callable)) {
         throw InvalidServiceCallConfigException::build([], ['methodName' => $this->getMethod()]);
     }
     $args = $this->getArguments();
     foreach ($args as $arg_i => $arg) {
         if ('@' === substr($arg, 0, 1)) {
             $args[$arg_i] = $this->getService($arg);
         }
     }
     call_user_func_array($callable, $args);
 }
 /**
  *
  * @param array  $config      Config to be checked
  * @param string $serviceName Name of the service checking (for exception)
  *
  * @throws InvalidServiceConfigException if missing class parameters
  * @throws InvalidServiceCallConfigException if the call config is not valid
  */
 protected function validateServiceConfig(array $config, $serviceName)
 {
     $exceptionArgs = ['serviceName' => $serviceName, 'serviceConfig' => $config];
     if (!isset($config['class'])) {
         throw InvalidServiceConfigException::build([], array_merge($exceptionArgs, ['missingParameter' => 'class']));
     }
     if (isset($config['calls'])) {
         if (!is_array($config['calls'])) {
             throw InvalidServiceCallConfigException::build([], array_merge($exceptionArgs, ['callConfig' => $config['calls']]));
         }
         foreach ($config['calls'] as $callConfigIndex => $callConfig) {
             if (!is_array($callConfig)) {
                 throw InvalidServiceCallConfigException::build([], array_merge($exceptionArgs, ['callConfig' => $callConfig, 'callConfigIndex' => $callConfigIndex]));
             }
             if (isset($callConfig[1]) && !is_array($callConfig[1])) {
                 throw InvalidServiceCallConfigException::build([], array_merge($exceptionArgs, ['callConfig' => $callConfig, 'callConfigIndex' => $callConfigIndex, 'invalidArguments' => $callConfig[1]]));
             }
         }
     }
 }