From 9c27e386542ed53d769373189227eba0189a54f0 Mon Sep 17 00:00:00 2001 From: Jordan Alliot Date: Wed, 18 Jan 2012 18:22:02 +0100 Subject: [PATCH 01/28] Moved proxy handling to a new class so that it can be reused in other parts of Composer --- src/Composer/Command/SelfUpdateCommand.php | 7 ++- src/Composer/Downloader/FileDownloader.php | 21 ++------ src/Composer/Json/JsonFile.php | 8 +-- src/Composer/Repository/PearRepository.php | 7 ++- src/Composer/Util/StreamContextFactory.php | 57 ++++++++++++++++++++++ 5 files changed, 74 insertions(+), 26 deletions(-) create mode 100644 src/Composer/Util/StreamContextFactory.php diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 50ad96c6d..febc78295 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -13,6 +13,7 @@ namespace Composer\Command; use Composer\Composer; +use Composer\Util\StreamContextFactory; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -39,7 +40,9 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { - $latest = trim(file_get_contents('http://getcomposer.org/version')); + $ctx = StreamContextFactory::getContext(); + + $latest = trim(file_get_contents('http://getcomposer.org/version'), false, $ctx); if (Composer::VERSION !== $latest) { $output->writeln(sprintf("Updating to version %s.", $latest)); @@ -47,7 +50,7 @@ EOT $remoteFilename = 'http://getcomposer.org/composer.phar'; $localFilename = $_SERVER['argv'][0]; - file_put_contents($localFilename, file_get_contents($remoteFilename)); + copy($remoteFilename, $localFilename, $ctx); } else { $output->writeln("You are using the latest composer version."); } diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index f74ef89dd..10e63806b 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -13,6 +13,7 @@ namespace Composer\Downloader; use Composer\IO\IOInterface; use Composer\Package\PackageInterface; +use Composer\Util\StreamContextFactory; /** * Base downloader for file packages @@ -77,30 +78,14 @@ abstract class FileDownloader implements DownloaderInterface } } - // Handle system proxy - $params = array('http' => array()); - - if (isset($_SERVER['HTTP_PROXY'])) { - // http(s):// is not supported in proxy - $proxy = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $_SERVER['HTTP_PROXY']); - - if (0 === strpos($proxy, 'ssl:') && !extension_loaded('openssl')) { - throw new \RuntimeException('You must enable the openssl extension to use a proxy over https'); - } - - $params['http'] = array( - 'proxy' => $proxy, - 'request_fulluri' => true, - ); - } + $ctx = StreamContextFactory::getContext(); if ($this->io->hasAuthorization($package->getSourceUrl())) { $auth = $this->io->getAuthorization($package->getSourceUrl()); $authStr = base64_encode($auth['username'] . ':' . $auth['password']); - $params['http'] = array_merge($params['http'], array('header' => "Authorization: Basic $authStr\r\n")); + stream_context_set_option($ctx, 'http', 'header', "Authorization: Basic $authStr\r\n"); } - $ctx = stream_context_create($params); stream_context_set_params($ctx, array("notification" => array($this, 'callbackGet'))); $this->io->overwrite(" Downloading: connection...", false); diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index fd43c9148..00baf5f40 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -14,6 +14,7 @@ namespace Composer\Json; use Composer\Repository\RepositoryManager; use Composer\Composer; +use Composer\Util\StreamContextFactory; /** * Reads/writes json files. @@ -59,11 +60,10 @@ class JsonFile */ public function read() { - $context = stream_context_create(array( - 'http' => array('header' => 'User-Agent: Composer/'.Composer::VERSION."\r\n") - )); + $ctx = StreamContextFactory::getContext(); + stream_context_set_option($ctx, 'http', 'header', 'User-Agent: Composer/'.Composer::VERSION."\r\n"); - $json = file_get_contents($this->path, false, $context); + $json = file_get_contents($this->path, false, $ctx); if (!$json) { throw new \RuntimeException('Could not read '.$this->path.', you are probably offline'); } diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 0e00a39c7..76267ff3c 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -13,6 +13,7 @@ namespace Composer\Repository; use Composer\Package\Loader\ArrayLoader; +use Composer\Util\StreamContextFactory; /** * @author Benjamin Eberlei @@ -87,7 +88,8 @@ class PearRepository extends ArrayRepository ); try { - $deps = file_get_contents($releaseLink . "/deps.".$pearVersion.".txt"); + $ctx = StreamContextFactory::getContext(); + $deps = file_get_contents($releaseLink.'/deps.'.$pearVersion.'.txt', false, $ctx); } catch (\ErrorException $e) { if (strpos($e->getMessage(), '404')) { continue; @@ -132,7 +134,8 @@ class PearRepository extends ArrayRepository */ private function requestXml($url) { - $content = file_get_contents($url); + $ctx = StreamContextFactory::getContext(); + $content = file_get_contents($url, false, $ctx); if (!$content) { throw new \UnexpectedValueException('The PEAR channel at '.$url.' did not respond.'); } diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php new file mode 100644 index 000000000..d32236a83 --- /dev/null +++ b/src/Composer/Util/StreamContextFactory.php @@ -0,0 +1,57 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Util; + +/** + * Allows the creation of a basic context supporting http proxy + * + * @author Jordan Alliot + */ +final class StreamContextFactory +{ + private static $context; + + /** + * Creates a context supporting HTTP proxies + * + * @return resource Default context + * @throws \RuntimeException if https proxy required and OpenSSL uninstalled + */ + public static function getContext() + { + if (null !== self::$context) { + return self::$context; + } + + // Handle system proxy + $params = array('http' => array()); + + if (isset($_SERVER['HTTP_PROXY']) || isset($_SERVER['http_proxy'])) { + // Some systems seem to rely on a lowercased version instead... + $proxy = isset($_SERVER['HTTP_PROXY']) ? $_SERVER['HTTP_PROXY'] : $_SERVER['http_proxy']; + + // http(s):// is not supported in proxy + $proxy = str_replace(array('http://', 'https://'), array('tcp://', 'ssl://'), $proxy); + + if (0 === strpos($proxy, 'ssl:') && !extension_loaded('openssl')) { + throw new \RuntimeException('You must enable the openssl extension to use a proxy over https'); + } + + $params['http'] = array( + 'proxy' => $proxy, + 'request_fulluri' => true, + ); + } + + return self::$context = stream_context_create($params); + } +} \ No newline at end of file From 054faef5eb60fba87d21b18d586be89a787b5a17 Mon Sep 17 00:00:00 2001 From: Jordan Alliot Date: Wed, 18 Jan 2012 19:15:13 +0100 Subject: [PATCH 02/28] New context at each call and possibility to add more options and params to the context --- src/Composer/Downloader/FileDownloader.php | 7 +++---- src/Composer/Json/JsonFile.php | 6 ++++-- src/Composer/Util/StreamContextFactory.php | 19 ++++++++----------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 10e63806b..189e76f59 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -78,15 +78,14 @@ abstract class FileDownloader implements DownloaderInterface } } - $ctx = StreamContextFactory::getContext(); - + $options = array(); if ($this->io->hasAuthorization($package->getSourceUrl())) { $auth = $this->io->getAuthorization($package->getSourceUrl()); $authStr = base64_encode($auth['username'] . ':' . $auth['password']); - stream_context_set_option($ctx, 'http', 'header', "Authorization: Basic $authStr\r\n"); + $options['http']['header'] = "Authorization: Basic $authStr\r\n"; } - stream_context_set_params($ctx, array("notification" => array($this, 'callbackGet'))); + $ctx = StreamContextFactory::getContext($options, array('notification' => array($this, 'callbackGet'))); $this->io->overwrite(" Downloading: connection...", false); @copy($url, $fileName, $ctx); diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 00baf5f40..0c585216d 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -60,8 +60,10 @@ class JsonFile */ public function read() { - $ctx = StreamContextFactory::getContext(); - stream_context_set_option($ctx, 'http', 'header', 'User-Agent: Composer/'.Composer::VERSION."\r\n"); + $ctx = StreamContextFactory::getContext(array( + 'http' => array( + 'header' => 'User-Agent: Composer/'.Composer::VERSION."\r\n" + ))); $json = file_get_contents($this->path, false, $ctx); if (!$json) { diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index d32236a83..8b452482d 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -1,4 +1,5 @@ array()); + $options = array_merge(array('http' => array()), $options); + // Handle system proxy if (isset($_SERVER['HTTP_PROXY']) || isset($_SERVER['http_proxy'])) { // Some systems seem to rely on a lowercased version instead... $proxy = isset($_SERVER['HTTP_PROXY']) ? $_SERVER['HTTP_PROXY'] : $_SERVER['http_proxy']; @@ -46,12 +43,12 @@ final class StreamContextFactory throw new \RuntimeException('You must enable the openssl extension to use a proxy over https'); } - $params['http'] = array( + $options['http'] = array( 'proxy' => $proxy, 'request_fulluri' => true, ); } - return self::$context = stream_context_create($params); + return stream_context_create($options, $params); } } \ No newline at end of file From 468eb0ed8d404be2c41cb0541133c06f85f30d2b Mon Sep 17 00:00:00 2001 From: Jordan Alliot Date: Fri, 20 Jan 2012 04:35:20 -0800 Subject: [PATCH 03/28] Merge default options after buildind proxy one --- src/Composer/Util/StreamContextFactory.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index 8b452482d..8ca3ccd69 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -22,14 +22,14 @@ final class StreamContextFactory /** * Creates a context supporting HTTP proxies * - * @param array $options Options to merge with the default - * @param array $params Parameters to specify on the context + * @param array $defaultOptions Options to merge with the default + * @param array $defaultParams Parameters to specify on the context * @return resource Default context * @throws \RuntimeException if https proxy required and OpenSSL uninstalled */ - static public function getContext(array $options = array(), array $params = array()) + static public function getContext(array $defaultOptions = array(), array $defaultParams = array()) { - $options = array_merge(array('http' => array()), $options); + $options = array('http' => array()); // Handle system proxy if (isset($_SERVER['HTTP_PROXY']) || isset($_SERVER['http_proxy'])) { @@ -48,7 +48,9 @@ final class StreamContextFactory 'request_fulluri' => true, ); } + + $options = array_merge($options, $defaultOptions); - return stream_context_create($options, $params); + return stream_context_create($options, $defaultParams); } -} \ No newline at end of file +} From b4d87af9592b65ecfd2336cfe04655dad84a09d8 Mon Sep 17 00:00:00 2001 From: Jordan Alliot Date: Sat, 21 Jan 2012 16:29:17 +0100 Subject: [PATCH 04/28] Changed array_merge to array_merge_recursive --- src/Composer/Util/StreamContextFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index 8ca3ccd69..4ea31da4d 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -49,7 +49,7 @@ final class StreamContextFactory ); } - $options = array_merge($options, $defaultOptions); + $options = array_merge_recursive($options, $defaultOptions); return stream_context_create($options, $defaultParams); } From 14adc0213e7d60b2e3b26da281a3b4bbe15614db Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 14:53:38 -0200 Subject: [PATCH 05/28] Added suport for PEAR2 repositories. --- src/Composer/Repository/PearRepository.php | 239 +++++++++++++++------ 1 file changed, 179 insertions(+), 60 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 51c1722b4..496950af5 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -31,7 +31,7 @@ class PearRepository extends ArrayRepository throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$config['url']); } - $this->url = $config['url']; + $this->url = preg_replace('#^(.+)/+$#U', '$1', $config['url']); } protected function initialize() @@ -51,24 +51,62 @@ class PearRepository extends ArrayRepository $categories = $categoryXML->getElementsByTagName("c"); foreach ($categories as $category) { - $categoryLink = $category->getAttribute("xlink:href"); - $categoryLink = str_replace("info.xml", "packages.xml", $categoryLink); - if ('/' !== substr($categoryLink, 0, 1)) { - $categoryLink = '/' . $categoryLink; + $link = $category->getAttribute("xlink:href"); + try { + $packagesLink = str_replace("info.xml", "packagesinfo.xml", $link); + $this->fetchPear2Repositories($this->url . '/' . $packagesLink); + } catch (\ErrorException $e) { + if (false === strpos($e->getMessage(), '404')) { + throw $e; + } + $categoryLink = str_replace("info.xml", "packages.xml", $link); + $this->fetchPearRepositories($this->url . '/' . $categoryLink); } - $packagesXML = $this->requestXml($this->url . $categoryLink); - $packages = $packagesXML->getElementsByTagName('p'); - $loader = new ArrayLoader(); - foreach ($packages as $package) { - $packageName = $package->nodeValue; + } + } - $packageLink = $package->getAttribute('xlink:href'); - $releaseLink = $this->url . str_replace("/rest/p/", "/rest/r/", $packageLink); - $allReleasesLink = $releaseLink . "/allreleases2.xml"; + /** + * @param string $categoryLink + * @throws ErrorException + * @throws InvalidArgumentException + */ + private function fetchPearRepositories($categoryLink) + { + $packagesXML = $this->requestXml($categoryLink); + $packages = $packagesXML->getElementsByTagName('p'); + $loader = new ArrayLoader(); + foreach ($packages as $package) { + $packageName = $package->nodeValue; + + $packageLink = $package->getAttribute('xlink:href'); + $releaseLink = $this->url . str_replace("/rest/p/", "/rest/r/", $packageLink); + $allReleasesLink = $releaseLink . "/allreleases2.xml"; + + try { + $releasesXML = $this->requestXml($allReleasesLink); + } catch (\ErrorException $e) { + if (strpos($e->getMessage(), '404')) { + continue; + } + throw $e; + } + + $releases = $releasesXML->getElementsByTagName('r'); + + foreach ($releases as $release) { + /* @var $release DOMElement */ + $pearVersion = $release->getElementsByTagName('v')->item(0)->nodeValue; + + $packageData = array( + 'name' => $packageName, + 'type' => 'library', + 'dist' => array('type' => 'pear', 'url' => $this->url.'/get/'.$packageName.'-'.$pearVersion.".tgz"), + 'version' => $pearVersion, + ); try { - $releasesXML = $this->requestXml($allReleasesLink); + $deps = file_get_contents($releaseLink . "/deps.".$pearVersion.".txt"); } catch (\ErrorException $e) { if (strpos($e->getMessage(), '404')) { continue; @@ -76,54 +114,135 @@ class PearRepository extends ArrayRepository throw $e; } - $releases = $releasesXML->getElementsByTagName('r'); + $packageData += $this->parseDependences($deps); - foreach ($releases as $release) { - /* @var $release DOMElement */ - $pearVersion = $release->getElementsByTagName('v')->item(0)->nodeValue; + try { + $this->addPackage($loader->load($packageData)); + } catch (\UnexpectedValueException $e) { + continue; + } + } + } + } - $packageData = array( - 'name' => $packageName, - 'type' => 'library', - 'dist' => array('type' => 'pear', 'url' => $this->url.'/get/'.$packageName.'-'.$pearVersion.".tgz"), - 'version' => $pearVersion, + /** + * @todo Improve dependences of pear packages. + * @param array $options + * @return array + */ + private function parseDependencesOptions(array $depsOptions) + { + $data = array(); + foreach ($depsOptions as $name => $options) { + if ('php' == $name) { + $key = $name; + if (isset($options['min'])) { + $value = '>=' . $options['min']; + } else { + $value = '>=0.0.0'; + } + $data[$key] = $value; + + } elseif ('package' == $name) { + foreach ($options as $key => $value) { + $key = $value['name']; + if (isset($value['min'])) { + $value = '>=' . $value['min']; + } else { + $value = '>=0.0.0'; + } + $data[$key] = $value; + } + } elseif ('extension' == $name) { + foreach ($options as $key => $value) { + $key = 'ext-' . $value['name']; + $value = '*'; + $data[$key] = $value; + } + } + } + $data = array_filter($data); + return $data; + } + + /** + * @param string $deps + * @return array + * @throws InvalidArgumentException + */ + private function parseDependences($deps) + { + if (preg_match('((O:([0-9])+:"([^"]+)"))', $deps, $matches)) { + if (strlen($matches[3]) == $matches[2]) { + throw new \InvalidArgumentException("Invalid dependency data, it contains serialized objects."); + } + } + $deps = (array) @unserialize($deps); + unset($deps['required']['pearinstaller']); + + $depsData = array(); + if (isset($deps['required'])) { + $depsData['require'] = $this->parseDependencesOptions($deps['required']); + } else { + $depsData['require'] = array('php' => '>=5.3.0'); + } + + if (isset($depsData['optional'])) { + $depsData['recommend'] = $this->parseDependencesOptions($depsData['optional']); + } + + return $depsData; + } + + /** + * @param string $packagesLink + * @return void + * @throws InvalidArgumentException + */ + private function fetchPear2Repositories($packagesLink) + { + $loader = new ArrayLoader(); + $packagesXml = $this->requestXml($packagesLink); + $informations = $packagesXml->getElementsByTagName('pi'); + foreach ($informations as $information) { + $package = $information->getElementsByTagName('p')->item(0); + + $packageName = $package->getElementsByTagName('n')->item(0)->nodeValue; + $packageData = array( + 'name' => $packageName, + 'type' => 'library' + ); + $packageKeys = array('l' => 'license', 'd' => 'description'); + foreach ($packageKeys as $pear => $composer) { + if ($package->getElementsByTagName($pear)->length > 0 + && ($pear = $package->getElementsByTagName($pear)->item(0)->nodeValue)) { + $packageData[$composer] = $pear; + } + } + + $depsData = $information->getElementsByTagName('deps')->item(0); + $depsData = $depsData->getElementsByTagName('d')->item(0); + $depsData = $this->parseDependences($depsData->nodeValue); + + $revisions = $information->getElementsByTagName('a')->item(0); + $revisions = $revisions->getElementsByTagName('r'); + $packageUrl = $this->url . '/get/' . $packageName; + foreach ($revisions as $revision) { + $version = $revision->getElementsByTagName('v')->item(0)->nodeValue; + $revisionData = array( + 'dist' => array( + 'type' => 'pear', + 'url' => $packageUrl . '-' . $version . '.tgz' + ), + 'version' => $version + ); + + try { + $this->addPackage( + $loader->load($packageData + $revisionData + $depsData) ); - - try { - $deps = file_get_contents($releaseLink . "/deps.".$pearVersion.".txt"); - } catch (\ErrorException $e) { - if (strpos($e->getMessage(), '404')) { - continue; - } - throw $e; - } - - if (preg_match('((O:([0-9])+:"([^"]+)"))', $deps, $matches)) { - if (strlen($matches[3]) == $matches[2]) { - throw new \InvalidArgumentException("Invalid dependency data, it contains serialized objects."); - } - } - $deps = unserialize($deps); - if (isset($deps['required']['package'])) { - - if (isset($deps['required']['package']['name'])) { - $deps['required']['package'] = array($deps['required']['package']); - } - - foreach ($deps['required']['package'] as $dependency) { - if (isset($dependency['min'])) { - $packageData['require'][$dependency['name']] = '>='.$dependency['min']; - } else { - $packageData['require'][$dependency['name']] = '>=0.0.0'; - } - } - } - - try { - $this->addPackage($loader->load($packageData)); - } catch (\UnexpectedValueException $e) { - continue; - } + } catch (\UnexpectedValueException $e) { + continue; } } } @@ -144,4 +263,4 @@ class PearRepository extends ArrayRepository return $dom; } -} +} \ No newline at end of file From 60831ac3fc310eb549c78e022e19787be474c1e1 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 14:54:55 -0200 Subject: [PATCH 06/28] Update src/Composer/Repository/PearRepository.php --- src/Composer/Repository/PearRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 496950af5..b2f12ab2a 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -31,7 +31,7 @@ class PearRepository extends ArrayRepository throw new \UnexpectedValueException('Invalid url given for PEAR repository: '.$config['url']); } - $this->url = preg_replace('#^(.+)/+$#U', '$1', $config['url']); + $this->url = rtrim($config['url'], '/'); } protected function initialize() From c7e0fb7e58bdeb8d839632a418dbea9b55a73164 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 16:19:25 -0200 Subject: [PATCH 07/28] Correction of typo error. --- src/Composer/Repository/PearRepository.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index b2f12ab2a..119ac1667 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -114,7 +114,7 @@ class PearRepository extends ArrayRepository throw $e; } - $packageData += $this->parseDependences($deps); + $packageData += $this->parseDependencies($deps); try { $this->addPackage($loader->load($packageData)); @@ -130,7 +130,7 @@ class PearRepository extends ArrayRepository * @param array $options * @return array */ - private function parseDependencesOptions(array $depsOptions) + private function parseDependenciesOptions(array $depsOptions) { $data = array(); foreach ($depsOptions as $name => $options) { @@ -170,7 +170,7 @@ class PearRepository extends ArrayRepository * @return array * @throws InvalidArgumentException */ - private function parseDependences($deps) + private function parseDependencies($deps) { if (preg_match('((O:([0-9])+:"([^"]+)"))', $deps, $matches)) { if (strlen($matches[3]) == $matches[2]) { @@ -182,13 +182,13 @@ class PearRepository extends ArrayRepository $depsData = array(); if (isset($deps['required'])) { - $depsData['require'] = $this->parseDependencesOptions($deps['required']); + $depsData['require'] = $this->parseDependenciesOptions($deps['required']); } else { $depsData['require'] = array('php' => '>=5.3.0'); } if (isset($depsData['optional'])) { - $depsData['recommend'] = $this->parseDependencesOptions($depsData['optional']); + $depsData['recommend'] = $this->parseDependenciesOptions($depsData['optional']); } return $depsData; @@ -222,7 +222,7 @@ class PearRepository extends ArrayRepository $depsData = $information->getElementsByTagName('deps')->item(0); $depsData = $depsData->getElementsByTagName('d')->item(0); - $depsData = $this->parseDependences($depsData->nodeValue); + $depsData = $this->parseDependencies($depsData->nodeValue); $revisions = $information->getElementsByTagName('a')->item(0); $revisions = $revisions->getElementsByTagName('r'); From 1e11aff456a9df7b57285a5f2a9db1684f65305d Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 16:26:29 -0200 Subject: [PATCH 08/28] Create method parseVersion for parsing of package versions. Now includes "max" version of the package. --- src/Composer/Repository/PearRepository.php | 38 ++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 119ac1667..d9799598d 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -124,6 +124,23 @@ class PearRepository extends ArrayRepository } } } + + /** + * @param array $data + * @return string + */ + private function parseVersion(array $data) + { + if (isset($data['min'])) { + $version = '>=' . $data['min']; + } else { + $version = '>=0.0.0'; + } + if (isset($data['max'])) { + $version .= ',<=' . $data['max']; + } + return $version; + } /** * @todo Improve dependences of pear packages. @@ -135,29 +152,16 @@ class PearRepository extends ArrayRepository $data = array(); foreach ($depsOptions as $name => $options) { if ('php' == $name) { - $key = $name; - if (isset($options['min'])) { - $value = '>=' . $options['min']; - } else { - $value = '>=0.0.0'; - } - $data[$key] = $value; - + $data[$name] = $this->parseVersion($options); } elseif ('package' == $name) { foreach ($options as $key => $value) { - $key = $value['name']; - if (isset($value['min'])) { - $value = '>=' . $value['min']; - } else { - $value = '>=0.0.0'; - } - $data[$key] = $value; + $key = $value['name']; + $data[$key] = $this->parseVersion($value); } } elseif ('extension' == $name) { foreach ($options as $key => $value) { $key = 'ext-' . $value['name']; - $value = '*'; - $data[$key] = $value; + $data[$key] = '*'; } } } From 0c6d80679146203c1d03408ff6b4870ca32e9bc2 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 16:29:56 -0200 Subject: [PATCH 09/28] Correction of typo. --- src/Composer/Repository/PearRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index d9799598d..91fc5b654 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -143,7 +143,7 @@ class PearRepository extends ArrayRepository } /** - * @todo Improve dependences of pear packages. + * @todo Improve dependencies resolution of pear packages. * @param array $options * @return array */ From b62a90a981b5131fa9a014210f2e4d3b32182be1 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 16:33:23 -0200 Subject: [PATCH 10/28] Removed hard code - suggestion of a PHP version. --- src/Composer/Repository/PearRepository.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 91fc5b654..7738b1a48 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -187,8 +187,6 @@ class PearRepository extends ArrayRepository $depsData = array(); if (isset($deps['required'])) { $depsData['require'] = $this->parseDependenciesOptions($deps['required']); - } else { - $depsData['require'] = array('php' => '>=5.3.0'); } if (isset($depsData['optional'])) { From 6c47d6efe2461aa8b9d8cb9e42727433fc9f952e Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 16:38:01 -0200 Subject: [PATCH 11/28] Renamed methods of Composer\Repository\PearRepository: fetchPearRepositories() to fetchPearPackages() and fetchPear2Repositories() to fetchPea2Packages(). --- src/Composer/Repository/PearRepository.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 7738b1a48..3c4064eb8 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -54,13 +54,13 @@ class PearRepository extends ArrayRepository $link = $category->getAttribute("xlink:href"); try { $packagesLink = str_replace("info.xml", "packagesinfo.xml", $link); - $this->fetchPear2Repositories($this->url . '/' . $packagesLink); + $this->fetchPear2Packages($this->url . '/' . $packagesLink); } catch (\ErrorException $e) { if (false === strpos($e->getMessage(), '404')) { throw $e; } $categoryLink = str_replace("info.xml", "packages.xml", $link); - $this->fetchPearRepositories($this->url . '/' . $categoryLink); + $this->fetchPearPackages($this->url . '/' . $categoryLink); } } @@ -71,7 +71,7 @@ class PearRepository extends ArrayRepository * @throws ErrorException * @throws InvalidArgumentException */ - private function fetchPearRepositories($categoryLink) + private function fetchPearPackages($categoryLink) { $packagesXML = $this->requestXml($categoryLink); $packages = $packagesXML->getElementsByTagName('p'); @@ -201,7 +201,7 @@ class PearRepository extends ArrayRepository * @return void * @throws InvalidArgumentException */ - private function fetchPear2Repositories($packagesLink) + private function fetchPear2Packages($packagesLink) { $loader = new ArrayLoader(); $packagesXml = $this->requestXml($packagesLink); From 4e6a9806b69f8f0b6a407f315f6832fb6a5b9153 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 16:39:16 -0200 Subject: [PATCH 12/28] Correction of wrong type suggestion. --- src/Composer/Repository/PearRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 3c4064eb8..fb1e2b5a6 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -95,7 +95,7 @@ class PearRepository extends ArrayRepository $releases = $releasesXML->getElementsByTagName('r'); foreach ($releases as $release) { - /* @var $release DOMElement */ + /* @var $release \DOMElement */ $pearVersion = $release->getElementsByTagName('v')->item(0)->nodeValue; $packageData = array( From dd2174885bea3d7e6371e13b66aa92da67c12a7e Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 16:49:03 -0200 Subject: [PATCH 13/28] Correction of variable overwrite used during an iteration and now the versions of PHP extensions are parsed like packages. --- src/Composer/Repository/PearRepository.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index fb1e2b5a6..695dcad25 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -155,13 +155,13 @@ class PearRepository extends ArrayRepository $data[$name] = $this->parseVersion($options); } elseif ('package' == $name) { foreach ($options as $key => $value) { - $key = $value['name']; - $data[$key] = $this->parseVersion($value); + $dataKey = $value['name']; + $data[$dataKey] = $this->parseVersion($value); } } elseif ('extension' == $name) { foreach ($options as $key => $value) { - $key = 'ext-' . $value['name']; - $data[$key] = '*'; + $dataKey = 'ext-' . $value['name']; + $data[$dataKey] = $this->parseVersion($value); } } } From be448e09b4fcdb2c51988d4aae1e7fcaa6e9eb9d Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 16:45:34 -0200 Subject: [PATCH 14/28] Update src/Composer/Repository/PearRepository.php --- src/Composer/Repository/PearRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 695dcad25..9b1d98b93 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -165,7 +165,6 @@ class PearRepository extends ArrayRepository } } } - $data = array_filter($data); return $data; } From 234a6710a14d73103e0bea1ddaa4bfbc028f84a8 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 17 Jan 2012 17:02:39 -0200 Subject: [PATCH 15/28] Correction at method parseVersion() of Composer\Repository\PearRepository. --- src/Composer/Repository/PearRepository.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 9b1d98b93..06095e2fe 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -124,22 +124,24 @@ class PearRepository extends ArrayRepository } } } - + /** * @param array $data - * @return string + * @return string */ private function parseVersion(array $data) { + if (!isset($data['min']) && !isset($data['max'])) { + return '*'; + } + $versions = array(); if (isset($data['min'])) { - $version = '>=' . $data['min']; - } else { - $version = '>=0.0.0'; + $versions[] = '>=' . $data['min']; } if (isset($data['max'])) { - $version .= ',<=' . $data['max']; + $versions[] = '<=' . $data['max']; } - return $version; + return implode(',', $versions); } /** @@ -155,7 +157,7 @@ class PearRepository extends ArrayRepository $data[$name] = $this->parseVersion($options); } elseif ('package' == $name) { foreach ($options as $key => $value) { - $dataKey = $value['name']; + $dataKey = $value['name']; $data[$dataKey] = $this->parseVersion($value); } } elseif ('extension' == $name) { @@ -165,6 +167,7 @@ class PearRepository extends ArrayRepository } } } + var_dump($data);die; return $data; } From 9ca157913abbb8567ab530ae4e78b52498447faf Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Wed, 18 Jan 2012 09:04:01 -0200 Subject: [PATCH 16/28] Remotion of a debug code. --- src/Composer/Repository/PearRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 06095e2fe..f502bd0df 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -167,7 +167,6 @@ class PearRepository extends ArrayRepository } } } - var_dump($data);die; return $data; } From b3d91cab02244906f1f97f256a0b5af4ab00833d Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Sat, 11 Feb 2012 13:04:33 -0200 Subject: [PATCH 17/28] Update dependence resolution for PEAR2 packages. --- src/Composer/Repository/PearRepository.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index f502bd0df..1ad09637e 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -157,8 +157,10 @@ class PearRepository extends ArrayRepository $data[$name] = $this->parseVersion($options); } elseif ('package' == $name) { foreach ($options as $key => $value) { - $dataKey = $value['name']; - $data[$dataKey] = $this->parseVersion($value); + if (is_array($value)) { + $dataKey = $value['name']; + $data[$dataKey] = $this->parseVersion($value); + } } } elseif ('extension' == $name) { foreach ($options as $key => $value) { @@ -223,9 +225,13 @@ class PearRepository extends ArrayRepository } } - $depsData = $information->getElementsByTagName('deps')->item(0); - $depsData = $depsData->getElementsByTagName('d')->item(0); - $depsData = $this->parseDependencies($depsData->nodeValue); + $depsData = array(); + foreach ($information->getElementsByTagName('deps') as $depElement) { + $depsVersion = $depElement->getElementsByTagName('v')->item(0)->nodeValue; + $depsData[$depsVersion] = $this->parseDependencies( + $depElement->getElementsByTagName('d')->item(0)->nodeValue + ); + } $revisions = $information->getElementsByTagName('a')->item(0); $revisions = $revisions->getElementsByTagName('r'); @@ -239,10 +245,13 @@ class PearRepository extends ArrayRepository ), 'version' => $version ); + if (isset($depsData[$version])) { + $revisionData += $depsData[$version]; + } try { $this->addPackage( - $loader->load($packageData + $revisionData + $depsData) + $loader->load($packageData + $revisionData) ); } catch (\UnexpectedValueException $e) { continue; From 61c66b98a87b5038b42f8a5f7f52d379e54d60bb Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Sat, 11 Feb 2012 13:33:25 -0200 Subject: [PATCH 18/28] Correction of wrong variable name. --- src/Composer/Repository/PearRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 1ad09637e..7b118ad12 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -192,8 +192,8 @@ class PearRepository extends ArrayRepository $depsData['require'] = $this->parseDependenciesOptions($deps['required']); } - if (isset($depsData['optional'])) { - $depsData['recommend'] = $this->parseDependenciesOptions($depsData['optional']); + if (isset($deps['optional'])) { + $depsData['recommend'] = $this->parseDependenciesOptions($deps['optional']); } return $depsData; From 230f43d009c535fa9bb6b946a5765ecc13f73686 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Sat, 11 Feb 2012 15:17:27 -0200 Subject: [PATCH 19/28] Chaged the key "recommend" for "suggest" in the parse of the PEAR2 dependences. --- src/Composer/Repository/PearRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 7b118ad12..4c277af83 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -193,7 +193,7 @@ class PearRepository extends ArrayRepository } if (isset($deps['optional'])) { - $depsData['recommend'] = $this->parseDependenciesOptions($deps['optional']); + $depsData['suggest'] = $this->parseDependenciesOptions($deps['optional']); } return $depsData; From 8a5c7b39e401bdbbd8f7b5e1575403578a226652 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Sat, 11 Feb 2012 15:58:23 -0200 Subject: [PATCH 20/28] Added "nbproject" folder to the .gitignore list. --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dfbe013f5..5992f93fc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /.project /.buildpath /composer.phar -/vendor \ No newline at end of file +/vendor +/nbproject From 81d41fc44287c418aa5bb142091ce79d6d325a32 Mon Sep 17 00:00:00 2001 From: Beau Simensen Date: Mon, 13 Feb 2012 13:05:44 -0800 Subject: [PATCH 21/28] Rename --dev to --prefer-source --- src/Composer/Command/InstallCommand.php | 4 ++-- src/Composer/Command/UpdateCommand.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 26e1a5ba2..d656ad5d1 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -46,7 +46,7 @@ class InstallCommand extends Command ->setName('install') ->setDescription('Parses the composer.json file and downloads the needed dependencies.') ->setDefinition(array( - new InputOption('dev', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), + new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'), new InputOption('no-install-recommends', null, InputOption::VALUE_NONE, 'Do not install recommended packages (ignored when installing from an existing lock file).'), new InputOption('install-suggests', null, InputOption::VALUE_NONE, 'Also install suggested packages (ignored when installing from an existing lock file).'), @@ -73,7 +73,7 @@ EOT $io, $composer, $eventDispatcher, - (Boolean)$input->getOption('dev'), + (Boolean)$input->getOption('prefer-source'), (Boolean)$input->getOption('dry-run'), (Boolean)$input->getOption('verbose'), (Boolean)$input->getOption('no-install-recommends'), diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 3c2b394c0..7e1e8e0c1 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -35,7 +35,7 @@ class UpdateCommand extends Command ->setName('update') ->setDescription('Updates your dependencies to the latest version, and updates the composer.lock file.') ->setDefinition(array( - new InputOption('dev', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), + new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'), new InputOption('no-install-recommends', null, InputOption::VALUE_NONE, 'Do not install recommended packages.'), new InputOption('install-suggests', null, InputOption::VALUE_NONE, 'Also install suggested packages.'), @@ -63,7 +63,7 @@ EOT $io, $composer, $eventDispatcher, - (Boolean)$input->getOption('dev'), + (Boolean)$input->getOption('prefer-source'), (Boolean)$input->getOption('dry-run'), (Boolean)$input->getOption('verbose'), (Boolean)$input->getOption('no-install-recommends'), From 416ae21a5a12c75965095a7e348c2a7f2889551c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 13 Feb 2012 23:07:18 +0100 Subject: [PATCH 22/28] Robustness fixes for new PEAR2 compat code --- src/Composer/Repository/PearRepository.php | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 4c277af83..9543d4c22 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -54,13 +54,13 @@ class PearRepository extends ArrayRepository $link = $category->getAttribute("xlink:href"); try { $packagesLink = str_replace("info.xml", "packagesinfo.xml", $link); - $this->fetchPear2Packages($this->url . '/' . $packagesLink); + $this->fetchPear2Packages($this->url . $packagesLink); } catch (\ErrorException $e) { if (false === strpos($e->getMessage(), '404')) { throw $e; } $categoryLink = str_replace("info.xml", "packages.xml", $link); - $this->fetchPearPackages($this->url . '/' . $categoryLink); + $this->fetchPearPackages($this->url . $categoryLink); } } @@ -153,6 +153,10 @@ class PearRepository extends ArrayRepository { $data = array(); foreach ($depsOptions as $name => $options) { + // make sure single deps are wrapped in an array + if (isset($options['name'])) { + $options = array($options); + } if ('php' == $name) { $data[$name] = $this->parseVersion($options); } elseif ('package' == $name) { @@ -188,11 +192,11 @@ class PearRepository extends ArrayRepository unset($deps['required']['pearinstaller']); $depsData = array(); - if (isset($deps['required'])) { + if (!empty($deps['required'])) { $depsData['require'] = $this->parseDependenciesOptions($deps['required']); } - if (isset($deps['optional'])) { + if (!empty($deps['optional'])) { $depsData['suggest'] = $this->parseDependenciesOptions($deps['optional']); } @@ -225,7 +229,7 @@ class PearRepository extends ArrayRepository } } - $depsData = array(); + $depsData = array(); foreach ($information->getElementsByTagName('deps') as $depElement) { $depsVersion = $depElement->getElementsByTagName('v')->item(0)->nodeValue; $depsData[$depsVersion] = $this->parseDependencies( @@ -233,12 +237,16 @@ class PearRepository extends ArrayRepository ); } - $revisions = $information->getElementsByTagName('a')->item(0); - $revisions = $revisions->getElementsByTagName('r'); + $releases = $information->getElementsByTagName('a')->item(0); + if (!$releases) { + continue; + } + + $releases = $releases->getElementsByTagName('r'); $packageUrl = $this->url . '/get/' . $packageName; - foreach ($revisions as $revision) { - $version = $revision->getElementsByTagName('v')->item(0)->nodeValue; - $revisionData = array( + foreach ($releases as $release) { + $version = $release->getElementsByTagName('v')->item(0)->nodeValue; + $releaseData = array( 'dist' => array( 'type' => 'pear', 'url' => $packageUrl . '-' . $version . '.tgz' @@ -246,12 +254,12 @@ class PearRepository extends ArrayRepository 'version' => $version ); if (isset($depsData[$version])) { - $revisionData += $depsData[$version]; + $releaseData += $depsData[$version]; } try { $this->addPackage( - $loader->load($packageData + $revisionData) + $loader->load($packageData + $releaseData) ); } catch (\UnexpectedValueException $e) { continue; From 01be62d842e445f54f4e7a7626446fb100433abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Tue, 14 Feb 2012 12:57:15 +0100 Subject: [PATCH 23/28] Updated ArrayDumper --- src/Composer/Package/Dumper/ArrayDumper.php | 9 +++ src/Composer/Package/MemoryPackage.php | 2 +- .../Test/Package/Dumper/ArrayDumperTest.php | 66 +++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/Composer/Test/Package/Dumper/ArrayDumperTest.php diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index ee2a0b376..f372929b1 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -24,11 +24,16 @@ class ArrayDumper { $keys = array( 'binaries' => 'bin', + 'scripts', 'type', 'names', 'extra', 'installationSource' => 'installation-source', 'license', + 'authors', + 'description', + 'homepage', + 'keywords', 'autoload', 'repositories', ); @@ -41,6 +46,10 @@ class ArrayDumper $data['target-dir'] = $package->getTargetDir(); } + if ($package->getReleaseDate()) { + $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s'); + } + if ($package->getSourceType()) { $data['source']['type'] = $package->getSourceType(); $data['source']['url'] = $package->getSourceUrl(); diff --git a/src/Composer/Package/MemoryPackage.php b/src/Composer/Package/MemoryPackage.php index 02222e43b..d1e63e102 100644 --- a/src/Composer/Package/MemoryPackage.php +++ b/src/Composer/Package/MemoryPackage.php @@ -438,7 +438,7 @@ class MemoryPackage extends BasePackage * * @param DateTime $releaseDate */ - public function setReleasedate(\DateTime $releaseDate) + public function setReleaseDate(\DateTime $releaseDate) { $this->releaseDate = $releaseDate; } diff --git a/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php new file mode 100644 index 000000000..eab3450bf --- /dev/null +++ b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php @@ -0,0 +1,66 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Test\Package\Dumper; + +use Composer\Package\Dumper\ArrayDumper; +use Composer\Package\MemoryPackage; + +class ArrayDumperTest extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->dumper = new ArrayDumper(); + } + + public function testRequiredInformations() + { + $package = new MemoryPackage('foo', '1.0.0.0', '1.0'); + + $config = $this->dumper->dump($package); + $this->assertEquals(array('name', 'version', 'version_normalized', 'type', 'names'), array_keys($config)); + } + + /** + * @dataProvider getKeys + */ + public function testKeys($key, $value, $expectedValue = null, $method = null) + { + $package = new MemoryPackage('foo', '1.0.0.0', '1.0'); + + $setter = 'set'.ucfirst($method ?: $key); + $package->$setter($value); + + $config = $this->dumper->dump($package); + $this->assertArrayHasKey($key, $config); + + $expectedValue = $expectedValue ?: $value; + $this->assertSame($expectedValue, $config[$key]); + } + + public function getKeys() + { + return array( + array('time', new \DateTime('2012-02-01'), '2012-02-01 00:00:00', 'ReleaseDate'), + array('authors', array('Nils Adermann ', 'Jordi Boggiano ')), + array('homepage', 'http://getcomposer.org'), + array('description', 'Package Manager'), + array('keywords', array('package', 'dependency', 'autoload')), + array('bin', array('bin/composer'), null, 'binaries'), + array('license', array('MIT')), + array('autoload', array('psr-0' => array('Composer' => 'src/'))), + array('repositories', array('packagist' => false)), + array('scripts', array('post-update-cmd' => 'MyVendor\\MyClass::postUpdate')), + array('extra', array('class' => 'MyVendor\\Installer')), + ); + } +} From b030a36bf58a44748ae2fa9247fca9d89209fee1 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Tue, 14 Feb 2012 12:29:32 -0200 Subject: [PATCH 24/28] Some PEAR repositories does not works because of a wrong link parse. --- src/Composer/Repository/PearRepository.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 9543d4c22..43ba5dc87 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -52,6 +52,9 @@ class PearRepository extends ArrayRepository foreach ($categories as $category) { $link = $category->getAttribute("xlink:href"); + if (0 !== strpos($link, '/')) { + $link = '/' . $link; + } try { $packagesLink = str_replace("info.xml", "packagesinfo.xml", $link); $this->fetchPear2Packages($this->url . $packagesLink); From cd7d0b300c65333d006702533b5764adad630cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bj=C3=B8rnskov?= Date: Tue, 14 Feb 2012 15:31:05 +0100 Subject: [PATCH 25/28] Formatting for the README.md install command. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 50788a490..9dae242e9 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ Installation / Usage 1. Download the [`composer.phar`](http://getcomposer.org/composer.phar) executable or use the installer. - + ``` sh $ curl -s http://getcomposer.org/installer | php + ``` 2. Create a composer.json defining your dependencies. Note that this example is From e92e3ba3554bcbeb34bd4ede535cb626e4c96e69 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 14 Feb 2012 16:06:09 +0100 Subject: [PATCH 26/28] Simplify code --- src/Composer/Repository/PearRepository.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 43ba5dc87..ff975d99a 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -51,10 +51,7 @@ class PearRepository extends ArrayRepository $categories = $categoryXML->getElementsByTagName("c"); foreach ($categories as $category) { - $link = $category->getAttribute("xlink:href"); - if (0 !== strpos($link, '/')) { - $link = '/' . $link; - } + $link = '/' . ltrim($category->getAttribute("xlink:href"), '/'); try { $packagesLink = str_replace("info.xml", "packagesinfo.xml", $link); $this->fetchPear2Packages($this->url . $packagesLink); From ff0f833b3e8da0a2737feb0035fb36b7abc5379e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Wed, 15 Feb 2012 11:59:39 +0100 Subject: [PATCH 27/28] Added support for JSON_UNESCAPED_UNICODE and fixed parsing string --- src/Composer/Json/JsonFile.php | 54 +++++++++++++++++------ tests/Composer/Test/Json/JsonFileTest.php | 20 +++++++++ 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 7d4ab8cb6..ecd286d78 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -78,8 +78,9 @@ class JsonFile * * @param array $hash writes hash into json file * @param Boolean $prettyPrint If true, output is pretty-printed + * @param Boolean $unescapeUnicode If true, unicode chars in output are unescaped */ - public function write(array $hash, $prettyPrint = true) + public function write(array $hash, $prettyPrint = true, $unescapeUnicode = true) { $dir = dirname($this->path); if (!is_dir($dir)) { @@ -94,7 +95,7 @@ class JsonFile ); } } - file_put_contents($this->path, static::encode($hash, $prettyPrint)); + file_put_contents($this->path, static::encode($hash, $prettyPrint, $unescapeUnicode)); } /** @@ -105,17 +106,23 @@ class JsonFile * * @param array $hash Data to encode into a formatted JSON string * @param Boolean $prettyPrint If true, output is pretty-printed + * @param Boolean $unescapeUnicode If true, unicode chars in output are unescaped * @return string Indented version of the original JSON string */ - static public function encode(array $hash, $prettyPrint = true) + static public function encode(array $hash, $prettyPrint = true, $unescapeUnicode = true) { - if ($prettyPrint && defined('JSON_PRETTY_PRINT')) { - return json_encode($hash, JSON_PRETTY_PRINT); + if (version_compare(PHP_VERSION, '5.4', '>=')) { + $options = $prettyPrint ? JSON_PRETTY_PRINT : 0; + if ($unescapeUnicode) { + $options |= JSON_UNESCAPED_UNICODE; + } + + return json_encode($hash, $options); } $json = json_encode($hash); - if (!$prettyPrint) { + if (!$prettyPrint && !$unescapeUnicode) { return $json; } @@ -124,21 +131,43 @@ class JsonFile $strLen = strlen($json); $indentStr = ' '; $newLine = "\n"; - $prevChar = ''; $outOfQuotes = true; + $buffer = ''; + $noescape = true; for ($i = 0; $i <= $strLen; $i++) { // Grab the next character in the string $char = substr($json, $i, 1); // Are we inside a quoted string? - if ('"' === $char && ('\\' !== $prevChar || '\\\\' === substr($json, $i-2, 2))) { + if ('"' === $char && $noescape) { $outOfQuotes = !$outOfQuotes; - } elseif (':' === $char && $outOfQuotes) { + } + + if (!$outOfQuotes) { + $buffer .= $char; + $noescape = '\\' === $char ? !$noescape : true; + continue; + } elseif ('' !== $buffer) { + if ($unescapeUnicode && function_exists('mb_convert_encoding')) { + // http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha + $result .= preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($match) { + return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE'); + }, $buffer.$char); + } else { + $result .= $buffer.$char; + } + + $buffer = ''; + continue; + } + + if (':' === $char) { // Add a space after the : character $char .= ' '; - } elseif (('}' === $char || ']' === $char) && $outOfQuotes) { + } elseif (('}' === $char || ']' === $char)) { $pos--; + $prevChar = substr($json, $i - 1, 1); if ('{' !== $prevChar && '[' !== $prevChar) { // If this character is the end of an element, @@ -153,12 +182,11 @@ class JsonFile } } - // Add the character to the result string $result .= $char; // If the last character was the beginning of an element, // output a new line and indent the next line - if ((',' === $char || '{' === $char || '[' === $char) && $outOfQuotes) { + if (',' === $char || '{' === $char || '[' === $char) { $result .= $newLine; if ('{' === $char || '[' === $char) { @@ -169,8 +197,6 @@ class JsonFile $result .= $indentStr; } } - - $prevChar = $char; } return $result; diff --git a/tests/Composer/Test/Json/JsonFileTest.php b/tests/Composer/Test/Json/JsonFileTest.php index 4ebf7b0c5..4ed016fa6 100644 --- a/tests/Composer/Test/Json/JsonFileTest.php +++ b/tests/Composer/Test/Json/JsonFileTest.php @@ -121,6 +121,26 @@ class JsonFileTest extends \PHPUnit_Framework_TestCase $this->assertJsonFormat($json, $data); } + public function testEscape() + { + $data = array("Metadata\\\"" => 'src/'); + $json = '{ + "Metadata\\\\\\"": "src\/" +}'; + + $this->assertJsonFormat($json, $data); + } + + public function testUnicode() + { + $data = array("Žluťoučký \" kůň" => "úpěl ďábelské ódy za €"); + $json = '{ + "Žluťoučký \" kůň": "úpěl ďábelské ódy za €" +}'; + + $this->assertJsonFormat($json, $data); + } + private function expectParseException($text, $json) { try { From 6905e3a7aeaba38b7a813d15f74621cd13d35a66 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 15 Feb 2012 18:21:17 +0100 Subject: [PATCH 28/28] Disable gzip compression of the phar --- src/Composer/Compiler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index 4898fd795..c21b66248 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -79,7 +79,8 @@ class Compiler $phar->stopBuffering(); - $phar->compressFiles(\Phar::GZ); + // disabled for interoperability with systems without gzip ext + // $phar->compressFiles(\Phar::GZ); $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false);