public function resolve()
    {
        if ($this->dependencies->count() === 0) {
            return array();
        }

        $resolved = new ArrayObject();
        foreach ($this->findRootNodes() as $rootNode) {
            $this->innerResolve($rootNode, $resolved, new ArrayObject());
        }

        //all resolved?
        if ($resolved->count() !== count($this->nodes)) {
            throw new CircularDependencyException();
        }

        $resolvedElements = array_map(function (DependencyNode $node) {
            return $node->getElement();
        }, $resolved->getArrayCopy());

        return $resolvedElements;
    }