Browse Source

Use pathinfo instead of substr

Jordi Boggiano 13 years ago
parent
commit
48ae8bf3ec
2 changed files with 4 additions and 2 deletions
  1. 1 1
      src/Composer/Command/CreateProjectCommand.php
  2. 3 1
      src/Composer/Factory.php

+ 1 - 1
src/Composer/Command/CreateProjectCommand.php

@@ -84,7 +84,7 @@ EOT
 
         if (null === $repositoryUrl) {
             $sourceRepo = new ComposerRepository(array('url' => 'http://packagist.org'), $io);
-        } elseif (".json" === substr($repositoryUrl, -5)) {
+        } elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) {
             $sourceRepo = new FilesystemRepository(new JsonFile($repositoryUrl, new RemoteFilesystem($io)));
         } elseif (0 === strpos($repositoryUrl, 'http')) {
             $sourceRepo = new ComposerRepository(array('url' => $repositoryUrl), $io);

+ 3 - 1
src/Composer/Factory.php

@@ -125,7 +125,9 @@ class Factory
 
         // init locker if possible
         if (isset($composerFile)) {
-            $lockFile = substr($composerFile, -5) === '.json' ? substr($composerFile, 0, -4).'lock' : $composerFile . '.lock';
+            $lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION)
+                ? substr($composerFile, 0, -4).'lock'
+                : $composerFile . '.lock';
             $locker = new Package\Locker(new JsonFile($lockFile, new RemoteFilesystem($io)), $rm, md5_file($composerFile));
             $composer->setLocker($locker);
         }