+ if (!$tail) {
+ return;
+ }
+
+ $tail = \DIRECTORY_SEPARATOR.implode(\DIRECTORY_SEPARATOR, $tail);
+ $tailLen = \strlen($tail);
+ $real = $refl->getFileName();
+
+ if (2 === self::$caseCheck) {
+ $real = $this->darwinRealpath($real);
+ }
+
+ if (0 === substr_compare($real, $tail, -$tailLen, $tailLen, true)
+ && 0 !== substr_compare($real, $tail, -$tailLen, $tailLen, false)
+ ) {
+ return array(substr($tail, -$tailLen + 1), substr($real, -$tailLen + 1), substr($real, 0, -$tailLen + 1));
+ }
+ }
+
+ /**
+ * `realpath` on MacOSX doesn't normalize the case of characters.
+ */
+ private function darwinRealpath($real)
+ {
+ $i = 1 + strrpos($real, '/');
+ $file = substr($real, $i);
+ $real = substr($real, 0, $i);
+
+ if (isset(self::$darwinCache[$real])) {
+ $kDir = $real;
+ } else {
+ $kDir = strtolower($real);
+
+ if (isset(self::$darwinCache[$kDir])) {
+ $real = self::$darwinCache[$kDir][0];
+ } else {
+ $dir = getcwd();
+ chdir($real);
+ $real = getcwd().'/';
+ chdir($dir);
+
+ $dir = $real;
+ $k = $kDir;
+ $i = \strlen($dir) - 1;
+ while (!isset(self::$darwinCache[$k])) {
+ self::$darwinCache[$k] = array($dir, array());
+ self::$darwinCache[$dir] = &self::$darwinCache[$k];
+
+ while ('/' !== $dir[--$i]) {
+ }
+ $k = substr($k, 0, ++$i);
+ $dir = substr($dir, 0, $i--);