2014-12-08 20:08:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reads a composer.lock file and provides accessors to get
|
|
|
|
|
* its hash and what is installed
|
|
|
|
|
*
|
|
|
|
|
* @since 1.25
|
|
|
|
|
*/
|
|
|
|
|
class ComposerLock {
|
2019-09-11 08:57:15 +00:00
|
|
|
/**
|
|
|
|
|
* @var array[]
|
|
|
|
|
*/
|
|
|
|
|
private $contents;
|
2014-12-08 20:08:52 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $location
|
|
|
|
|
*/
|
|
|
|
|
public function __construct( $location ) {
|
|
|
|
|
$this->contents = json_decode( file_get_contents( $location ), true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Dependencies currently installed according to composer.lock
|
|
|
|
|
*
|
2019-09-11 08:57:15 +00:00
|
|
|
* @return array[]
|
2014-12-08 20:08:52 +00:00
|
|
|
*/
|
|
|
|
|
public function getInstalledDependencies() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$deps = [];
|
2014-12-08 20:08:52 +00:00
|
|
|
foreach ( $this->contents['packages'] as $installed ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$deps[$installed['name']] = [
|
2015-01-03 23:28:02 +00:00
|
|
|
'version' => ComposerJson::normalizeVersion( $installed['version'] ),
|
|
|
|
|
'type' => $installed['type'],
|
2017-10-06 22:17:58 +00:00
|
|
|
'licenses' => $installed['license'] ?? [],
|
|
|
|
|
'authors' => $installed['authors'] ?? [],
|
|
|
|
|
'description' => $installed['description'] ?? '',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-12-08 20:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $deps;
|
|
|
|
|
}
|
|
|
|
|
}
|