src/Comely/IO/DependencyInjection/DependencyInjectionContainer.php
public function add(string $key, $object)
    {
        $key = self::ProcessKey(__METHOD__, $key);
        $objectType = gettype($object);
        switch ($objectType) {
            case "object":
                $this->repository->push($object, $key);
                return true;
            case "string":
                return $this->service($key)->class($object);
            default:
                throw new DependencyInjectionException(
                    sprintf('Cannot store "%s" in Dependency Injection container', $objectType)
                );
        }
    }
public function add(string $key, $object)
    {
        $key = self::ProcessKey(__METHOD__, $key);
        $objectType = gettype($object);
        switch ($objectType) {
            case "object":
                $this->repository->push($object, $key);
                return true;
            case "string":
                return $this->service($key)->class($object);
            default:
                throw new DependencyInjectionException(
                    sprintf('Cannot store "%s" in Dependency Injection container', $objectType)
                );
        }
    }
public function add ( string $ key , $ object ) { $ key = self :: ProcessKey ( __METHOD__ , $ key ) ; $ objectType = gettype ( $ object ) ; switch ( $ objectType ) { case "object" : $ this -> repository -> push ( $ object , $ key ) ; return true ; case "string" : return $ this -> service ( $ key ) -> class ( $ object ) ; default : throw new DependencyInjectionException ( sprintf ( 'Cannot store "%s" in Dependency Injection container' , $ objectType ) ) ; } }
Store an instance or add new server

If second argument is an instance, it will be stored as-is.

If second argument is a class name (string), it will be added as service
and instance to Service will be returned

@param string $key
@param $object
@return Service|bool
@throws DependencyInjectionException
@throws Exception\RepositoryException
@throws Exception\ServicesException
Store an instance or add new server