public function addByArray(array $services = [])
  {
    if (!empty($services)) {
      foreach ($services as $name => $methods) {
        if (!$this->has($name)) {
          $service = new Service();

          foreach ($methods as $method => $value) {
            if (method_exists($service, $method)) {
              $service->{$method}($value);
            } else {
                throw new ServiceMethodNotExists(sprintf(
                  "Method '%s' does not exists on the %s service.",
                  $method,
                  $name
                ));
              }
          }

          $this->services[$name] = $service;

          continue;
        }

        throw new ServiceAlreadyExists(sprintf(
          "Service '%s' already exists.",
          $name
        ));
      }
    }

    return $this;
  }
public function addByArray(array $services = [])
  {
    if (!empty($services)) {
      foreach ($services as $name => $methods) {
        if (!$this->has($name)) {
          $service = new Service();

          foreach ($methods as $method => $value) {
            if (method_exists($service, $method)) {
              $service->{$method}($value);
            } else {
                throw new ServiceMethodNotExists(sprintf(
                  "Method '%s' does not exists on the %s service.",
                  $method,
                  $name
                ));
              }
          }

          $this->services[$name] = $service;

          continue;
        }

        throw new ServiceAlreadyExists(sprintf(
          "Service '%s' already exists.",
          $name
        ));
      }
    }

    return $this;
  }
public function addByArray ( array $ services = [ ] ) { if ( ! empty ( $ services ) ) { foreach ( $ services as $ name => $ methods ) { if ( ! $ this -> has ( $ name ) ) { $ service = new Service ( ) ; foreach ( $ methods as $ method => $ value ) { if ( method_exists ( $ service , $ method ) ) { $ service -> { $ method } ( $ value ) ; } else { throw new ServiceMethodNotExists ( sprintf ( "Method '%s' does not exists on the %s service." , $ method , $ name ) ) ; } } $ this -> services [ $ name ] = $ service ; continue ; } throw new ServiceAlreadyExists ( sprintf ( "Service '%s' already exists." , $ name ) ) ; } } return $ this ; }
Add services by array

@param array $services

@return $this

@throws ServiceAlreadyExists
@throws ServiceMethodNotExists
Add services by array