2011-04-17 22:14:44 +00:00
< ? php
/*
* This file is part of Composer .
*
* ( c ) Nils Adermann < naderman @ naderman . de >
* Jordi Boggiano < j . boggiano @ seld . be >
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
namespace Composer\Repository ;
2011-09-20 21:34:06 +00:00
use Composer\Package\Loader\ArrayLoader ;
2012-04-13 00:58:40 +00:00
use Composer\Package\PackageInterface ;
2012-10-13 16:54:48 +00:00
use Composer\Package\AliasPackage ;
2012-08-20 13:44:45 +00:00
use Composer\Package\Version\VersionParser ;
2012-10-13 16:54:48 +00:00
use Composer\DependencyResolver\Pool ;
2011-10-01 13:01:33 +00:00
use Composer\Json\JsonFile ;
2012-04-06 20:39:43 +00:00
use Composer\Cache ;
2012-04-09 14:36:06 +00:00
use Composer\Config ;
2012-03-18 20:04:15 +00:00
use Composer\IO\IOInterface ;
use Composer\Util\RemoteFilesystem ;
2011-04-17 22:14:44 +00:00
/**
* @ author Jordi Boggiano < j . boggiano @ seld . be >
*/
2012-11-29 08:24:28 +00:00
class ComposerRepository extends ArrayRepository implements StreamableRepositoryInterface
2011-04-17 22:14:44 +00:00
{
2012-04-13 00:58:40 +00:00
protected $config ;
2012-10-03 09:56:31 +00:00
protected $options ;
2011-09-20 21:34:06 +00:00
protected $url ;
2012-10-14 14:33:53 +00:00
protected $baseUrl ;
2012-03-18 20:04:15 +00:00
protected $io ;
2013-02-21 15:50:04 +00:00
protected $rfs ;
2012-04-06 20:39:43 +00:00
protected $cache ;
2012-04-13 00:58:40 +00:00
protected $notifyUrl ;
2012-10-14 14:33:53 +00:00
protected $hasProviders = false ;
2013-02-21 15:50:04 +00:00
protected $providersUrl ;
2012-10-14 14:33:53 +00:00
protected $providerListing ;
2012-10-01 11:58:01 +00:00
protected $providers = array ();
protected $providersByUid = array ();
2012-08-20 13:44:45 +00:00
protected $loader ;
2012-10-24 14:11:32 +00:00
protected $rootAliases ;
2013-02-21 16:37:18 +00:00
protected $allowSslDowngrade = false ;
2012-08-24 00:29:03 +00:00
private $rawData ;
private $minimalPackages ;
2012-10-11 19:26:11 +00:00
private $degradedMode = false ;
2012-10-01 11:58:01 +00:00
private $rootData ;
2011-04-17 22:14:44 +00:00
2012-04-09 14:36:06 +00:00
public function __construct ( array $repoConfig , IOInterface $io , Config $config )
2011-04-17 22:14:44 +00:00
{
2012-10-11 18:54:59 +00:00
if ( ! preg_match ( '{^[\w.]+\??://}' , $repoConfig [ 'url' ])) {
2011-12-12 09:57:57 +00:00
// assume http as the default protocol
2012-04-09 14:36:06 +00:00
$repoConfig [ 'url' ] = 'http://' . $repoConfig [ 'url' ];
2011-12-03 11:43:38 +00:00
}
2012-04-09 14:36:06 +00:00
$repoConfig [ 'url' ] = rtrim ( $repoConfig [ 'url' ], '/' );
2012-10-11 18:54:59 +00:00
if ( 'https?' === substr ( $repoConfig [ 'url' ], 0 , 6 )) {
$repoConfig [ 'url' ] = ( extension_loaded ( 'openssl' ) ? 'https' : 'http' ) . substr ( $repoConfig [ 'url' ], 6 );
}
2012-11-05 14:39:43 +00:00
$urlBits = parse_url ( $repoConfig [ 'url' ]);
if ( empty ( $urlBits [ 'scheme' ]) || empty ( $urlBits [ 'host' ])) {
2012-04-09 14:36:06 +00:00
throw new \UnexpectedValueException ( 'Invalid url given for Composer repository: ' . $repoConfig [ 'url' ]);
2011-09-20 21:34:06 +00:00
}
2012-10-03 09:56:31 +00:00
if ( ! isset ( $repoConfig [ 'options' ])) {
$repoConfig [ 'options' ] = array ();
}
2013-02-21 16:37:18 +00:00
if ( isset ( $repoConfig [ 'allow_ssl_downgrade' ]) && true === $repoConfig [ 'allow_ssl_downgrade' ]) {
$this -> allowSslDowngrade = true ;
}
2012-10-03 09:56:31 +00:00
2012-04-13 00:58:40 +00:00
$this -> config = $config ;
2012-10-03 09:56:31 +00:00
$this -> options = $repoConfig [ 'options' ];
2012-04-09 14:36:06 +00:00
$this -> url = $repoConfig [ 'url' ];
2012-10-14 14:33:53 +00:00
$this -> baseUrl = rtrim ( preg_replace ( '{^(.*)(?:/packages.json)?(?:[?#].*)?$}' , '$1' , $this -> url ), '/' );
2012-03-18 20:04:15 +00:00
$this -> io = $io ;
2013-02-21 15:50:04 +00:00
$this -> cache = new Cache ( $io , $config -> get ( 'cache-repo-dir' ) . '/' . preg_replace ( '{[^a-z0-9.]}i' , '-' , $this -> url ), 'a-z0-9.$' );
2012-08-20 13:44:45 +00:00
$this -> loader = new ArrayLoader ();
2013-02-21 15:50:04 +00:00
$this -> rfs = new RemoteFilesystem ( $this -> io , $this -> options );
2011-04-17 22:14:44 +00:00
}
2012-10-24 14:11:32 +00:00
public function setRootAliases ( array $rootAliases )
{
$this -> rootAliases = $rootAliases ;
}
2012-08-22 15:47:05 +00:00
/**
* { @ inheritDoc }
*/
2012-08-20 13:44:45 +00:00
public function getMinimalPackages ()
{
if ( isset ( $this -> minimalPackages )) {
return $this -> minimalPackages ;
}
2012-08-24 00:29:03 +00:00
if ( null === $this -> rawData ) {
$this -> rawData = $this -> loadDataFromServer ();
}
2012-08-20 13:44:45 +00:00
$this -> minimalPackages = array ();
$versionParser = new VersionParser ;
2012-08-24 00:29:03 +00:00
foreach ( $this -> rawData as $package ) {
2012-08-20 13:44:45 +00:00
$version = ! empty ( $package [ 'version_normalized' ]) ? $package [ 'version_normalized' ] : $versionParser -> normalize ( $package [ 'version' ]);
$data = array (
'name' => strtolower ( $package [ 'name' ]),
'repo' => $this ,
'version' => $version ,
'raw' => $package ,
);
if ( ! empty ( $package [ 'replace' ])) {
$data [ 'replace' ] = $package [ 'replace' ];
}
if ( ! empty ( $package [ 'provide' ])) {
$data [ 'provide' ] = $package [ 'provide' ];
}
2012-08-22 12:20:43 +00:00
// add branch aliases
2012-08-22 14:35:22 +00:00
if ( $aliasNormalized = $this -> loader -> getBranchAlias ( $package )) {
$data [ 'alias' ] = preg_replace ( '{(\.9{7})+}' , '.x' , $aliasNormalized );
$data [ 'alias_normalized' ] = $aliasNormalized ;
2012-08-22 12:20:43 +00:00
}
2012-08-20 13:44:45 +00:00
$this -> minimalPackages [] = $data ;
}
return $this -> minimalPackages ;
}
2012-08-23 17:16:23 +00:00
/**
* { @ inheritDoc }
*/
public function filterPackages ( $callback , $class = 'Composer\Package\Package' )
{
2012-08-24 00:29:03 +00:00
if ( null === $this -> rawData ) {
$this -> rawData = $this -> loadDataFromServer ();
}
2012-08-23 17:16:23 +00:00
2012-08-24 00:29:03 +00:00
foreach ( $this -> rawData as $package ) {
2012-09-08 00:00:02 +00:00
if ( false === call_user_func ( $callback , $package = $this -> createPackage ( $package , $class ))) {
2012-08-23 17:16:23 +00:00
return false ;
}
if ( $package -> getAlias ()) {
2012-09-06 06:12:28 +00:00
if ( false === call_user_func ( $callback , $this -> createAliasPackage ( $package ))) {
2012-08-23 17:16:23 +00:00
return false ;
}
}
}
return true ;
}
2012-08-22 15:47:05 +00:00
/**
* { @ inheritDoc }
*/
public function loadPackage ( array $data )
2012-08-20 13:44:45 +00:00
{
2012-09-08 00:00:02 +00:00
$package = $this -> createPackage ( $data [ 'raw' ], 'Composer\Package\Package' );
2012-08-22 12:20:43 +00:00
$package -> setRepository ( $this );
2012-08-20 13:44:45 +00:00
return $package ;
}
2012-08-22 15:47:05 +00:00
/**
* { @ inheritDoc }
*/
public function loadAliasPackage ( array $data , PackageInterface $aliasOf )
{
$aliasPackage = $this -> createAliasPackage ( $aliasOf , $data [ 'version' ], $data [ 'alias' ]);
$aliasPackage -> setRepository ( $this );
return $aliasPackage ;
}
2012-10-01 11:58:01 +00:00
public function hasProviders ()
{
$this -> loadRootServerFile ();
2012-10-14 14:33:53 +00:00
return $this -> hasProviders ;
2012-10-01 11:58:01 +00:00
}
2012-10-18 10:57:55 +00:00
public function resetPackageIds ()
{
foreach ( $this -> providersByUid as $package ) {
2012-10-22 12:28:55 +00:00
if ( $package instanceof AliasPackage ) {
$package -> getAliasOf () -> setId ( - 1 );
}
2012-10-18 10:57:55 +00:00
$package -> setId ( - 1 );
}
}
2012-10-13 16:54:48 +00:00
public function whatProvides ( Pool $pool , $name )
2012-10-01 11:58:01 +00:00
{
2012-10-14 14:33:53 +00:00
// skip platform packages
2012-10-13 15:18:47 +00:00
if ( $name === 'php' || in_array ( substr ( $name , 0 , 4 ), array ( 'ext-' , 'lib-' ), true ) || $name === '__root__' ) {
return array ();
}
2012-10-01 11:58:01 +00:00
if ( isset ( $this -> providers [ $name ])) {
return $this -> providers [ $name ];
}
2012-10-14 14:33:53 +00:00
if ( null === $this -> providerListing ) {
$this -> loadProviderListings ( $this -> loadRootServerFile ());
}
2012-10-01 11:58:01 +00:00
2013-02-21 15:50:04 +00:00
if ( $this -> providersUrl ) {
// package does not exist in this repo
if ( ! isset ( $this -> providerListing [ $name ])) {
return array ();
}
2012-10-14 14:33:53 +00:00
2013-02-21 15:50:04 +00:00
$hash = $this -> providerListing [ $name ][ 'sha256' ];
$url = str_replace ( array ( '%package%' , '%hash%' ), array ( $name , $hash ), $this -> providersUrl );
$cacheKey = 'provider-' . strtr ( $name , '/' , '$' ) . '.json' ;
} else {
// BC handling for old providers-includes
$url = 'p/' . $name . '.json' ;
// package does not exist in this repo
if ( ! isset ( $this -> providerListing [ $url ])) {
return array ();
}
$hash = $this -> providerListing [ $url ][ 'sha256' ];
$cacheKey = null ;
2012-10-14 14:33:53 +00:00
}
2013-02-21 15:50:04 +00:00
if ( $this -> cache -> sha256 ( $cacheKey ) === $hash ) {
$packages = json_decode ( $this -> cache -> read ( $cacheKey ), true );
2012-10-14 14:33:53 +00:00
} else {
2013-02-21 15:50:04 +00:00
$packages = $this -> fetchFile ( $url , $cacheKey , $hash );
2012-10-01 11:58:01 +00:00
}
$this -> providers [ $name ] = array ();
2012-10-13 16:54:48 +00:00
foreach ( $packages [ 'packages' ] as $versions ) {
2012-10-01 11:58:01 +00:00
foreach ( $versions as $version ) {
2012-10-13 16:54:48 +00:00
// avoid loading the same objects twice
2012-10-01 11:58:01 +00:00
if ( isset ( $this -> providersByUid [ $version [ 'uid' ]])) {
2012-10-13 16:54:48 +00:00
// skip if already assigned
if ( ! isset ( $this -> providers [ $name ][ $version [ 'uid' ]])) {
// expand alias in two packages
if ( $this -> providersByUid [ $version [ 'uid' ]] instanceof AliasPackage ) {
$this -> providers [ $name ][ $version [ 'uid' ]] = $this -> providersByUid [ $version [ 'uid' ]] -> getAliasOf ();
$this -> providers [ $name ][ $version [ 'uid' ] . '-alias' ] = $this -> providersByUid [ $version [ 'uid' ]];
} else {
$this -> providers [ $name ][ $version [ 'uid' ]] = $this -> providersByUid [ $version [ 'uid' ]];
}
2012-10-24 14:11:32 +00:00
// check for root aliases
if ( isset ( $this -> providersByUid [ $version [ 'uid' ] . '-root' ])) {
$this -> providers [ $name ][ $version [ 'uid' ] . '-root' ] = $this -> providersByUid [ $version [ 'uid' ] . '-root' ];
}
2012-10-13 16:54:48 +00:00
}
2012-10-01 11:58:01 +00:00
} else {
2012-10-30 21:17:58 +00:00
if ( ! $pool -> isPackageAcceptable ( strtolower ( $version [ 'name' ]), VersionParser :: parseStability ( $version [ 'version' ]))) {
2012-10-13 16:54:48 +00:00
continue ;
}
// load acceptable packages in the providers
2012-10-01 11:58:01 +00:00
$package = $this -> createPackage ( $version , 'Composer\Package\Package' );
$package -> setRepository ( $this );
2012-10-13 16:54:48 +00:00
$this -> providers [ $name ][ $version [ 'uid' ]] = $package ;
2012-10-01 11:58:01 +00:00
$this -> providersByUid [ $version [ 'uid' ]] = $package ;
if ( $package -> getAlias ()) {
$alias = $this -> createAliasPackage ( $package );
2012-10-13 15:19:06 +00:00
$alias -> setRepository ( $this );
2012-10-01 11:58:01 +00:00
2012-10-13 16:54:48 +00:00
$this -> providers [ $name ][ $version [ 'uid' ] . '-alias' ] = $alias ;
// override provider with its alias so it can be expanded in the if block above
2012-10-01 11:58:01 +00:00
$this -> providersByUid [ $version [ 'uid' ]] = $alias ;
}
2012-10-24 14:11:32 +00:00
// handle root package aliases
unset ( $rootAliasData );
if ( isset ( $this -> rootAliases [ $name ][ $package -> getVersion ()])) {
$rootAliasData = $this -> rootAliases [ $name ][ $package -> getVersion ()];
} elseif (( $aliasNormalized = $package -> getAlias ()) && isset ( $this -> rootAliases [ $name ][ $aliasNormalized ])) {
$rootAliasData = $this -> rootAliases [ $name ][ $aliasNormalized ];
}
if ( isset ( $rootAliasData )) {
$alias = $this -> createAliasPackage ( $package , $rootAliasData [ 'alias_normalized' ], $rootAliasData [ 'alias' ]);
$alias -> setRepository ( $this );
$this -> providers [ $name ][ $version [ 'uid' ] . '-root' ] = $alias ;
$this -> providersByUid [ $version [ 'uid' ] . '-root' ] = $alias ;
}
2012-10-01 11:58:01 +00:00
}
}
}
return $this -> providers [ $name ];
}
2012-08-22 15:47:05 +00:00
/**
* { @ inheritDoc }
*/
2011-04-17 22:14:44 +00:00
protected function initialize ()
{
parent :: initialize ();
2012-04-06 20:39:43 +00:00
2012-08-20 13:44:45 +00:00
$repoData = $this -> loadDataFromServer ();
foreach ( $repoData as $package ) {
2012-09-08 00:00:02 +00:00
$this -> addPackage ( $this -> createPackage ( $package , 'Composer\Package\CompletePackage' ));
2012-08-20 13:44:45 +00:00
}
}
2012-10-01 11:58:01 +00:00
protected function loadRootServerFile ()
2012-08-20 13:44:45 +00:00
{
2012-10-01 11:58:01 +00:00
if ( null !== $this -> rootData ) {
return $this -> rootData ;
}
2012-07-20 08:27:02 +00:00
if ( ! extension_loaded ( 'openssl' ) && 'https' === substr ( $this -> url , 0 , 5 )) {
throw new \RuntimeException ( 'You must enable the openssl extension in your php.ini to load information from ' . $this -> url );
}
2012-10-11 19:26:11 +00:00
$jsonUrlParts = parse_url ( $this -> url );
2012-08-29 13:12:08 +00:00
2012-10-11 19:26:11 +00:00
if ( isset ( $jsonUrlParts [ 'path' ]) && false !== strpos ( $jsonUrlParts [ 'path' ], '/packages.json' )) {
$jsonUrl = $this -> url ;
} else {
$jsonUrl = $this -> url . '/packages.json' ;
}
2012-04-13 00:58:40 +00:00
2012-10-11 19:26:11 +00:00
$data = $this -> fetchFile ( $jsonUrl , 'packages.json' );
2013-02-21 16:37:18 +00:00
if ( $this -> allowSslDowngrade ) {
$this -> url = str_replace ( 'https://' , 'http://' , $this -> url );
}
2012-04-13 00:58:40 +00:00
2013-02-21 15:50:04 +00:00
// TODO remove this BC notify_batch support
2012-11-28 17:44:49 +00:00
if ( ! empty ( $data [ 'notify_batch' ])) {
2013-02-21 15:50:04 +00:00
$notifyBatchUrl = $data [ 'notify_batch' ];
}
if ( ! empty ( $data [ 'notify-batch' ])) {
$notifyBatchUrl = $data [ 'notify-batch' ];
}
if ( ! empty ( $notifyBatchUrl )) {
if ( '/' === $notifyBatchUrl [ 0 ]) {
$this -> notifyUrl = preg_replace ( '{(https?://[^/]+).*}i' , '$1' . $notifyBatchUrl , $this -> url );
2012-11-28 17:44:49 +00:00
} else {
2013-02-21 15:50:04 +00:00
$this -> notifyUrl = $notifyBatchUrl ;
2012-11-28 17:44:49 +00:00
}
}
if ( ! $this -> notifyUrl && ! empty ( $data [ 'notify' ])) {
2012-10-11 19:26:11 +00:00
if ( '/' === $data [ 'notify' ][ 0 ]) {
$this -> notifyUrl = preg_replace ( '{(https?://[^/]+).*}i' , '$1' . $data [ 'notify' ], $this -> url );
2012-04-06 20:39:43 +00:00
} else {
2012-10-11 19:26:11 +00:00
$this -> notifyUrl = $data [ 'notify' ];
2012-04-06 20:39:43 +00:00
}
}
2012-04-06 18:40:31 +00:00
2013-02-21 15:50:04 +00:00
if ( ! empty ( $data [ 'providers-url' ])) {
if ( '/' === $data [ 'providers-url' ][ 0 ]) {
$this -> providersUrl = preg_replace ( '{(https?://[^/]+).*}i' , '$1' . $data [ 'providers-url' ], $this -> url );
} else {
$this -> providersUrl = $data [ 'providers-url' ];
}
$this -> hasProviders = true ;
}
2012-10-14 14:33:53 +00:00
if ( ! empty ( $data [ 'providers' ]) || ! empty ( $data [ 'providers-includes' ])) {
$this -> hasProviders = true ;
2012-10-01 11:58:01 +00:00
}
return $this -> rootData = $data ;
}
protected function loadDataFromServer ()
{
$data = $this -> loadRootServerFile ();
2012-08-20 13:44:45 +00:00
return $this -> loadIncludes ( $data );
2012-04-06 18:40:31 +00:00
}
2012-10-14 14:33:53 +00:00
protected function loadProviderListings ( $data )
{
if ( isset ( $data [ 'providers' ])) {
if ( ! is_array ( $this -> providerListing )) {
$this -> providerListing = array ();
}
$this -> providerListing = array_merge ( $this -> providerListing , $data [ 'providers' ]);
}
2013-02-21 15:50:04 +00:00
if ( $this -> providersUrl && isset ( $data [ 'provider-includes' ])) {
$includes = $data [ 'provider-includes' ];
} elseif ( isset ( $data [ 'providers-includes' ])) {
// BC layer for old-style providers-includes
$includes = $data [ 'providers-includes' ];
}
if ( ! empty ( $includes )) {
foreach ( $includes as $include => $metadata ) {
2012-10-14 14:33:53 +00:00
if ( $this -> cache -> sha256 ( $include ) === $metadata [ 'sha256' ]) {
$includedData = json_decode ( $this -> cache -> read ( $include ), true );
} else {
2012-10-15 12:37:27 +00:00
$includedData = $this -> fetchFile ( $include , null , $metadata [ 'sha256' ]);
2012-10-14 14:33:53 +00:00
}
$this -> loadProviderListings ( $includedData );
}
}
}
2012-08-20 13:44:45 +00:00
protected function loadIncludes ( $data )
2012-04-06 18:40:31 +00:00
{
2012-08-20 13:44:45 +00:00
$packages = array ();
2012-04-06 18:40:31 +00:00
// legacy repo handling
if ( ! isset ( $data [ 'packages' ]) && ! isset ( $data [ 'includes' ])) {
foreach ( $data as $pkg ) {
foreach ( $pkg [ 'versions' ] as $metadata ) {
2012-08-20 13:44:45 +00:00
$packages [] = $metadata ;
2012-04-06 18:40:31 +00:00
}
}
2012-10-22 20:40:32 +00:00
return $packages ;
2011-04-17 22:14:44 +00:00
}
2012-04-06 18:40:31 +00:00
if ( isset ( $data [ 'packages' ])) {
foreach ( $data [ 'packages' ] as $package => $versions ) {
foreach ( $versions as $version => $metadata ) {
2012-08-20 13:44:45 +00:00
$packages [] = $metadata ;
2012-04-06 18:40:31 +00:00
}
}
2012-04-06 17:56:34 +00:00
}
2012-04-06 18:40:31 +00:00
if ( isset ( $data [ 'includes' ])) {
foreach ( $data [ 'includes' ] as $include => $metadata ) {
2012-04-06 20:39:43 +00:00
if ( $this -> cache -> sha1 ( $include ) === $metadata [ 'sha1' ]) {
$includedData = json_decode ( $this -> cache -> read ( $include ), true );
} else {
2012-10-11 19:26:11 +00:00
$includedData = $this -> fetchFile ( $include );
2012-04-06 20:39:43 +00:00
}
2012-08-20 13:44:45 +00:00
$packages = array_merge ( $packages , $this -> loadIncludes ( $includedData ));
2011-10-29 05:43:26 +00:00
}
2011-04-23 18:52:37 +00:00
}
2012-08-20 13:44:45 +00:00
return $packages ;
2011-04-23 18:52:37 +00:00
}
2012-09-08 00:00:02 +00:00
protected function createPackage ( array $data , $class )
{
try {
2012-11-29 08:24:28 +00:00
$data [ 'notification-url' ] = $this -> notifyUrl ;
2012-09-08 00:00:02 +00:00
return $this -> loader -> load ( $data , 'Composer\Package\CompletePackage' );
} catch ( \Exception $e ) {
2012-09-08 11:49:37 +00:00
throw new \RuntimeException ( 'Could not load package ' . ( isset ( $data [ 'name' ]) ? $data [ 'name' ] : json_encode ( $data )) . ' in ' . $this -> url . ': [' . get_class ( $e ) . '] ' . $e -> getMessage (), 0 , $e );
2012-09-08 00:00:02 +00:00
}
}
2012-10-11 19:26:11 +00:00
2012-10-15 12:37:27 +00:00
protected function fetchFile ( $filename , $cacheKey = null , $sha256 = null )
2012-10-11 19:26:11 +00:00
{
if ( ! $cacheKey ) {
$cacheKey = $filename ;
2012-10-14 14:33:53 +00:00
$filename = $this -> baseUrl . '/' . $filename ;
2012-10-11 19:26:11 +00:00
}
$retries = 3 ;
while ( $retries -- ) {
try {
2013-02-21 15:50:04 +00:00
$json = $this -> rfs -> getContents ( $filename , $filename , false );
if ( $sha256 && $sha256 !== hash ( 'sha256' , $json )) {
2012-10-21 14:10:47 +00:00
if ( $retries ) {
usleep ( 100 );
continue ;
}
2013-02-21 16:07:53 +00:00
// TODO use scarier wording once we know for sure it doesn't do false positives anymore
throw new RepositorySecurityException ( 'The contents of ' . $filename . ' do not match its signature. This should indicate a man-in-the-middle attack. Try running composer again and report this if you think it is a mistake.' );
2012-10-15 12:37:27 +00:00
}
2013-02-21 15:50:04 +00:00
$data = JsonFile :: parseJson ( $json , $filename );
$this -> cache -> write ( $cacheKey , $json );
2012-10-11 19:26:11 +00:00
break ;
} catch ( \Exception $e ) {
2013-02-21 17:16:54 +00:00
if ( $retries ) {
usleep ( 100 );
continue ;
}
2013-02-21 16:41:38 +00:00
if ( $e instanceof RepositorySecurityException ) {
throw $e ;
}
2013-02-21 17:16:54 +00:00
if ( $contents = $this -> cache -> read ( $cacheKey )) {
if ( ! $this -> degradedMode ) {
$this -> io -> write ( '<warning>' . $e -> getMessage () . '</warning>' );
$this -> io -> write ( '<warning>' . $this -> url . ' could not be fully loaded, package information was loaded from the local cache and may be out of date</warning>' );
2012-10-11 19:26:11 +00:00
}
2013-02-21 17:16:54 +00:00
$this -> degradedMode = true ;
$data = JsonFile :: parseJson ( $contents , $this -> cache -> getRoot () . $cacheKey );
2012-10-11 19:35:51 +00:00
2013-02-21 17:16:54 +00:00
break ;
2012-10-11 19:26:11 +00:00
}
2013-02-21 17:16:54 +00:00
throw $e ;
2012-10-11 19:26:11 +00:00
}
}
return $data ;
}
2011-09-17 11:39:37 +00:00
}