Browse Source

Fix handling of platform packages to be future proof, refs #3872

Jordi Boggiano 10 years ago
parent
commit
06fb00bfe5
1 changed files with 23 additions and 17 deletions
  1. 23 17
      src/Composer/Json/JsonManipulator.php

+ 23 - 17
src/Composer/Json/JsonManipulator.php

@@ -12,6 +12,8 @@
 
 namespace Composer\Json;
 
+use Composer\Repository\PlatformRepository;
+
 /**
  * @author Jordi Boggiano <j.boggiano@seld.be>
  */
@@ -111,23 +113,27 @@ class JsonManipulator
     private function sortPackages(array &$packages = array())
     {
         $prefix = function ($requirement) {
-            return preg_replace(
-                array(
-                    '/^php$/',
-                    '/^hhvm$/',
-                    '/^ext-\w+$/',
-                    '/^lib-\w+$/',
-                    '/^.+$/',
-                ),
-                array(
-                    '0-$0',
-                    '1-$0',
-                    '2-$0',
-                    '3-$0',
-                    '4-$0',
-                ),
-                $requirement
-            );
+            if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $requirement)) {
+                return preg_replace(
+                    array(
+                        '/^php/',
+                        '/^hhvm/',
+                        '/^ext/',
+                        '/^lib/',
+                        '/^\D/',
+                    ),
+                    array(
+                        '0-$0',
+                        '1-$0',
+                        '2-$0',
+                        '3-$0',
+                        '4-$0',
+                    ),
+                    $requirement
+                );
+            }
+
+            return '5-'.$requirement;
         };
 
         uksort($packages, function ($a, $b) use ($prefix) {