public function attach($key, $instance, $type = self::OBJECT)
    {
        switch ($type) {
            case self::OBJECT:
            case self::CACHE:
                if (!is_object($instance)) {
                    throw new \LogicException('Instance is not an object!');
                }
                break;
            case self::DATABASE:
                if (!($instance instanceof \PDO)) {
                    throw new \LogicException();
                }
                break;
        }

        if (isset($this->instances[$key])) {
            return $this;
        }

        $this->instances[$key] = $instance;

        return $this;
    }