From 7ef709c7341940e5bb94e0532be75b7376896288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20L=C3=BCnemann?= Date: Tue, 15 Nov 2016 17:46:17 +0100 Subject: [PATCH] Use SplFileInfo to simplify DrupalFinder::locateRoot deprecate DrupalFinder::shiftPathUp, does not Work with streamWrapper on Windows --- src/DrupalFinder.php | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/DrupalFinder.php b/src/DrupalFinder.php index 5e287b9..9419a4b 100644 --- a/src/DrupalFinder.php +++ b/src/DrupalFinder.php @@ -6,6 +6,7 @@ */ namespace DrupalFinder; +use SplFileInfo; class DrupalFinder { @@ -24,29 +25,22 @@ class DrupalFinder { private $composerRoot; public function locateRoot($start_path) { + $start_path = new SplFileInfo($start_path); $this->drupalRoot = FALSE; $this->composerRoot = FALSE; foreach (array(TRUE, FALSE) as $follow_symlinks) { - $path = $start_path; - if ($follow_symlinks && is_link($path)) { - $path = realpath($path); - } - // Check the start path. - if ($checked_path = $this->isValidRoot($path)) { - return $checked_path; - } - else { - // Move up dir by dir and check each. - while ($path = $this->shiftPathUp($path)) { - if ($follow_symlinks && is_link($path)) { - $path = realpath($path); - } - if ($checked_path = $this->isValidRoot($path)) { - return $checked_path; - } + for ($path = $start_path; + $path->getFilename() != '.'; + $path = $path->getPathInfo()) { + if ($follow_symlinks && $path->isLink()) { + $path = $path->getRealPath(); } - } + // Check the start path. + if ($checked_path = $this->isValidRoot($path->getPathname())) { + return $checked_path; + } + }; } return FALSE; @@ -55,6 +49,8 @@ public function locateRoot($start_path) { /** * Returns parent directory. * + * @deprecated does not work with streamWrappers on Windows + * * @param string * Path to start from. *