Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  
   3  namespace ScssPhp\ScssPhp\Util;
   4  
   5  /**
   6   * @internal
   7   */
   8  class Path
   9  {
  10      /**
  11       * @param string $path
  12       *
  13       * @return bool
  14       */
  15      public static function isAbsolute($path)
  16      {
  17          if ($path === '') {
  18              return false;
  19          }
  20  
  21          if ($path[0] === '/') {
  22              return true;
  23          }
  24  
  25          if (\DIRECTORY_SEPARATOR !== '\\') {
  26              return false;
  27          }
  28  
  29          if ($path[0] === '\\') {
  30              return true;
  31          }
  32  
  33          if (\strlen($path) < 3) {
  34              return false;
  35          }
  36  
  37          if ($path[1] !== ':') {
  38              return false;
  39          }
  40  
  41          if ($path[2] !== '/' && $path[2] !== '\\') {
  42              return false;
  43          }
  44  
  45          if (!preg_match('/^[A-Za-z]$/', $path[0])) {
  46              return false;
  47          }
  48  
  49          return true;
  50      }
  51  
  52      /**
  53       * @param string $part1
  54       * @param string $part2
  55       *
  56       * @return string
  57       */
  58      public static function join($part1, $part2)
  59      {
  60          if ($part1 === '' || self::isAbsolute($part2)) {
  61              return $part2;
  62          }
  63  
  64          if ($part2 === '') {
  65              return $part1;
  66          }
  67  
  68          $last = $part1[\strlen($part1) - 1];
  69          $separator = \DIRECTORY_SEPARATOR;
  70  
  71          if ($last === '/' || $last === \DIRECTORY_SEPARATOR) {
  72              $separator = '';
  73          }
  74  
  75          return $part1 . $separator . $part2;
  76      }
  77  }