Last active
December 17, 2015 17:08
-
-
Save Spir/5643351 to your computer and use it in GitHub Desktop.
Functions to build a Composer depencied tree for Laravel (make use of Laravel app_path() to get the path of the composer/installed files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function buildDependenciesTree() { | |
$composer = json_decode((string)(file_get_contents(app_path().'/../composer.json'))); | |
$installed = json_decode((string)(file_get_contents(app_path().'/../vendor/composer/installed.json'))); | |
$tree = Array(); | |
foreach($composer->require as $lib => $version) { | |
// skip PHP and other non lib requirements | |
if (!is_dir(app_path().'/../vendor/'.$lib)) | |
continue; | |
$tree[] = loadDependencies($installed, $lib); | |
} | |
return $tree; | |
} | |
function loadDependencies($installed, $selected) { | |
$dependencies = Array(); | |
foreach($installed as $dependency) { | |
if (isset($dependency->name) && $dependency->name==$selected && isset($dependency->require) && count($dependency->require)) { | |
$dependencyConf = getDependencyInformations($dependency); | |
foreach($dependency->require as $lib => $version) { | |
// skip PHP and other non lib requirements | |
if (!is_dir(app_path().'/../vendor/'.$lib)) | |
continue; | |
$dependencyConf['require'][] = loadDependencies($installed, $lib); | |
} | |
$dependencies[] = $dependencyConf; | |
} | |
} | |
return $dependencies; | |
} | |
function getDependencyInformations($dependency) { | |
return Array( | |
'name'=> (isset($dependency->name))?$dependency->name:'', | |
'version'=> (isset($dependency->version))?$dependency->version:'', | |
'description'=> (isset($dependency->description))?$dependency->description:'', | |
'require' => Array(), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment