public function set(string $serviceName, $object) {
        if(isset($this->serviceData[$serviceName]) || in_array($serviceName, $this->getSelfReferenceNames())) {
            if($this->replaceExistingServices()) {
                trigger_error("Service $serviceName is already registered", E_USER_NOTICE);
            } else {
                $e = new ServiceException("Service $serviceName is already registered");
                $e->setServiceName($serviceName);
                throw $e;
            }
        }


        if(is_callable($object)) {
            $object = new CallbackContainer($object);
        } elseif (is_array($object)) {
            $object = new ConfiguredServiceContainer($serviceName, $object, $this);
        } elseif(!is_object($object)) {
            throw new ServiceException("Service Manager only allows objects to be service instances!");
        } elseif(!($object instanceof ContainerInterface)) {
            $object = new StaticContainer($object);
        }

        $this->serviceData[$serviceName] = $object;
    }
public function set(string $serviceName, $object) {
        if(isset($this->serviceData[$serviceName]) || in_array($serviceName, $this->getSelfReferenceNames())) {
            if($this->replaceExistingServices()) {
                trigger_error("Service $serviceName is already registered", E_USER_NOTICE);
            } else {
                $e = new ServiceException("Service $serviceName is already registered");
                $e->setServiceName($serviceName);
                throw $e;
            }
        }


        if(is_callable($object)) {
            $object = new CallbackContainer($object);
        } elseif (is_array($object)) {
            $object = new ConfiguredServiceContainer($serviceName, $object, $this);
        } elseif(!is_object($object)) {
            throw new ServiceException("Service Manager only allows objects to be service instances!");
        } elseif(!($object instanceof ContainerInterface)) {
            $object = new StaticContainer($object);
        }

        $this->serviceData[$serviceName] = $object;
    }
public function set ( string $ serviceName , $ object ) { if ( isset ( $ this -> serviceData [ $ serviceName ] ) || in_array ( $ serviceName , $ this -> getSelfReferenceNames ( ) ) ) { if ( $ this -> replaceExistingServices ( ) ) { trigger_error ( "Service $serviceName is already registered" , E_USER_NOTICE ) ; } else { $ e = new ServiceException ( "Service $serviceName is already registered" ) ; $ e -> setServiceName ( $ serviceName ) ; throw $ e ; } } if ( is_callable ( $ object ) ) { $ object = new CallbackContainer ( $ object ) ; } elseif ( is_array ( $ object ) ) { $ object = new ConfiguredServiceContainer ( $ serviceName , $ object , $ this ) ; } elseif ( ! is_object ( $ object ) ) { throw new ServiceException ( "Service Manager only allows objects to be service instances!" ) ; } elseif ( ! ( $ object instanceof ContainerInterface ) ) { $ object = new StaticContainer ( $ object ) ; } $ this -> serviceData [ $ serviceName ] = $ object ; }
Sets a service

Accepted are:
- Objects that implement ContainerInterface, their getInstance method call will be the service instance
- A callback (note! Objects implementing __invoke are also callbacks!) to obtain the service instance
- An array to load configured service
- Any other object directly as service

If replaceExistingServices() returns false, this method call fails with an already registered service.


@param string $serviceName
@param object|callable|ContainerInterface $object
@throws ServiceException
@see ServiceManager::replaceExistingServices()
@see ServiceManager::__get()
Sets a service