src/Composer/Command/ShowCommand.php
protected function addTree(
        $name,
        $package,
        RepositoryInterface $installedRepo,
        RepositoryInterface $distantRepos,
        array $packagesInTree
    ) {
        $children = array();
        list($package, $versions) = $this->getPackage(
            $installedRepo,
            $distantRepos,
            $name,
            $package->getPrettyConstraint() === 'self.version' ? $package->getConstraint() : $package->getPrettyConstraint()
        );
        if (is_object($package)) {
            $requires = $package->getRequires();
            ksort($requires);
            foreach ($requires as $requireName => $require) {
                $currentTree = $packagesInTree;

                $treeChildDesc = array(
                    'name' => $requireName,
                    'version' => $require->getPrettyConstraint(),
                );

                if (!in_array($requireName, $currentTree, true)) {
                    $currentTree[] = $requireName;
                    $deepChildren = $this->addTree($requireName, $require, $installedRepo, $distantRepos, $currentTree);
                    if ($deepChildren) {
                        $treeChildDesc['requires'] = $deepChildren;
                    }
                }

                $children[] = $treeChildDesc;
            }
        }

        return $children;
    }
protected function addTree(
        $name,
        $package,
        RepositoryInterface $installedRepo,
        RepositoryInterface $distantRepos,
        array $packagesInTree
    ) {
        $children = array();
        list($package, $versions) = $this->getPackage(
            $installedRepo,
            $distantRepos,
            $name,
            $package->getPrettyConstraint() === 'self.version' ? $package->getConstraint() : $package->getPrettyConstraint()
        );
        if (is_object($package)) {
            $requires = $package->getRequires();
            ksort($requires);
            foreach ($requires as $requireName => $require) {
                $currentTree = $packagesInTree;

                $treeChildDesc = array(
                    'name' => $requireName,
                    'version' => $require->getPrettyConstraint(),
                );

                if (!in_array($requireName, $currentTree, true)) {
                    $currentTree[] = $requireName;
                    $deepChildren = $this->addTree($requireName, $require, $installedRepo, $distantRepos, $currentTree);
                    if ($deepChildren) {
                        $treeChildDesc['requires'] = $deepChildren;
                    }
                }

                $children[] = $treeChildDesc;
            }
        }

        return $children;
    }
protected function addTree ( $ name , $ package , RepositoryInterface $ installedRepo , RepositoryInterface $ distantRepos , array $ packagesInTree ) { $ children = array ( ) ; list ( $ package , $ versions ) = $ this -> getPackage ( $ installedRepo , $ distantRepos , $ name , $ package -> getPrettyConstraint ( ) === 'self.version' ? $ package -> getConstraint ( ) : $ package -> getPrettyConstraint ( ) ) ; if ( is_object ( $ package ) ) { $ requires = $ package -> getRequires ( ) ; ksort ( $ requires ) ; foreach ( $ requires as $ requireName => $ require ) { $ currentTree = $ packagesInTree ; $ treeChildDesc = array ( 'name' => $ requireName , 'version' => $ require -> getPrettyConstraint ( ) , ) ; if ( ! in_array ( $ requireName , $ currentTree , true ) ) { $ currentTree [ ] = $ requireName ; $ deepChildren = $ this -> addTree ( $ requireName , $ require , $ installedRepo , $ distantRepos , $ currentTree ) ; if ( $ deepChildren ) { $ treeChildDesc [ 'requires' ] = $ deepChildren ; } } $ children [ ] = $ treeChildDesc ; } } return $ children ; }
Display a package tree

@param  string                  $name
@param  PackageInterface|string $package
@param  RepositoryInterface     $installedRepo
@param  RepositoryInterface     $distantRepos
@param  array                   $packagesInTree
@return array
Display a package tree