From 4af410e1b97c217059a3a5b60766458a7cb90f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=B6nthal?= Date: Sat, 29 Jun 2013 22:46:04 +0200 Subject: [PATCH 1/5] using finder for classmap generator --- src/Composer/Autoload/ClassMapGenerator.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index f3b59c5aa..93b2b3c70 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -12,6 +12,7 @@ */ namespace Composer\Autoload; +use Symfony\Component\Finder\Finder; /** * ClassMapGenerator @@ -53,7 +54,7 @@ class ClassMapGenerator if (is_file($path)) { $path = array(new \SplFileInfo($path)); } elseif (is_dir($path)) { - $path = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); + $path = Finder::create()->files()->followLinks()->name('/.*[php|inc]/')->in($path); } else { throw new \RuntimeException( 'Could not scan for classes inside "'.$path. @@ -65,10 +66,6 @@ class ClassMapGenerator $map = array(); foreach ($path as $file) { - if (!$file->isFile()) { - continue; - } - $filePath = $file->getRealPath(); if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc'))) { @@ -84,7 +81,6 @@ class ClassMapGenerator foreach ($classes as $class) { $map[$class] = $filePath; } - } return $map; @@ -102,7 +98,11 @@ class ClassMapGenerator $traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait'; try { - $contents = php_strip_whitespace($path); + if (!is_readable($path)) { + throw new \RuntimeException('file not found'); + } + //suppress warnings on unclosed comments + $contents = @php_strip_whitespace($path); } catch (\Exception $e) { throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e); } From 1a4a104df0fc913cc6dcf962c19d6369558efed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=B6nthal?= Date: Fri, 5 Jul 2013 09:24:54 +0200 Subject: [PATCH 2/5] use best finder adapter --- src/Composer/Autoload/ClassMapGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 93b2b3c70..f9268bc32 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -54,7 +54,7 @@ class ClassMapGenerator if (is_file($path)) { $path = array(new \SplFileInfo($path)); } elseif (is_dir($path)) { - $path = Finder::create()->files()->followLinks()->name('/.*[php|inc]/')->in($path); + $path = Finder::create()->useBestAdapter()->files()->followLinks()->name('/.*[php|inc]/')->in($path); } else { throw new \RuntimeException( 'Could not scan for classes inside "'.$path. From 963f189fb284371467f29537e62f526bd677cc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=B6nthal?= Date: Fri, 5 Jul 2013 12:27:48 +0200 Subject: [PATCH 3/5] bumped finder version, reverted warning suppression --- composer.json | 2 +- src/Composer/Autoload/ClassMapGenerator.php | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 6d9299258..ead101d2c 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "justinrainbow/json-schema": "1.1.*", "seld/jsonlint": "1.*", "symfony/console": "~2.3@dev", - "symfony/finder": "~2.1", + "symfony/finder": "~2.2", "symfony/process": "~2.1@dev" }, "require-dev": { diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index f9268bc32..e408eea75 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -54,7 +54,7 @@ class ClassMapGenerator if (is_file($path)) { $path = array(new \SplFileInfo($path)); } elseif (is_dir($path)) { - $path = Finder::create()->useBestAdapter()->files()->followLinks()->name('/.*[php|inc]/')->in($path); + $path = Finder::create()->useBestAdapter()->files()->followLinks()->name('/\.(php|inc)$/')->in($path); } else { throw new \RuntimeException( 'Could not scan for classes inside "'.$path. @@ -98,11 +98,7 @@ class ClassMapGenerator $traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait'; try { - if (!is_readable($path)) { - throw new \RuntimeException('file not found'); - } - //suppress warnings on unclosed comments - $contents = @php_strip_whitespace($path); + $contents = php_strip_whitespace($path); } catch (\Exception $e) { throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e); } From f75dda759d681c1993f993459130ee7f35161e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=B6nthal?= Date: Tue, 9 Jul 2013 15:33:04 +0200 Subject: [PATCH 4/5] simplified extension check in classmap generation --- src/Composer/Autoload/ClassMapGenerator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index e408eea75..880bef2a8 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -66,9 +66,10 @@ class ClassMapGenerator $map = array(); foreach ($path as $file) { + /** @var \SplFileInfo $file */ $filePath = $file->getRealPath(); - if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc'))) { + if (!in_array($file->getExtension(), array('php', 'inc'))) { continue; } From 860483e97e0966823c1461876d72874d1ef4b061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=B6nthal?= Date: Tue, 9 Jul 2013 15:53:27 +0200 Subject: [PATCH 5/5] reverted simplification cause of php < 5.3.6 --- src/Composer/Autoload/ClassMapGenerator.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 880bef2a8..e408eea75 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -66,10 +66,9 @@ class ClassMapGenerator $map = array(); foreach ($path as $file) { - /** @var \SplFileInfo $file */ $filePath = $file->getRealPath(); - if (!in_array($file->getExtension(), array('php', 'inc'))) { + if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc'))) { continue; }