protected function buildWithDefinition($id, array $config = [], $definition = null)
    {
        if (\is_string($definition)) {
            if ($definition !== $id) {
                return $this->build($definition, $config);
            }
            $definition = ['__class' => $definition];
        }

        if (\is_array($definition) && !isset($definition[0], $definition[1])) {
            return $this->buildFromConfig($id, array_merge($config, $definition));
        }

        if (\is_callable($definition)) {
            return $definition($this, $config);
        }

        if (\is_object($definition)) {
            return $definition;
        }

        throw new InvalidConfigException('Unexpected object definition type: ' . \gettype($definition));
    }