Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Previous erasys changes #3

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
29 changes: 26 additions & 3 deletions src/Composer/Autoload/AutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static function autoload(\$class)
file_put_contents($targetDir.'/autoload_files.php', $includeFilesFile);
}
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $classMapAuthoritative));
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $classMapAuthoritative, $autoloads['extensions']));

// use stream_copy_to_stream instead of copy
// to work around https://bugs.php.net/bug.php?id=64634
Expand Down Expand Up @@ -312,11 +312,12 @@ public function parseAutoloads(array $packageMap, PackageInterface $mainPackage)
$psr4 = $this->parseAutoloadsType($packageMap, 'psr-4', $mainPackage);
$classmap = $this->parseAutoloadsType($sortedPackageMap, 'classmap', $mainPackage);
$files = $this->parseAutoloadsType($sortedPackageMap, 'files', $mainPackage);
$extensions = $this->parseExtensions($packageMap, $mainPackage);

krsort($psr0);
krsort($psr4);

return array('psr-0' => $psr0, 'psr-4' => $psr4, 'classmap' => $classmap, 'files' => $files);
return array('psr-0' => $psr0, 'psr-4' => $psr4, 'classmap' => $classmap, 'files' => $files, 'extensions' => $extensions);
}

/**
Expand Down Expand Up @@ -453,7 +454,7 @@ protected function getAutoloadFile($vendorPathToTargetDirCode, $suffix)
AUTOLOAD;
}

protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $classMapAuthoritative)
protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $classMapAuthoritative, $autoloadExtensions)
{
// TODO the class ComposerAutoloaderInit should be revert to a closure
// when APC has been fixed:
Expand Down Expand Up @@ -544,6 +545,14 @@ public static function getLoader()
INCLUDEPATH;
}

if ($autoloadExtensions) {
$autoloadExtensions = var_export($autoloadExtensions, true);
$file .= <<<AUTOLOAD_EXTENSION
\$loader->setAutoloadExtensions($autoloadExtensions);

AUTOLOAD_EXTENSION;
}

if ($targetDirLoader) {
$file .= <<<REGISTER_AUTOLOAD
spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'autoload'), true, true);
Expand Down Expand Up @@ -636,6 +645,20 @@ protected function parseAutoloadsType(array $packageMap, $type, PackageInterface
return $autoloads;
}

protected function parseExtensions(array $packageMap, PackageInterface $mainPackage) {
$extensions = array();

foreach ($packageMap as $item) {
list($package, $installPath) = $item;
foreach ($package->getAutoloadExtensions() as $ext) {
$extensions[$ext] = $ext;
}
}

return array_values($extensions);

}

/**
* Sorts packages by dependency weight
*
Expand Down
104 changes: 75 additions & 29 deletions src/Composer/Autoload/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ClassLoader

private $classMapAuthoritative = false;

private $autoloadExtensions = array();

public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
Expand Down Expand Up @@ -271,6 +273,26 @@ public function isClassMapAuthoritative()
return $this->classMapAuthoritative;
}

/**
* Sets autoload extensions
*
* @param $autoloadExtensions
*/
public function setAutoloadExtensions($autoloadExtensions)
{
$this->autoloadExtensions = $autoloadExtensions;
}

/**
* Returns autoload extensions
*
* @return array
*/
public function getAutoloadExtensions()
{
return $this->autoloadExtensions;
}

/**
* Registers this instance as an autoloader.
*
Expand Down Expand Up @@ -326,13 +348,18 @@ public function findFile($class)
return false;
}

$file = $this->findFileWithExtension($class, '.php');

// Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
// set autoload extensions with a reasonable default
$exts = $this->autoloadExtensions;
if (count($exts) == 0) {
$exts = ['.php'];
// Search for Hack files if we are running on HHVM
if (defined('HHVM_VERSION')) {
$exts[] = '.hh';
}
}

$file = $this->findFileWithExtensions($class, $exts);

if ($file === null) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
Expand All @@ -341,63 +368,82 @@ public function findFile($class)
return $file;
}

private function findFileWithExtension($class, $ext)
private function findFileWithExtensions($class, array $exts)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;

$psr4ClassPath = strtr($class, '\\', DIRECTORY_SEPARATOR);
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;

foreach ($exts as $ext) {
// PSR-4 lookup
$logicalPathPsr4 = $psr4ClassPath . $ext;

if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
}
}
}
}

// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
if (count($this->fallbackDirsPsr4) > 0) {
foreach ($exts as $ext) {
$logicalPathPsr4 = $psr4ClassPath . $ext;
foreach ($this->fallbackDirsPsr4 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
}
}

// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
$psr0ClassPath = substr($psr4ClassPath, 0, $pos + 1)
. strtr(substr($psr4ClassPath, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
$psr0ClassPath = strtr($class, '_', DIRECTORY_SEPARATOR);
}

if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
foreach ($exts as $ext) {
foreach ($dirs as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $psr0ClassPath . $ext)) {
return $file;
}
}
}
}
}
}

// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
if (count($this->fallbackDirsPsr0) > 0) {
foreach ($exts as $ext) {
foreach ($this->fallbackDirsPsr0 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $psr0ClassPath . $ext)) {
return $file;
}
}
}
}

// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
if ($this->useIncludePath) {
foreach ($exts as $ext) {
if ($file = stream_resolve_include_path($psr0ClassPath . $ext)) {
return $file;
}
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Composer/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function configure()
$this
->setName('self-update')
->setAliases(array('selfupdate'))
->setDescription('Updates composer.phar to the latest version.')
->setDescription('Updates composer.phar to the latest version. Do not use in erasys environment!')
->setDefinition(array(
new InputOption('rollback', 'r', InputOption::VALUE_NONE, 'Revert to an older installation of composer'),
new InputOption('clean-backups', null, InputOption::VALUE_NONE, 'Delete old backups during an update. This makes the current version of composer the only backup available after the update'),
Expand All @@ -58,6 +58,9 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->getIO()->writeError('<error>Composer should not be updated with this command in erasys environment.</error>');
return;

$baseUrl = (extension_loaded('openssl') ? 'https' : 'http') . '://' . self::HOMEPAGE;
$config = Factory::createConfig();
$remoteFilesystem = new RemoteFilesystem($this->getIO(), $config);
Expand Down
39 changes: 39 additions & 0 deletions src/Composer/Downloader/Bzip2Downloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of Composer.
*
* (c) Nils Adermann <[email protected]>
* Jordi Boggiano <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Composer\Downloader;

/**
* Downloader for tar.bz2 files
*
* @author Konrad Gibaszewski <[email protected]>
*/
class Bzip2Downloader extends ArchiveDownloader {

/**
* {@inheritDoc}
*/
protected function extract($file, $path) {
try {
exec('tar xfj ' . ' ' . $file . ' -C ' . $path);
} catch (\UnexpectedValueException $e) {
$message = sprintf("Could not extract archive '%s': %s",
$file,
$e->getMessage()
);

throw new \RuntimeException($message, $e->getCode(), $e);
}

}

}
2 changes: 2 additions & 0 deletions src/Composer/Downloader/DownloadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public function update(PackageInterface $initial, PackageInterface $target, $tar

// upgrading from a dist stable package to a dev package, force source reinstall
if ($target->isDev() && 'dist' === $installationSource) {
$this->io->writeError(" <info>Installation source changed from stable to dev, wiping $targetDir</info>");
$downloader->remove($initial, $targetDir);
$this->download($target, $targetDir);

Expand All @@ -254,6 +255,7 @@ public function update(PackageInterface $initial, PackageInterface $target, $tar
$target->setInstallationSource($installationSource);
$downloader->update($initial, $target, $targetDir);
} else {
$this->io->writeError(" <info>Installation type changed from $initialType to $targetType, wiping $targetDir</info>");
$downloader->remove($initial, $targetDir);
$this->download($target, $targetDir, 'source' === $installationSource);
}
Expand Down
38 changes: 27 additions & 11 deletions src/Composer/Downloader/TarDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,35 @@
namespace Composer\Downloader;

/**
* Downloader for tar files: tar, tar.gz or tar.bz2
* Class TarDownloader
*
* Downloader for uncompressed tar files
*
* @author Kirill chEbba Chebunin <[email protected]>
* @author Konrad Gibaszewski <[email protected]>
*
* @package Composer\Downloader
*/
class TarDownloader extends ArchiveDownloader
{
/**
* {@inheritDoc}
*/
protected function extract($file, $path)
{
// Can throw an UnexpectedValueException
$archive = new \PharData($file);
$archive->extractTo($path, null, true);
class TarDownloader extends ArchiveDownloader {

/**
* {@inheritDoc}
*/
protected function extract($file, $path) {

try {
// Unpack from tar
$archive = new \PharData($file);
$archive->extractTo($path, null, true);

} catch (\UnexpectedValueException $e) {
$message = sprintf("Could not unpack from tar archive '%s': %s",
$file,
$e->getMessage()
);

throw new \RuntimeException($message, $e->getCode(), $e);
}
}

}
2 changes: 2 additions & 0 deletions src/Composer/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ public function createDownloadManager(IOInterface $io, Config $config, EventDisp
$dm->setDownloader('zip', new Downloader\ZipDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('rar', new Downloader\RarDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('tar.bz2', new Downloader\Bzip2Downloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('gzip', new Downloader\GzipDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('file', new Downloader\FileDownloader($io, $config, $eventDispatcher, $cache));
Expand All @@ -423,6 +424,7 @@ public function createArchiveManager(Config $config, Downloader\DownloadManager

$am = new Archiver\ArchiveManager($dm);
$am->addArchiver(new Archiver\PharArchiver);
$am->addArchiver(new Archiver\GitArchiver);

return $am;
}
Expand Down
1 change: 1 addition & 0 deletions src/Composer/Installer/LibraryInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ protected function updateCode(PackageInterface $initial, PackageInterface $targe
if (substr($initialDownloadPath, 0, strlen($targetDownloadPath)) === $targetDownloadPath
|| substr($targetDownloadPath, 0, strlen($initialDownloadPath)) === $initialDownloadPath
) {
$this->io->writeError(" <info>Installation download path changed, wiping library directory</info>");
$this->removeCode($initial);
$this->installCode($target);

Expand Down
4 changes: 4 additions & 0 deletions src/Composer/Package/AliasPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ public function getDevAutoload()
{
return $this->aliasOf->getDevAutoload();
}
public function getAutoloadExtensions()
{
return $this->aliasOf->getAutoloadExtensions();
}
public function getIncludePaths()
{
return $this->aliasOf->getIncludePaths();
Expand Down
Loading