[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> class-wp-filesystem-base.php (source)

   1  <?php
   2  /**
   3   * Base WordPress Filesystem
   4   *
   5   * @package WordPress
   6   * @subpackage Filesystem
   7   */
   8  
   9  /**
  10   * Base WordPress Filesystem class which Filesystem implementations extend.
  11   *
  12   * @since 2.5.0
  13   *
  14   * @phpstan-type FileListing array{
  15   *     name: string,
  16   *     perms?: string,
  17   *     permsn?: string,
  18   *     number?: int|string|false,
  19   *     owner?: string|int<1, max>|false,
  20   *     group?: string|int<1, max>|false,
  21   *     size: int|string|false,
  22   *     lastmodunix?: int|string|false,
  23   *     lastmod?: string|false,
  24   *     time: int|string|false,
  25   *     type: 'd'|'f'|'l',
  26   *     islink?: bool,
  27   *     isdir?: bool,
  28   *     files?: mixed[]|false, // The mixed[] is actually FileListing[] but PHPStan does not support recursive or self-referencing array shapes.
  29   * }
  30   */
  31  #[AllowDynamicProperties]
  32  class WP_Filesystem_Base {
  33  
  34      /**
  35       * Whether to display debug data for the connection.
  36       *
  37       * @since 2.5.0
  38       * @var bool
  39       */
  40      public $verbose = false;
  41  
  42      /**
  43       * Cached list of local filepaths to mapped remote filepaths.
  44       *
  45       * @since 2.7.0
  46       * @var array<string, string>
  47       */
  48      public $cache = array();
  49  
  50      /**
  51       * The Access method of the current connection, Set automatically.
  52       *
  53       * @since 2.5.0
  54       * @var string
  55       */
  56      public $method = '';
  57  
  58      /**
  59       * @var WP_Error
  60       */
  61      public $errors = null;
  62  
  63      /**
  64       * @var array<string, mixed>
  65       */
  66      public $options = array();
  67  
  68      /**
  69       * Returns the path on the remote filesystem of ABSPATH.
  70       *
  71       * @since 2.7.0
  72       *
  73       * @return string|false The location of the remote path, or false on failure.
  74       */
  75  	public function abspath() {
  76          $folder = $this->find_folder( ABSPATH );
  77  
  78          /*
  79           * Perhaps the FTP folder is rooted at the WordPress install.
  80           * Check for wp-includes folder in root. Could have some false positives, but rare.
  81           */
  82          if ( ! $folder && $this->is_dir( '/' . WPINC ) ) {
  83              $folder = '/';
  84          }
  85  
  86          return $folder;
  87      }
  88  
  89      /**
  90       * Returns the path on the remote filesystem of WP_CONTENT_DIR.
  91       *
  92       * @since 2.7.0
  93       *
  94       * @return string|false The location of the remote path, or false on failure.
  95       */
  96  	public function wp_content_dir() {
  97          return $this->find_folder( WP_CONTENT_DIR );
  98      }
  99  
 100      /**
 101       * Returns the path on the remote filesystem of WP_PLUGIN_DIR.
 102       *
 103       * @since 2.7.0
 104       *
 105       * @return string|false The location of the remote path, or false on failure.
 106       */
 107  	public function wp_plugins_dir() {
 108          return $this->find_folder( WP_PLUGIN_DIR );
 109      }
 110  
 111      /**
 112       * Returns the path on the remote filesystem of the Themes Directory.
 113       *
 114       * @since 2.7.0
 115       *
 116       * @param string|false $theme Optional. The theme stylesheet or template for the directory.
 117       *                            Default false.
 118       * @return string|false The location of the remote path, or false on failure.
 119       */
 120  	public function wp_themes_dir( $theme = false ) {
 121          $theme_root = get_theme_root( is_string( $theme ) ? $theme : '' );
 122  
 123          // Account for relative theme roots.
 124          if ( '/themes' === $theme_root || ! is_dir( $theme_root ) ) {
 125              $theme_root = WP_CONTENT_DIR . $theme_root;
 126          }
 127  
 128          return $this->find_folder( $theme_root );
 129      }
 130  
 131      /**
 132       * Returns the path on the remote filesystem of WP_LANG_DIR.
 133       *
 134       * @since 3.2.0
 135       *
 136       * @return string|false The location of the remote path, or false on failure.
 137       */
 138  	public function wp_lang_dir() {
 139          return $this->find_folder( WP_LANG_DIR );
 140      }
 141  
 142      /**
 143       * Locates a folder on the remote filesystem.
 144       *
 145       * @since 2.5.0
 146       * @deprecated 2.7.0 use WP_Filesystem_Base::abspath() or WP_Filesystem_Base::wp_*_dir() instead.
 147       * @see WP_Filesystem_Base::abspath()
 148       * @see WP_Filesystem_Base::wp_content_dir()
 149       * @see WP_Filesystem_Base::wp_plugins_dir()
 150       * @see WP_Filesystem_Base::wp_themes_dir()
 151       * @see WP_Filesystem_Base::wp_lang_dir()
 152       *
 153       * @param string $base    Optional. The folder to start searching from. Default '.'.
 154       * @param bool   $verbose Optional. True to display debug information. Default false.
 155       * @return string|false The location of the remote path, or false on failure.
 156       */
 157  	public function find_base_dir( $base = '.', $verbose = false ) {
 158          _deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem_Base::abspath() or WP_Filesystem_Base::wp_*_dir()' );
 159          $this->verbose = $verbose;
 160          return $this->abspath();
 161      }
 162  
 163      /**
 164       * Locates a folder on the remote filesystem.
 165       *
 166       * @since 2.5.0
 167       * @deprecated 2.7.0 use WP_Filesystem_Base::abspath() or WP_Filesystem_Base::wp_*_dir() methods instead.
 168       * @see WP_Filesystem_Base::abspath()
 169       * @see WP_Filesystem_Base::wp_content_dir()
 170       * @see WP_Filesystem_Base::wp_plugins_dir()
 171       * @see WP_Filesystem_Base::wp_themes_dir()
 172       * @see WP_Filesystem_Base::wp_lang_dir()
 173       *
 174       * @param string $base    Optional. The folder to start searching from. Default '.'.
 175       * @param bool   $verbose Optional. True to display debug information. Default false.
 176       * @return string|false The location of the remote path, or false on failure.
 177       */
 178  	public function get_base_dir( $base = '.', $verbose = false ) {
 179          _deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem_Base::abspath() or WP_Filesystem_Base::wp_*_dir()' );
 180          $this->verbose = $verbose;
 181          return $this->abspath();
 182      }
 183  
 184      /**
 185       * Locates a folder on the remote filesystem.
 186       *
 187       * Assumes that on Windows systems, Stripping off the Drive
 188       * letter is OK Sanitizes \\ to / in Windows filepaths.
 189       *
 190       * @since 2.7.0
 191       *
 192       * @param string $folder the folder to locate.
 193       * @return string|false The location of the remote path, false on failure.
 194       */
 195  	public function find_folder( $folder ) {
 196          if ( isset( $this->cache[ $folder ] ) ) {
 197              return $this->cache[ $folder ];
 198          }
 199  
 200          if ( stripos( $this->method, 'ftp' ) !== false ) {
 201              $constant_overrides = array(
 202                  'FTP_BASE'        => ABSPATH,
 203                  'FTP_CONTENT_DIR' => WP_CONTENT_DIR,
 204                  'FTP_PLUGIN_DIR'  => WP_PLUGIN_DIR,
 205                  'FTP_LANG_DIR'    => WP_LANG_DIR,
 206              );
 207  
 208              // Direct matches ( folder = CONSTANT/ ).
 209              foreach ( $constant_overrides as $constant => $dir ) {
 210                  if ( ! defined( $constant ) ) {
 211                      continue;
 212                  }
 213  
 214                  if ( $folder === $dir ) {
 215                      /** @var string $constant_value */
 216                      $constant_value = constant( $constant );
 217                      return trailingslashit( $constant_value );
 218                  }
 219              }
 220  
 221              // Prefix matches ( folder = CONSTANT/subdir ),
 222              foreach ( $constant_overrides as $constant => $dir ) {
 223                  if ( ! defined( $constant ) ) {
 224                      continue;
 225                  }
 226  
 227                  if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir.
 228                      /** @var string $constant_value */
 229                      $constant_value   = constant( $constant );
 230                      $potential_folder = (string) preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( $constant_value ), $folder );
 231                      $potential_folder = trailingslashit( $potential_folder );
 232  
 233                      if ( $this->is_dir( $potential_folder ) ) {
 234                          $this->cache[ $folder ] = $potential_folder;
 235  
 236                          return $potential_folder;
 237                      }
 238                  }
 239              }
 240          } elseif ( 'direct' === $this->method ) {
 241              $folder = str_replace( '\\', '/', $folder ); // Windows path sanitization.
 242  
 243              return trailingslashit( $folder );
 244          }
 245  
 246          $folder = (string) preg_replace( '|^([a-z]{1}):|i', '', $folder ); // Strip out Windows drive letter if it's there.
 247          $folder = str_replace( '\\', '/', $folder ); // Windows path sanitization.
 248  
 249          if ( isset( $this->cache[ $folder ] ) ) {
 250              return $this->cache[ $folder ];
 251          }
 252  
 253          if ( $this->exists( $folder ) ) { // Folder exists at that absolute path.
 254              $folder                 = trailingslashit( $folder );
 255              $this->cache[ $folder ] = $folder;
 256  
 257              return $folder;
 258          }
 259  
 260          $return = $this->search_for_folder( $folder );
 261  
 262          if ( $return ) {
 263              $this->cache[ $folder ] = $return;
 264          }
 265  
 266          return $return;
 267      }
 268  
 269      /**
 270       * Locates a folder on the remote filesystem.
 271       *
 272       * Expects Windows sanitized path.
 273       *
 274       * @since 2.7.0
 275       *
 276       * @param string $folder The folder to locate.
 277       * @param string $base   The folder to start searching from.
 278       * @param bool   $loop   If the function has recursed. Internal use only.
 279       * @return string|false The location of the remote path, false to cease looping.
 280       */
 281  	public function search_for_folder( $folder, $base = '.', $loop = false ) {
 282          if ( empty( $base ) || '.' === $base ) {
 283              $cwd  = $this->cwd();
 284              $base = is_string( $cwd ) ? trailingslashit( $cwd ) : '/';
 285          }
 286  
 287          $folder = untrailingslashit( $folder );
 288  
 289          if ( $this->verbose ) {
 290              /* translators: 1: Folder to locate, 2: Folder to start searching from. */
 291              printf( "\n" . __( 'Looking for %1$s in %2$s' ) . "<br />\n", $folder, $base );
 292          }
 293  
 294          $folder_parts     = explode( '/', $folder );
 295          $folder_part_keys = array_keys( $folder_parts );
 296          $last_index       = array_pop( $folder_part_keys );
 297          $last_path        = $folder_parts[ $last_index ];
 298  
 299          $files = $this->dirlist( $base );
 300  
 301          foreach ( $folder_parts as $index => $key ) {
 302              if ( $index === $last_index ) {
 303                  continue; // We want this to be caught by the next code block.
 304              }
 305  
 306              /*
 307               * Working from /home/ to /user/ to /wordpress/ see if that file exists within
 308               * the current folder, If it's found, change into it and follow through looking
 309               * for it. If it can't find WordPress down that route, it'll continue onto the next
 310               * folder level, and see if that matches, and so on. If it reaches the end, and still
 311               * can't find it, it'll return false for the entire function.
 312               */
 313              if ( isset( $files[ $key ] ) ) {
 314  
 315                  // Let's try that folder:
 316                  $newdir = trailingslashit( path_join( $base, $key ) );
 317  
 318                  if ( $this->verbose ) {
 319                      /* translators: %s: Directory name. */
 320                      printf( "\n" . __( 'Changing to %s' ) . "<br />\n", $newdir );
 321                  }
 322  
 323                  // Only search for the remaining path tokens in the directory, not the full path again.
 324                  $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) );
 325                  $ret       = $this->search_for_folder( $newfolder, $newdir, $loop );
 326  
 327                  if ( $ret ) {
 328                      return $ret;
 329                  }
 330              }
 331          }
 332  
 333          /*
 334           * Only check this as a last resort, to prevent locating the incorrect install.
 335           * All above procedures will fail quickly if this is the right branch to take.
 336           */
 337          if ( isset( $files[ $last_path ] ) ) {
 338              if ( $this->verbose ) {
 339                  /* translators: %s: Directory name. */
 340                  printf( "\n" . __( 'Found %s' ) . "<br />\n", $base . $last_path );
 341              }
 342  
 343              return trailingslashit( $base . $last_path );
 344          }
 345  
 346          /*
 347           * Prevent this function from looping again.
 348           * No need to proceed if we've just searched in `/`.
 349           */
 350          if ( $loop || '/' === $base ) {
 351              return false;
 352          }
 353  
 354          /*
 355           * As an extra last resort, Change back to / if the folder wasn't found.
 356           * This comes into effect when the CWD is /home/user/ but WP is at /var/www/....
 357           */
 358          return $this->search_for_folder( $folder, '/', true );
 359      }
 360  
 361      /**
 362       * Returns the *nix-style file permissions for a file.
 363       *
 364       * From the PHP documentation page for fileperms().
 365       *
 366       * @link https://www.php.net/manual/en/function.fileperms.php
 367       *
 368       * @since 2.5.0
 369       *
 370       * @param string $file String filename.
 371       * @return string The *nix-style representation of permissions.
 372       */
 373  	public function gethchmod( $file ) {
 374          $perms = intval( $this->getchmod( $file ), 8 );
 375  
 376          if ( ( $perms & 0xC000 ) === 0xC000 ) { // Socket.
 377              $info = 's';
 378          } elseif ( ( $perms & 0xA000 ) === 0xA000 ) { // Symbolic Link.
 379              $info = 'l';
 380          } elseif ( ( $perms & 0x8000 ) === 0x8000 ) { // Regular.
 381              $info = '-';
 382          } elseif ( ( $perms & 0x6000 ) === 0x6000 ) { // Block special.
 383              $info = 'b';
 384          } elseif ( ( $perms & 0x4000 ) === 0x4000 ) { // Directory.
 385              $info = 'd';
 386          } elseif ( ( $perms & 0x2000 ) === 0x2000 ) { // Character special.
 387              $info = 'c';
 388          } elseif ( ( $perms & 0x1000 ) === 0x1000 ) { // FIFO pipe.
 389              $info = 'p';
 390          } else { // Unknown.
 391              $info = 'u';
 392          }
 393  
 394          // Owner.
 395          $info .= ( ( $perms & 0x0100 ) ? 'r' : '-' );
 396          $info .= ( ( $perms & 0x0080 ) ? 'w' : '-' );
 397          $info .= ( ( $perms & 0x0040 ) ?
 398                      ( ( $perms & 0x0800 ) ? 's' : 'x' ) :
 399                      ( ( $perms & 0x0800 ) ? 'S' : '-' ) );
 400  
 401          // Group.
 402          $info .= ( ( $perms & 0x0020 ) ? 'r' : '-' );
 403          $info .= ( ( $perms & 0x0010 ) ? 'w' : '-' );
 404          $info .= ( ( $perms & 0x0008 ) ?
 405                      ( ( $perms & 0x0400 ) ? 's' : 'x' ) :
 406                      ( ( $perms & 0x0400 ) ? 'S' : '-' ) );
 407  
 408          // World.
 409          $info .= ( ( $perms & 0x0004 ) ? 'r' : '-' );
 410          $info .= ( ( $perms & 0x0002 ) ? 'w' : '-' );
 411          $info .= ( ( $perms & 0x0001 ) ?
 412                      ( ( $perms & 0x0200 ) ? 't' : 'x' ) :
 413                      ( ( $perms & 0x0200 ) ? 'T' : '-' ) );
 414  
 415          return $info;
 416      }
 417  
 418      /**
 419       * Gets the permissions of the specified file or filepath in their octal format.
 420       *
 421       * @since 2.5.0
 422       *
 423       * @param string $file Path to the file.
 424       * @return string Mode of the file (the last 3 digits).
 425       */
 426  	public function getchmod( $file ) {
 427          return '777';
 428      }
 429  
 430      /**
 431       * Converts *nix-style file permissions to an octal number.
 432       *
 433       * Converts '-rw-r--r--' to 0644
 434       * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod()
 435       *
 436       * @link https://www.php.net/manual/en/function.chmod.php#49614
 437       *
 438       * @since 2.5.0
 439       *
 440       * @param string $mode string The *nix-style file permissions.
 441       * @return string Octal representation of permissions.
 442       */
 443  	public function getnumchmodfromh( $mode ) {
 444          $realmode = '';
 445          $legal    = array( '', 'w', 'r', 'x', '-' );
 446          $attarray = (array) preg_split( '//', $mode );
 447  
 448          for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
 449              $key = array_search( $attarray[ $i ], $legal, true );
 450  
 451              if ( $key ) {
 452                  $realmode .= $legal[ $key ];
 453              }
 454          }
 455  
 456          $mode  = str_pad( $realmode, 10, '-', STR_PAD_LEFT );
 457          $trans = array(
 458              '-' => '0',
 459              'r' => '4',
 460              'w' => '2',
 461              'x' => '1',
 462          );
 463          $mode  = strtr( $mode, $trans );
 464  
 465          $newmode  = $mode[0];
 466          $newmode .= (int) $mode[1] + (int) $mode[2] + (int) $mode[3];
 467          $newmode .= (int) $mode[4] + (int) $mode[5] + (int) $mode[6];
 468          $newmode .= (int) $mode[7] + (int) $mode[8] + (int) $mode[9];
 469  
 470          return $newmode;
 471      }
 472  
 473      /**
 474       * Determines if the string provided contains binary characters.
 475       *
 476       * @since 2.7.0
 477       *
 478       * @param string $text String to test against.
 479       * @return bool True if string is binary, false otherwise.
 480       */
 481  	public function is_binary( $text ) {
 482          return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127)
 483      }
 484  
 485      /**
 486       * Changes the owner of a file or directory.
 487       *
 488       * Default behavior is to do nothing, override this in your subclass, if desired.
 489       *
 490       * @since 2.5.0
 491       *
 492       * @param string     $file      Path to the file or directory.
 493       * @param string|int $owner     A user name or number.
 494       * @param bool       $recursive Optional. If set to true, changes file owner recursively.
 495       *                              Default false.
 496       * @return bool True on success, false on failure.
 497       */
 498  	public function chown( $file, $owner, $recursive = false ) {
 499          return false;
 500      }
 501  
 502      /**
 503       * Connects filesystem.
 504       *
 505       * @since 2.5.0
 506       * @abstract
 507       *
 508       * @return bool True on success, false on failure (always true for WP_Filesystem_Direct).
 509       */
 510  	public function connect() {
 511          return true;
 512      }
 513  
 514      /**
 515       * Reads entire file into a string.
 516       *
 517       * @since 2.5.0
 518       * @abstract
 519       *
 520       * @param string $file Name of the file to read.
 521       * @return string|false Read data on success, false on failure.
 522       */
 523  	public function get_contents( $file ) {
 524          return false;
 525      }
 526  
 527      /**
 528       * Reads entire file into an array.
 529       *
 530       * @since 2.5.0
 531       * @abstract
 532       *
 533       * @param string $file Path to the file.
 534       * @return string[]|false File contents in an array on success, false on failure.
 535       */
 536  	public function get_contents_array( $file ) {
 537          return false;
 538      }
 539  
 540      /**
 541       * Writes a string to a file.
 542       *
 543       * @since 2.5.0
 544       * @abstract
 545       *
 546       * @param string    $file     Remote path to the file where to write the data.
 547       * @param string    $contents The data to write.
 548       * @param int|false $mode     Optional. The file permissions as octal number, usually 0644.
 549       *                            Default false.
 550       * @return bool True on success, false on failure.
 551       */
 552  	public function put_contents( $file, $contents, $mode = false ) {
 553          return false;
 554      }
 555  
 556      /**
 557       * Gets the current working directory.
 558       *
 559       * @since 2.5.0
 560       * @abstract
 561       *
 562       * @return string|false The current working directory on success, false on failure.
 563       */
 564  	public function cwd() {
 565          return false;
 566      }
 567  
 568      /**
 569       * Changes current directory.
 570       *
 571       * @since 2.5.0
 572       * @abstract
 573       *
 574       * @param string $dir The new current directory.
 575       * @return bool True on success, false on failure.
 576       */
 577  	public function chdir( $dir ) {
 578          return false;
 579      }
 580  
 581      /**
 582       * Changes the file group.
 583       *
 584       * @since 2.5.0
 585       * @abstract
 586       *
 587       * @param string     $file      Path to the file.
 588       * @param string|int $group     A group name or number.
 589       * @param bool       $recursive Optional. If set to true, changes file group recursively.
 590       *                              Default false.
 591       * @return bool True on success, false on failure.
 592       */
 593  	public function chgrp( $file, $group, $recursive = false ) {
 594          return false;
 595      }
 596  
 597      /**
 598       * Changes filesystem permissions.
 599       *
 600       * @since 2.5.0
 601       * @abstract
 602       *
 603       * @param string    $file      Path to the file.
 604       * @param int|false $mode      Optional. The permissions as octal number, usually 0644 for files,
 605       *                             0755 for directories. Default false.
 606       * @param bool      $recursive Optional. If set to true, changes file permissions recursively.
 607       *                             Default false.
 608       * @return bool True on success, false on failure.
 609       *
 610       * @phpstan-impure
 611       */
 612  	public function chmod( $file, $mode = false, $recursive = false ) {
 613          return false;
 614      }
 615  
 616      /**
 617       * Gets the file owner.
 618       *
 619       * @since 2.5.0
 620       * @abstract
 621       *
 622       * @param string $file Path to the file.
 623       * @return string|false Username of the owner on success, false on failure.
 624       */
 625  	public function owner( $file ) {
 626          return false;
 627      }
 628  
 629      /**
 630       * Gets the file's group.
 631       *
 632       * @since 2.5.0
 633       * @abstract
 634       *
 635       * @param string $file Path to the file.
 636       * @return string|false The group on success, false on failure.
 637       */
 638  	public function group( $file ) {
 639          return false;
 640      }
 641  
 642      /**
 643       * Copies a file.
 644       *
 645       * @since 2.5.0
 646       * @abstract
 647       *
 648       * @param string    $source      Path to the source file.
 649       * @param string    $destination Path to the destination file.
 650       * @param bool      $overwrite   Optional. Whether to overwrite the destination file if it exists.
 651       *                               Default false.
 652       * @param int|false $mode        Optional. The permissions as octal number, usually 0644 for files,
 653       *                               0755 for dirs. Default false.
 654       * @return bool True on success, false on failure.
 655       */
 656  	public function copy( $source, $destination, $overwrite = false, $mode = false ) {
 657          return false;
 658      }
 659  
 660      /**
 661       * Moves a file.
 662       *
 663       * @since 2.5.0
 664       * @abstract
 665       *
 666       * @param string $source      Path to the source file.
 667       * @param string $destination Path to the destination file.
 668       * @param bool   $overwrite   Optional. Whether to overwrite the destination file if it exists.
 669       *                            Default false.
 670       * @return bool True on success, false on failure.
 671       */
 672  	public function move( $source, $destination, $overwrite = false ) {
 673          return false;
 674      }
 675  
 676      /**
 677       * Deletes a file or directory.
 678       *
 679       * @since 2.5.0
 680       * @abstract
 681       *
 682       * @param string       $file      Path to the file or directory.
 683       * @param bool         $recursive Optional. If set to true, deletes files and folders recursively.
 684       *                                Default false.
 685       * @param string|false $type      Type of resource. 'f' for file, 'd' for directory.
 686       *                                Default false.
 687       * @return bool True on success, false on failure.
 688       */
 689  	public function delete( $file, $recursive = false, $type = false ) {
 690          return false;
 691      }
 692  
 693      /**
 694       * Checks if a file or directory exists.
 695       *
 696       * @since 2.5.0
 697       * @abstract
 698       *
 699       * @param string $path Path to file or directory.
 700       * @return bool Whether $path exists or not.
 701       */
 702  	public function exists( $path ) {
 703          return false;
 704      }
 705  
 706      /**
 707       * Checks if resource is a file.
 708       *
 709       * @since 2.5.0
 710       * @abstract
 711       *
 712       * @param string $file File path.
 713       * @return bool Whether $file is a file.
 714       */
 715  	public function is_file( $file ) {
 716          return false;
 717      }
 718  
 719      /**
 720       * Checks if resource is a directory.
 721       *
 722       * @since 2.5.0
 723       * @abstract
 724       *
 725       * @param string $path Directory path.
 726       * @return bool Whether $path is a directory.
 727       */
 728  	public function is_dir( $path ) {
 729          return false;
 730      }
 731  
 732      /**
 733       * Checks if a file is readable.
 734       *
 735       * @since 2.5.0
 736       * @abstract
 737       *
 738       * @param string $file Path to file.
 739       * @return bool Whether $file is readable.
 740       */
 741  	public function is_readable( $file ) {
 742          return false;
 743      }
 744  
 745      /**
 746       * Checks if a file or directory is writable.
 747       *
 748       * @since 2.5.0
 749       * @abstract
 750       *
 751       * @param string $path Path to file or directory.
 752       * @return bool Whether $path is writable.
 753       */
 754  	public function is_writable( $path ) {
 755          return false;
 756      }
 757  
 758      /**
 759       * Gets the file's last access time.
 760       *
 761       * @since 2.5.0
 762       * @abstract
 763       *
 764       * @param string $file Path to file.
 765       * @return int|false Unix timestamp representing last access time, false on failure.
 766       */
 767  	public function atime( $file ) {
 768          return false;
 769      }
 770  
 771      /**
 772       * Gets the file modification time.
 773       *
 774       * @since 2.5.0
 775       * @abstract
 776       *
 777       * @param string $file Path to file.
 778       * @return int|false Unix timestamp representing modification time, false on failure.
 779       */
 780  	public function mtime( $file ) {
 781          return false;
 782      }
 783  
 784      /**
 785       * Gets the file size (in bytes).
 786       *
 787       * @since 2.5.0
 788       * @abstract
 789       *
 790       * @param string $file Path to file.
 791       * @return int|false Size of the file in bytes on success, false on failure.
 792       */
 793  	public function size( $file ) {
 794          return false;
 795      }
 796  
 797      /**
 798       * Sets the access and modification times of a file.
 799       *
 800       * Note: If $file doesn't exist, it will be created.
 801       *
 802       * @since 2.5.0
 803       * @abstract
 804       *
 805       * @param string $file  Path to file.
 806       * @param int    $time  Optional. Modified time to set for file.
 807       *                      Default 0.
 808       * @param int    $atime Optional. Access time to set for file.
 809       *                      Default 0.
 810       * @return bool True on success, false on failure.
 811       */
 812  	public function touch( $file, $time = 0, $atime = 0 ) {
 813          return false;
 814      }
 815  
 816      /**
 817       * Creates a directory.
 818       *
 819       * @since 2.5.0
 820       * @abstract
 821       *
 822       * @param string           $path  Path for new directory.
 823       * @param int|false        $chmod Optional. The permissions as octal number (or false to skip chmod).
 824       *                                Default false.
 825       * @param string|int|false $chown Optional. A user name or number (or false to skip chown).
 826       *                                Default false.
 827       * @param string|int|false $chgrp Optional. A group name or number (or false to skip chgrp).
 828       *                                Default false.
 829       * @return bool True on success, false on failure.
 830       */
 831  	public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
 832          return false;
 833      }
 834  
 835      /**
 836       * Deletes a directory.
 837       *
 838       * @since 2.5.0
 839       * @abstract
 840       *
 841       * @param string $path      Path to directory.
 842       * @param bool   $recursive Optional. Whether to recursively remove files/directories.
 843       *                          Default false.
 844       * @return bool True on success, false on failure.
 845       */
 846  	public function rmdir( $path, $recursive = false ) {
 847          return false;
 848      }
 849  
 850      /**
 851       * Gets details for files in a directory or a specific file.
 852       *
 853       * @since 2.5.0
 854       * @abstract
 855       *
 856       * @param string $path           Path to directory or file.
 857       * @param bool   $include_hidden Optional. Whether to include details of hidden ("." prefixed) files.
 858       *                               Default true.
 859       * @param bool   $recursive      Optional. Whether to recursively include file details in nested directories.
 860       *                               Default false.
 861       * @return array|false {
 862       *     Array of arrays containing file information. False if unable to list directory contents.
 863       *
 864       *     @type array ...$0 {
 865       *         Array of file information. Note that some elements may not be available on all filesystems.
 866       *
 867       *         @type string           $name        Name of the file or directory.
 868       *         @type string           $perms       *nix representation of permissions.
 869       *         @type string           $permsn      Octal representation of permissions.
 870       *         @type int|string|false $number      File number. May be a numeric string. False if not available.
 871       *         @type string|false     $owner       Owner name or ID, or false if not available.
 872       *         @type string|false     $group       File permissions group, or false if not available.
 873       *         @type int|string|false $size        Size of file in bytes. May be a numeric string.
 874       *                                             False if not available.
 875       *         @type int|string|false $lastmodunix Last modified unix timestamp. May be a numeric string.
 876       *                                             False if not available.
 877       *         @type string|false     $lastmod     Last modified month (3 letters) and day (without leading 0), or
 878       *                                             false if not available.
 879       *         @type int|string|false $time        Last modified time. A Unix timestamp on FTP transports, or false if not available.
 880       *         @type string           $type        Type of resource. 'f' for file, 'd' for directory, 'l' for link.
 881       *         @type array|false      $files       If a directory and `$recursive` is true, contains another array of
 882       *                                             files. False if unable to list directory contents.
 883       *     }
 884       * }
 885       * @phpstan-return array<string, FileListing>|false
 886       */
 887  	public function dirlist( $path, $include_hidden = true, $recursive = false ) {
 888          return false;
 889      }
 890  }


Generated : Wed Oct 28 08:20:35 2026 Cross-referenced by PHPXref