ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
FSTools Class Reference

Filesystem tools not provided by default; can recursively create, copy and delete folders. More...

+ Inheritance diagram for FSTools:
+ Collaboration diagram for FSTools:

Public Member Functions

 mkdirr ($folder)
 Recursively creates a directory. More...
 
 copyr ($source, $dest)
 Copy a file, or recursively copy a folder and its contents; modified so that copied files, if PHP, have includes removed. More...
 
 copyable ($file)
 Overloadable function that tests a filename for copyability. More...
 
 rmdirr ($dirname)
 Delete a file, or a folder and its contents. More...
 
 globr ($dir, $pattern, $flags=NULL)
 Recursively globs a directory. More...
 
 __call ($name, $args)
 Allows for PHP functions to be called and be stubbed. More...
 

Static Public Member Functions

static singleton ()
 Returns a global instance of FSTools. More...
 
static setSingleton ($singleton)
 Sets our global singleton to something else; useful for overloading functions. More...
 

Static Private Attributes

static $singleton
 

Detailed Description

Filesystem tools not provided by default; can recursively create, copy and delete folders.

Some template methods are provided for extensibility.

Note
This class must be instantiated to be used, although it does not maintain state.

Definition at line 10 of file FSTools.php.

Member Function Documentation

◆ __call()

FSTools::__call (   $name,
  $args 
)

Allows for PHP functions to be called and be stubbed.

Warning
This function will not work for functions that need to pass references; manually define a stub function for those.

Definition at line 157 of file FSTools.php.

158 {
159 return call_user_func_array($name, $args);
160 }

◆ copyable()

FSTools::copyable (   $file)

Overloadable function that tests a filename for copyability.

By default, everything should be copied; you can restrict things to ignore hidden files, unreadable files, etc. This function applies to copyr().

Reimplemented in MergeLibraryFSTools.

Definition at line 99 of file FSTools.php.

100 {
101 return true;
102 }

Referenced by copyr().

+ Here is the caller graph for this function:

◆ copyr()

FSTools::copyr (   $source,
  $dest 
)

Copy a file, or recursively copy a folder and its contents; modified so that copied files, if PHP, have includes removed.

Note
Adapted from http://aidanlister.com/repos/v/function.copyr.php

Definition at line 63 of file FSTools.php.

64 {
65 // Simple copy for a file
66 if (is_file($source)) {
67 return $this->copy($source, $dest);
68 }
69 // Make destination directory
70 if (!is_dir($dest)) {
71 $this->mkdir($dest);
72 }
73 // Loop through the folder
74 $dir = $this->dir($source);
75 while ( false !== ($entry = $dir->read()) ) {
76 // Skip pointers
77 if ($entry == '.' || $entry == '..') {
78 continue;
79 }
80 if (!$this->copyable($entry)) {
81 continue;
82 }
83 // Deep copy directories
84 if ($dest !== "$source/$entry") {
85 $this->copyr("$source/$entry", "$dest/$entry");
86 }
87 }
88 // Clean up
89 $dir->close();
90 return true;
91 }
copyr($source, $dest)
Copy a file, or recursively copy a folder and its contents; modified so that copied files,...
Definition: FSTools.php:63
copyable($file)
Overloadable function that tests a filename for copyability.
Definition: FSTools.php:99

References copyable(), and copyr().

Referenced by copyr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ globr()

FSTools::globr (   $dir,
  $pattern,
  $flags = NULL 
)

Recursively globs a directory.

Definition at line 139 of file FSTools.php.

140 {
141 $files = $this->glob("$dir/$pattern", $flags);
142 if ($files === false) $files = array();
143 $sub_dirs = $this->glob("$dir/*", GLOB_ONLYDIR);
144 if ($sub_dirs === false) $sub_dirs = array();
145 foreach ($sub_dirs as $sub_dir) {
146 $sub_files = $this->globr($sub_dir, $pattern, $flags);
147 $files = array_merge($files, $sub_files);
148 }
149 return $files;
150 }
$files
Definition: add-vimline.php:18
globr($dir, $pattern, $flags=NULL)
Recursively globs a directory.
Definition: FSTools.php:139

References $files, and globr().

Referenced by globr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mkdirr()

FSTools::mkdirr (   $folder)

Recursively creates a directory.

Parameters
string$folderName of folder to create
Note
Adapted from the PHP manual comment 76612

Definition at line 38 of file FSTools.php.

39 {
40 $folders = preg_split("#[\\\\/]#", $folder);
41 $base = '';
42 for($i = 0, $c = count($folders); $i < $c; $i++) {
43 if(empty($folders[$i])) {
44 if (!$i) {
45 // special case for root level
46 $base .= DIRECTORY_SEPARATOR;
47 }
48 continue;
49 }
50 $base .= $folders[$i];
51 if(!is_dir($base)){
52 $this->mkdir($base);
53 }
54 $base .= DIRECTORY_SEPARATOR;
55 }
56 }

◆ rmdirr()

FSTools::rmdirr (   $dirname)

Delete a file, or a folder and its contents.

Note
Adapted from http://aidanlister.com/repos/v/function.rmdirr.php

Definition at line 108 of file FSTools.php.

109 {
110 // Sanity check
111 if (!$this->file_exists($dirname)) {
112 return false;
113 }
114
115 // Simple delete for a file
116 if ($this->is_file($dirname) || $this->is_link($dirname)) {
117 return $this->unlink($dirname);
118 }
119
120 // Loop through the folder
121 $dir = $this->dir($dirname);
122 while (false !== $entry = $dir->read()) {
123 // Skip pointers
124 if ($entry == '.' || $entry == '..') {
125 continue;
126 }
127 // Recurse
128 $this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
129 }
130
131 // Clean up
132 $dir->close();
133 return $this->rmdir($dirname);
134 }
rmdirr($dirname)
Delete a file, or a folder and its contents.
Definition: FSTools.php:108

References rmdirr().

Referenced by rmdirr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSingleton()

static FSTools::setSingleton (   $singleton)
static

Sets our global singleton to something else; useful for overloading functions.

Definition at line 28 of file FSTools.php.

29 {
31 }
static $singleton
Definition: FSTools.php:13

References $singleton.

◆ singleton()

static FSTools::singleton ( )
static

Returns a global instance of FSTools.

Definition at line 18 of file FSTools.php.

19 {
22 }
Filesystem tools not provided by default; can recursively create, copy and delete folders.
Definition: FSTools.php:11

References $singleton.

Referenced by FSTools_File\__construct().

+ Here is the caller graph for this function:

Field Documentation

◆ $singleton

FSTools::$singleton
staticprivate

Definition at line 13 of file FSTools.php.

Referenced by setSingleton(), and singleton().


The documentation for this class was generated from the following file: