1
0
Fork 0

Add debug info and remove autoload parsing that was too slow

pull/518/head
Jordi Boggiano 2012-04-01 19:54:29 +02:00
parent 4b2283e41c
commit d53ac36636
1 changed files with 20 additions and 72 deletions

View File

@ -120,6 +120,9 @@ class PearRepository extends ArrayRepository
'type' => 'library', 'type' => 'library',
'dist' => array('type' => 'pear', 'url' => $this->url.'/get/'.$packageName.'-'.$pearVersion.".tgz"), 'dist' => array('type' => 'pear', 'url' => $this->url.'/get/'.$packageName.'-'.$pearVersion.".tgz"),
'version' => $pearVersion, 'version' => $pearVersion,
'autoload' => array(
'classmap' => array(''),
),
); );
try { try {
@ -133,20 +136,15 @@ class PearRepository extends ArrayRepository
$packageData += $this->parseDependencies($deps); $packageData += $this->parseDependencies($deps);
// figure out autoload info
try {
$packageInfo = simplexml_load_string($this->rfs->getContents($this->url, $releaseLink . "/package.".$pearVersion.".xml", false));
$packageData += $this->guessAutoload($packageInfo);
} catch (TransportException $e) {
if (strpos($e->getMessage(), '404')) {
continue;
}
throw $e;
}
try { try {
$this->addPackage($loader->load($packageData)); $this->addPackage($loader->load($packageData));
if ($this->io->isVerbose()) {
$this->io->write('Loaded '.$packageData['name'].' '.$packageData['version']);
}
} catch (\UnexpectedValueException $e) { } catch (\UnexpectedValueException $e) {
if ($this->io->isVerbose()) {
$this->io->write('Could not load '.$packageData['name'].' '.$packageData['version'].': '.$e->getMessage());
}
continue; continue;
} }
} }
@ -252,7 +250,10 @@ class PearRepository extends ArrayRepository
$fullName = 'pear-'.$this->channel.'/'.$packageName; $fullName = 'pear-'.$this->channel.'/'.$packageName;
$packageData = array( $packageData = array(
'name' => $fullName, 'name' => $fullName,
'type' => 'library' 'type' => 'library',
'autoload' => array(
'classmap' => array(''),
),
); );
$packageKeys = array('l' => 'license', 'd' => 'description'); $packageKeys = array('l' => 'license', 'd' => 'description');
foreach ($packageKeys as $pear => $composer) { foreach ($packageKeys as $pear => $composer) {
@ -290,75 +291,22 @@ class PearRepository extends ArrayRepository
$releaseData += $depsData[$version]; $releaseData += $depsData[$version];
} }
// figure out autoload info $package = $packageData + $releaseData;
try { try {
$releaseLink = $this->url . "/rest/r/".strtolower($packageName); $this->addPackage($loader->load($package));
$packageInfo = simplexml_load_string($this->rfs->getContents($this->url, $releaseLink . "/package.".$version.".xml", false)); if ($this->io->isVerbose()) {
$packageData += $this->guessAutoload($packageInfo); $this->io->write('Loaded '.$package['name'].' '.$package['version']);
} catch (TransportException $e) {
if (strpos($e->getMessage(), '404')) {
continue;
} }
throw $e;
}
try {
$this->addPackage(
$loader->load($packageData + $releaseData)
);
} catch (\UnexpectedValueException $e) { } catch (\UnexpectedValueException $e) {
// TODO add debug mode with --verbose that outputs those failures if ($this->io->isVerbose()) {
$this->io->write('Could not load '.$package['name'].' '.$package['version'].': '.$e->getMessage());
}
continue; continue;
} }
} }
} }
} }
private function guessAutoload(\SimpleXMLElement $packageInfo)
{
$files = array();
if (count($packageInfo->contents->dir)) {
foreach ($packageInfo->contents->dir as $dir) {
if (count($dir->file)) {
foreach ($dir->file as $file) {
if ('php' !== (string) $file['role']) {
continue;
}
$files[] = ltrim($dir['name'].$file['name'], '/');
}
}
}
}
// reduce to meaningful unique paths
while (true) {
foreach ($files as $key => $file) {
foreach ($files as $key2 => $file2) {
if ($key === $key2) {
continue;
}
if (false !== strpos($file, '/') && dirname($file) === dirname($file2)) {
unset($files[$key2]);
$files[$key] = dirname($file);
continue 3;
}
if (0 === strpos($file2, $file.'/') || $file === $file2) {
unset($files[$key2]);
continue 3;
}
}
}
break;
}
return array(
'autoload' => array(
'classmap' => $files,
),
);
}
/** /**
* @param string $url * @param string $url
* @return DOMDocument * @return DOMDocument