code: private function resolveSymlinkedDirectorySymlink($pathname)
      {
          if (!is_dir($pathname)) {
              return $pathname;
          }
  
          $resolved = rtrim($pathname, '/');
  
          if (!strlen($resolved)) {
              return $pathname;
          }
  
          return $resolved;
      }
docs: resolve pathname to symbolic link of a directory
  
  @param string $pathname directory path to resolve
  
  @return string resolved path to symbolic link or original pathname (unresolved)